@@ -54,6 +54,7 @@ func (r *Resources) EnsureAnnotations(cachedStatus inspector.Inspector) error {
5454 }
5555
5656 if err := ensureServiceAccountsAnnotations (kubecli .CoreV1 ().ServiceAccounts (r .context .GetNamespace ()),
57+ cachedStatus ,
5758 deployment .ArangoDeploymentResourceKind ,
5859 r .context .GetAPIObject ().GetName (),
5960 r .context .GetAPIObject ().GetNamespace (),
@@ -71,6 +72,7 @@ func (r *Resources) EnsureAnnotations(cachedStatus inspector.Inspector) error {
7172 }
7273
7374 if err := ensurePdbsAnnotations (kubecli .PolicyV1beta1 ().PodDisruptionBudgets (r .context .GetNamespace ()),
75+ cachedStatus ,
7476 deployment .ArangoDeploymentResourceKind ,
7577 r .context .GetAPIObject ().GetName (),
7678 r .context .GetAPIObject ().GetNamespace (),
@@ -137,22 +139,20 @@ func setSecretAnnotations(client typedCore.SecretInterface, secret *core.Secret,
137139 })
138140}
139141
140- func ensureServiceAccountsAnnotations (client typedCore.ServiceAccountInterface , kind , name , namespace string , annotations map [string ]string ) error {
141- serviceAccounts , err := k8sutil .GetServiceAccountsForParent (client ,
142- kind ,
143- name ,
144- namespace )
145- if err != nil {
146- return err
147- }
148-
149- for _ , serviceAccount := range serviceAccounts {
142+ func ensureServiceAccountsAnnotations (client typedCore.ServiceAccountInterface , cachedStatus inspector.Inspector , kind , name , namespace string , annotations map [string ]string ) error {
143+ if err := cachedStatus .IterateServiceAccounts (func (serviceAccount * core.ServiceAccount ) error {
150144 if ! k8sutil .CompareAnnotations (serviceAccount .GetAnnotations (), annotations ) {
151145 log .Info ().Msgf ("Replacing annotations for ServiceAccount %s" , serviceAccount .Name )
152- if err = setServiceAccountAnnotations (client , serviceAccount , annotations ); err != nil {
146+ if err : = setServiceAccountAnnotations (client , serviceAccount , annotations ); err != nil {
153147 return err
154148 }
155149 }
150+
151+ return nil
152+ }, func (serviceAccount * core.ServiceAccount ) bool {
153+ return k8sutil .IsChildResource (kind , name , namespace , serviceAccount )
154+ }); err != nil {
155+ return err
156156 }
157157
158158 return nil
@@ -213,22 +213,20 @@ func setServiceAnnotations(client typedCore.ServiceInterface, service *core.Serv
213213 })
214214}
215215
216- func ensurePdbsAnnotations (client policyTyped.PodDisruptionBudgetInterface , kind , name , namespace string , annotations map [string ]string ) error {
217- podDisruptionBudgets , err := k8sutil .GetPDBForParent (client ,
218- kind ,
219- name ,
220- namespace )
221- if err != nil {
222- return err
223- }
224-
225- for _ , podDisruptionBudget := range podDisruptionBudgets {
216+ func ensurePdbsAnnotations (client policyTyped.PodDisruptionBudgetInterface , cachedStatus inspector.Inspector , kind , name , namespace string , annotations map [string ]string ) error {
217+ if err := cachedStatus .IteratePodDisruptionBudgets (func (podDisruptionBudget * policy.PodDisruptionBudget ) error {
226218 if ! k8sutil .CompareAnnotations (podDisruptionBudget .GetAnnotations (), annotations ) {
227- log .Info ().Msgf ("Replacing annotations for PDB %s" , podDisruptionBudget .Name )
228- if err = setPdbAnnotations (client , podDisruptionBudget , annotations ); err != nil {
219+ log .Info ().Msgf ("Replacing annotations for PodDisruptionBudget %s" , podDisruptionBudget .Name )
220+ if err : = setPdbAnnotations (client , podDisruptionBudget , annotations ); err != nil {
229221 return err
230222 }
231223 }
224+
225+ return nil
226+ }, func (podDisruptionBudget * policy.PodDisruptionBudget ) bool {
227+ return k8sutil .IsChildResource (kind , name , namespace , podDisruptionBudget )
228+ }); err != nil {
229+ return err
232230 }
233231
234232 return nil
@@ -289,17 +287,23 @@ func setPvcAnnotations(client typedCore.PersistentVolumeClaimInterface, persiste
289287 })
290288}
291289
292- func getPodGroup (pod * core.Pod ) api.ServerGroup {
293- if pod .Labels == nil {
290+ func getObjectGroup (obj meta.Object ) api.ServerGroup {
291+ l := obj .GetLabels ()
292+ if len (l ) == 0 {
294293 return api .ServerGroupUnknown
295294 }
296295
297- return api .ServerGroupFromRole (pod .Labels [k8sutil .LabelKeyRole ])
296+ group , ok := l [k8sutil .LabelKeyRole ]
297+ if ! ok {
298+ return api .ServerGroupUnknown
299+ }
300+
301+ return api .ServerGroupFromRole (group )
298302}
299303
300304func ensurePodsAnnotations (client typedCore.PodInterface , cachedStatus inspector.Inspector , kind , name , namespace string , annotations map [string ]string , spec api.DeploymentSpec ) error {
301305 if err := cachedStatus .IteratePods (func (pod * core.Pod ) error {
302- group := getPodGroup (pod )
306+ group := getObjectGroup (pod )
303307 mergedAnnotations := k8sutil .MergeAnnotations (annotations , spec .GetServerGroupSpec (group ).Annotations )
304308
305309 if ! k8sutil .CompareAnnotations (pod .GetAnnotations (), mergedAnnotations ) {
@@ -336,3 +340,10 @@ func setPodAnnotations(client typedCore.PodInterface, pod *core.Pod, annotations
336340 return nil
337341 })
338342}
343+
344+ func (r * Resources ) isChildResource (obj meta.Object ) bool {
345+ return k8sutil .IsChildResource (deployment .ArangoDeploymentResourceKind ,
346+ r .context .GetAPIObject ().GetName (),
347+ r .context .GetAPIObject ().GetNamespace (),
348+ obj )
349+ }
0 commit comments