Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ mocks: install-mockery ## Build mocks
@echo -n "building mocks for sigs.k8s.io/controller-runtime/pkg/client ... "
@bin/mockery --quiet --name="(Object|Client|Status|Reader|SubResourceWriter)" --case=underscore --output=mocks/controller-runtime/pkg/client --dir="$(CONTROLLER_RUNTIME_DIR)/pkg/client"
@echo "ok."
@echo -n "building mocks for sigs.k8s.io/controller-runtime/pkg/cache ... "
@bin/mockery --quiet --name="(Cache)" --case=underscore --output=mocks/controller-runtime/pkg/cache --dir="$(CONTROLLER_RUNTIME_DIR)/pkg/cache"
@echo "ok."

help: ## Show this help.
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep | sed -e 's/\\$$//' \
Expand Down
231 changes: 231 additions & 0 deletions mocks/controller-runtime/pkg/cache/cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions mocks/controller-runtime/pkg/cache/new_cache_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions pkg/runtime/adoption_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
ctrlrt "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
k8sctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"
Expand Down Expand Up @@ -57,7 +58,7 @@ type adoptionReconciler struct {
// of an upstream controller-runtime.Manager
func (r *adoptionReconciler) BindControllerManager(mgr ctrlrt.Manager) error {
r.kc = mgr.GetClient()
r.apiReader = mgr.GetAPIReader()
r.ackResourceCache = mgr.GetCache()
return ctrlrt.NewControllerManagedBy(
mgr,
).For(
Expand Down Expand Up @@ -251,7 +252,7 @@ func (r *adoptionReconciler) Sync(

// Only create the described resource if it does not already exist
// in k8s cluster.
if err := r.apiReader.Get(ctx, types.NamespacedName{
if err := r.ackResourceCache.Get(ctx, types.NamespacedName{
Namespace: described.MetaObject().GetNamespace(),
Name: described.MetaObject().GetName(),
}, described.RuntimeObject()); err != nil {
Expand Down Expand Up @@ -306,15 +307,15 @@ func (r *adoptionReconciler) getAdoptedResource(
req ctrlrt.Request,
) (*ackv1alpha1.AdoptedResource, error) {
ro := &ackv1alpha1.AdoptedResource{}
// Here we use k8s APIReader to read the k8s object by making the
// Here we use k8s ACKResourceCache to read the k8s object by making the
// direct call to k8s apiserver instead of using k8sClient.
// The reason is that k8sClient uses a cache and sometimes k8sClient can
// return stale copy of object.
// It is okay to make direct call to k8s apiserver because we are only
// making single read call for complete reconciler loop.
// See following issue for more details:
// https://github.com/aws-controllers-k8s/community/issues/894
if err := r.apiReader.Get(ctx, req.NamespacedName, ro); err != nil {
if err := r.ackResourceCache.Get(ctx, req.NamespacedName, ro); err != nil {
return nil, err
}
return ro, nil
Expand Down Expand Up @@ -615,7 +616,7 @@ func NewAdoptionReconcilerWithClient(
metrics *ackmetrics.Metrics,
cache ackrtcache.Caches,
kc client.Client,
apiReader client.Reader,
ackResourceCache cache.Cache,
) acktypes.AdoptedResourceReconciler {
return &adoptionReconciler{
reconciler: reconciler{
Expand All @@ -625,7 +626,7 @@ func NewAdoptionReconcilerWithClient(
metrics: metrics,
cache: cache,
kc: kc,
apiReader: apiReader,
ackResourceCache: ackResourceCache,
},
}
}
Loading