Skip to content

Commit 4ba8f18

Browse files
hu-keyukaovilaiclaude
authored
Issue 1743: move/dupe podAnnotations into podConfig (#1773)
* move podAnnotations into podConfig * move podAnnotations into podConfig * fix: NodeAgent DaemonSet annotations initialization Change nodeAgentAnnotations initialization to use nil instead of empty map when no annotations are provided. This ensures the DaemonSet template annotations field remains nil rather than an empty map, matching the expected behavior in unit tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * `make bundle` Signed-off-by: Tiger Kaovilai <[email protected]> --------- Signed-off-by: Tiger Kaovilai <[email protected]> Co-authored-by: Tiger Kaovilai <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 76cb430 commit 4ba8f18

File tree

8 files changed

+73
-13
lines changed

8 files changed

+73
-13
lines changed

api/v1alpha1/dataprotectionapplication_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ type PodConfig struct {
347347
// labels to add to pods
348348
// +optional
349349
Labels map[string]string `json:"labels,omitempty"`
350+
// annotations to add to pods
351+
// +optional
352+
Annotations map[string]string `json:"annotations,omitempty"`
350353
// nodeSelector defines the nodeSelector to be supplied to podSpec
351354
// +optional
352355
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
@@ -790,6 +793,7 @@ type DataProtectionApplicationSpec struct {
790793
UnsupportedOverrides map[UnsupportedImageKey]string `json:"unsupportedOverrides,omitempty"`
791794
// add annotations to pods deployed by operator
792795
// +optional
796+
// Deprecated: Use PodConfig instead
793797
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
794798
// podDnsPolicy defines how a pod's DNS will be configured.
795799
// https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ spec:
365365
podConfig:
366366
description: Pod specific configuration
367367
properties:
368+
annotations:
369+
additionalProperties:
370+
type: string
371+
description: annotations to add to pods
372+
type: object
368373
env:
369374
description: env defines the list of environment variables to be supplied to podSpec
370375
items:
@@ -714,6 +719,11 @@ spec:
714719
podConfig:
715720
description: Pod specific configuration
716721
properties:
722+
annotations:
723+
additionalProperties:
724+
type: string
725+
description: annotations to add to pods
726+
type: object
717727
env:
718728
description: env defines the list of environment variables to be supplied to podSpec
719729
items:
@@ -1226,6 +1236,11 @@ spec:
12261236
podConfig:
12271237
description: Pod specific configuration
12281238
properties:
1239+
annotations:
1240+
additionalProperties:
1241+
type: string
1242+
description: annotations to add to pods
1243+
type: object
12291244
env:
12301245
description: env defines the list of environment variables to be supplied to podSpec
12311246
items:
@@ -2530,7 +2545,9 @@ spec:
25302545
podAnnotations:
25312546
additionalProperties:
25322547
type: string
2533-
description: add annotations to pods deployed by operator
2548+
description: |-
2549+
add annotations to pods deployed by operator
2550+
Deprecated: Use PodConfig instead
25342551
type: object
25352552
podDnsConfig:
25362553
description: |-

config/crd/bases/oadp.openshift.io_dataprotectionapplications.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ spec:
365365
podConfig:
366366
description: Pod specific configuration
367367
properties:
368+
annotations:
369+
additionalProperties:
370+
type: string
371+
description: annotations to add to pods
372+
type: object
368373
env:
369374
description: env defines the list of environment variables to be supplied to podSpec
370375
items:
@@ -714,6 +719,11 @@ spec:
714719
podConfig:
715720
description: Pod specific configuration
716721
properties:
722+
annotations:
723+
additionalProperties:
724+
type: string
725+
description: annotations to add to pods
726+
type: object
717727
env:
718728
description: env defines the list of environment variables to be supplied to podSpec
719729
items:
@@ -1226,6 +1236,11 @@ spec:
12261236
podConfig:
12271237
description: Pod specific configuration
12281238
properties:
1239+
annotations:
1240+
additionalProperties:
1241+
type: string
1242+
description: annotations to add to pods
1243+
type: object
12291244
env:
12301245
description: env defines the list of environment variables to be supplied to podSpec
12311246
items:
@@ -2530,7 +2545,9 @@ spec:
25302545
podAnnotations:
25312546
additionalProperties:
25322547
type: string
2533-
description: add annotations to pods deployed by operator
2548+
description: |-
2549+
add annotations to pods deployed by operator
2550+
Deprecated: Use PodConfig instead
25342551
type: object
25352552
podDnsConfig:
25362553
description: |-

internal/controller/nodeagent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ func (r *DataProtectionApplicationReconciler) buildNodeAgentDaemonset(ds *appsv1
304304
}
305305

306306
var nodeAgentResourceReqs corev1.ResourceRequirements
307+
var nodeAgentAnnotations map[string]string
308+
if dpa.Spec.Configuration != nil && dpa.Spec.Configuration.NodeAgent != nil && dpa.Spec.Configuration.NodeAgent.PodConfig != nil {
309+
nodeAgentAnnotations = dpa.Spec.Configuration.NodeAgent.PodConfig.Annotations
310+
}
307311

308312
// get resource requirements for nodeAgent ds
309313
// ignoring err here as it is checked in validator.go
@@ -330,7 +334,7 @@ func (r *DataProtectionApplicationReconciler) buildNodeAgentDaemonset(ds *appsv1
330334
installDs := install.DaemonSet(ds.Namespace,
331335
install.WithResources(nodeAgentResourceReqs),
332336
install.WithImage(getVeleroImage(dpa)),
333-
install.WithAnnotations(dpa.Spec.PodAnnotations),
337+
install.WithAnnotations(nodeAgentAnnotations),
334338
install.WithSecret(false),
335339
install.WithServiceAccountName(common.Velero),
336340
install.WithNodeAgentConfigMap(configMapName),

internal/controller/nodeagent_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,16 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) {
688688
Configuration: &oadpv1alpha1.ApplicationConfig{
689689
Velero: &oadpv1alpha1.VeleroConfig{},
690690
NodeAgent: &oadpv1alpha1.NodeAgentConfig{
691-
NodeAgentCommonFields: oadpv1alpha1.NodeAgentCommonFields{},
692-
UploaderType: "kopia",
691+
NodeAgentCommonFields: oadpv1alpha1.NodeAgentCommonFields{
692+
PodConfig: &oadpv1alpha1.PodConfig{
693+
Annotations: map[string]string{
694+
"test-annotation": "awesome annotation",
695+
},
696+
},
697+
},
698+
UploaderType: "kopia",
693699
},
694700
},
695-
PodAnnotations: map[string]string{
696-
"test-annotation": "awesome annotation",
697-
},
698701
},
699702
),
700703
clientObjects: []client.Object{testGenericInfrastructure},

internal/controller/velero.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ func (r *DataProtectionApplicationReconciler) buildVeleroDeployment(veleroDeploy
167167
// get resource requirements for velero deployment
168168
// ignoring err here as it is checked in validator.go
169169
veleroResourceReqs, _ := r.getVeleroResourceReqs()
170-
podAnnotations, err := common.AppendUniqueKeyTOfTMaps(dpa.Spec.PodAnnotations, veleroDeployment.Annotations)
170+
veleroAnnotations := make(map[string]string)
171+
if dpa.Spec.Configuration != nil && dpa.Spec.Configuration.Velero != nil && dpa.Spec.Configuration.Velero.PodConfig != nil {
172+
veleroAnnotations = dpa.Spec.Configuration.Velero.PodConfig.Annotations
173+
}
174+
175+
podAnnotations, err := common.AppendUniqueKeyTOfTMaps(veleroAnnotations, veleroDeployment.Annotations)
171176
if err != nil {
172177
return fmt.Errorf("error appending pod annotations: %v", err)
173178
}

internal/controller/velero_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,13 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
694694
nil,
695695
oadpv1alpha1.DataProtectionApplicationSpec{
696696
Configuration: &oadpv1alpha1.ApplicationConfig{
697-
Velero: &oadpv1alpha1.VeleroConfig{},
698-
},
699-
PodAnnotations: map[string]string{
700-
"test-annotation": "awesome annotation",
697+
Velero: &oadpv1alpha1.VeleroConfig{
698+
PodConfig: &oadpv1alpha1.PodConfig{
699+
Annotations: map[string]string{
700+
"test-annotation": "awesome annotation",
701+
},
702+
},
703+
},
701704
},
702705
},
703706
),

0 commit comments

Comments
 (0)