Skip to content

Conversation

@a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Aug 30, 2020

Issue #, if available: #102

Description of changes:

Adding functionalities to help caching and accessing CARM configmap and namespace ACK related annotations.

  • Namespace annotations cache
  • CARM ConfigMap (ack-role-account-map) cache
  • Caches unit tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start, @a-hilaly! Suggestions inline, mostly around naming and the structure of the cache itself.

@a-hilaly a-hilaly force-pushed the carm-impl branch 3 times, most recently from 923830c to 085dbf3 Compare September 1, 2020 20:26
@jaypipes jaypipes changed the title WIP: CARM cache functionlities implementation WIP: CARM cache implementation Sep 8, 2020
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting very close, thank you @a-hilaly! Few more suggestions inline...

@a-hilaly a-hilaly force-pushed the carm-impl branch 3 times, most recently from 48f6078 to 265f8c2 Compare September 14, 2020 13:12
@a-hilaly a-hilaly force-pushed the carm-impl branch 2 times, most recently from 20acee9 to 6f265ae Compare September 14, 2020 13:46
@a-hilaly a-hilaly removed the WIP label Sep 14, 2020
@a-hilaly a-hilaly changed the title WIP: CARM cache implementation CARM cache implementation Sep 14, 2020
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this as-is. Awesome work, @a-hilaly. @mhausenblas and @vijtrip2 would you mind doing a thorough review of this patch before I merge please?

c.log.V(1).Info("cached ack-role-account-map data")
}
},
UpdateFunc: func(old, new interface{}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teeny nit: new is a keyword in Go and naming variables the same as keywords (something called "variable shadowing" ) is generally discouraged. Might be better to name these orig and desired?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, nice catch! I will change that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return err
}
r.cache = ackrtcache.New(kc, r.log)
r.kc = mgr.GetClient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you did the above instead of just:

r.kc = mgr.GetClient()
r.cache = ackrtcache.New(r.kc, r.log)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad for using kc as a variable name ... clientset makes much more sense.
ackrtcache.New first parameter takes a client-go/kubernetes.Interface , while mgr.GetClient returns a client.Client (from sigs.k8s.io/controller-runtime/pkg/client)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed kc to clientset

Copy link
Collaborator

@jaypipes jaypipes Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you misunderstood me :) I was saying that the clientset object is already being created on line 71 with:

r.kc = mgr.GetClient()

so you don't have to create another one with the call to mgr.GetConfig() and then kubernetes.NewForConfig(). You can just pass the reconciler's kc attribute (which is the kubernetes clientset) to your ackrtcache.New() function:

r.kc = mgr.GetClient()
r.cache = ackrtcache.New(r.kc, r.log)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh i see now... i think i tried this approach before but something wasn't compiling

Copy link
Member Author

@a-hilaly a-hilaly Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's because: client-go/kubernetes.NewForConfig() returns a kubernetes.Interface, mgr.Client() returns a ctrlrt/client.Client and client.Client doesn't implement the kubernetes.Interface interface

here is the compile error i get:

cannot use r.kc (type "sigs.k8s.io/controller-runtime/pkg/client".Client) as type kubernetes.Interface in argument to "github.com/aws/aws-controllers-k8s/pkg/runtime/cache".New:
	"sigs.k8s.io/controller-runtime/pkg/client".Client does not implement kubernetes.Interface (missing AdmissionregistrationV1 method)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. interesting... OK, soon as I'm done with a customer call I'll look into perhaps a cleaner way to do this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just closing this out, but I've asked @a-hilaly to create an issue with a TODO about this and we're going to merge this as-is.

Copy link
Contributor

@vijtrip2 vijtrip2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mhausenblas mhausenblas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well. Meta comment: we need to review the resource requests (non blocking).

Let's ship it!

- reconciler.getRegion now try lookup for CRs region annotation, namespace default region annotation before finally trying to use flag/env values.
- Add pkg/runtime/cache.NamespacesCache object to simplify access to namespace annotations and keep the cache up to date whenever new changes are made.
- Add pkg/runtime/cache.AccountsCache object to simplify access to CARM configmap  and keep the cache up to date whenever new changes are made.
- Add pkg/runtime/cache.Caches object to quickly create NamespacesCache and AccountsCache
- Inject NAMESPACE environment variable to controller pods using k8s downward api
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline, sorry I wasn't clear.

return err
}
r.cache = ackrtcache.New(kc, r.log)
r.kc = mgr.GetClient()
Copy link
Collaborator

@jaypipes jaypipes Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you misunderstood me :) I was saying that the clientset object is already being created on line 71 with:

r.kc = mgr.GetClient()

so you don't have to create another one with the call to mgr.GetConfig() and then kubernetes.NewForConfig(). You can just pass the reconciler's kc attribute (which is the kubernetes clientset) to your ackrtcache.New() function:

r.kc = mgr.GetClient()
r.cache = ackrtcache.New(r.kc, r.log)

return err
}
r.cache = ackrtcache.New(kc, r.log)
r.kc = mgr.GetClient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just closing this out, but I've asked @a-hilaly to create an issue with a TODO about this and we're going to merge this as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants