@@ -31,6 +31,8 @@ type namespaceInfo struct {
3131 defaultRegion string
3232 // services.k8s.aws/owner-account-id Annotation
3333 ownerAccountID string
34+ // services.k8s.aws/endpoint-url Annotation
35+ endpointURL string
3436}
3537
3638// getDefaultRegion returns the default region value
@@ -49,15 +51,23 @@ func (n *namespaceInfo) getOwnerAccountID() string {
4951 return n .ownerAccountID
5052}
5153
54+ // getEndpointURL returns the namespace Endpoint URL
55+ func (n * namespaceInfo ) getEndpointURL () string {
56+ if n == nil {
57+ return ""
58+ }
59+ return n .endpointURL
60+ }
61+
5262// NamespaceCache is responsible of keeping track of namespaces
5363// annotations, and caching those related to the ACK controller.
5464type NamespaceCache struct {
5565 sync.RWMutex
5666
5767 log logr.Logger
58- // Provide a namespace specifically to listen to.
68+ // Provide a namespace specifically to listen to.
5969 // Provide empty string to listen to all namespaces except kube-system and kube-public.
60- watchNamespace string
70+ watchNamespace string
6171
6272 // Namespace informer
6373 informer k8scache.SharedInformer
@@ -81,12 +91,12 @@ func NewNamespaceCache(clientset kubernetes.Interface, log logr.Logger, watchNam
8191 }
8292}
8393
84- // Check if the provided namespace should be listened to or not
94+ // Check if the provided namespace should be listened to or not
8595func isWatchNamespace (raw interface {}, watchNamespace string ) bool {
8696 object , ok := raw .(* corev1.Namespace )
8797 if ! ok {
8898 return false
89- }
99+ }
90100
91101 if watchNamespace != "" {
92102 return watchNamespace == object .ObjectMeta .Name
@@ -143,8 +153,18 @@ func (c *NamespaceCache) GetOwnerAccountID(namespace string) (string, bool) {
143153 return "" , false
144154}
145155
156+ // GetEndpointURL returns the endpoint URL if it exists
157+ func (c * NamespaceCache ) GetEndpointURL (namespace string ) (string , bool ) {
158+ info , ok := c .getNamespaceInfo (namespace )
159+ if ok {
160+ e := info .getEndpointURL ()
161+ return e , e != ""
162+ }
163+ return "" , false
164+ }
165+
146166// getNamespaceInfo reads a namespace cached annotations and
147- // return a given namespace default aws region and owner account id.
167+ // return a given namespace default aws region, owner account id and endpoint url .
148168// This function is thread safe.
149169func (c * NamespaceCache ) getNamespaceInfo (ns string ) (* namespaceInfo , bool ) {
150170 c .RLock ()
@@ -166,6 +186,10 @@ func (c *NamespaceCache) setNamespaceInfoFromK8sObject(ns *corev1.Namespace) {
166186 if ok {
167187 nsInfo .ownerAccountID = OwnerAccountID
168188 }
189+ EndpointURL , ok := nsa [ackv1alpha1 .AnnotationEndpointURL ]
190+ if ok {
191+ nsInfo .endpointURL = EndpointURL
192+ }
169193 c .Lock ()
170194 defer c .Unlock ()
171195 c .namespaceInfos [ns .ObjectMeta .Name ] = nsInfo
0 commit comments