Skip to content

Commit

Permalink
don't override matchlabels
Browse files Browse the repository at this point in the history
  • Loading branch information
kaovilai committed May 10, 2022
1 parent 0a34837 commit 6cc6dd2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
17 changes: 16 additions & 1 deletion controllers/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,22 @@ func (r *DPAReconciler) ReconcileResticDaemonset(log logr.Logger) (bool, error)
// Deployment selector is immutable so we set this value only if
// a new object is going to be created
if ds.ObjectMeta.CreationTimestamp.IsZero() {
ds.Spec.Selector = resticLabelSelector
if ds.Spec.Selector == nil {
ds.Spec.Selector = &metav1.LabelSelector{}
}
var err error
if ds.Spec.Selector == nil {
ds.Spec.Selector = &metav1.LabelSelector{
MatchLabels: make(map[string]string),
}
}
if ds.Spec.Selector.MatchLabels == nil {
ds.Spec.Selector.MatchLabels = make(map[string]string)
}
ds.Spec.Selector.MatchLabels, err = common.AppendUniqueLabels(ds.Spec.Selector.MatchLabels, resticLabelSelector.MatchLabels)
if err != nil {
return fmt.Errorf("failed to append labels to selector: %s", err)
}
}

if err := controllerutil.SetControllerReference(&dpa, ds, r.Scheme); err != nil {
Expand Down
13 changes: 11 additions & 2 deletions controllers/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,17 @@ func (r *DPAReconciler) customizeVeleroDeployment(dpa *oadpv1alpha1.DataProtecti
if err != nil {
return fmt.Errorf("velero deployment label: %v", err)
}
veleroDeployment.Spec.Selector = &metav1.LabelSelector{
MatchLabels: veleroDeployment.Labels,
if veleroDeployment.Spec.Selector == nil {
veleroDeployment.Spec.Selector = &metav1.LabelSelector{
MatchLabels: make(map[string]string),
}
}
if veleroDeployment.Spec.Selector.MatchLabels == nil {
veleroDeployment.Spec.Selector.MatchLabels = make(map[string]string)
}
veleroDeployment.Spec.Selector.MatchLabels, err = common.AppendUniqueLabels(veleroDeployment.Spec.Selector.MatchLabels, veleroDeployment.Labels, r.getDpaAppLabels(dpa))
if err != nil {
return fmt.Errorf("velero deployment selector label: %v", err)
}
veleroDeployment.Spec.Template.Labels, err = common.AppendUniqueLabels(veleroDeployment.Spec.Template.Labels, veleroDeployment.Labels)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions controllers/velero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -129,6 +130,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -254,6 +256,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -302,6 +305,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -428,6 +432,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -468,6 +473,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -512,6 +518,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -639,6 +646,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -679,6 +687,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -734,6 +743,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -864,6 +874,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/component": Server,
oadpv1alpha1.OadpOperatorLabel: "True",
"component": "velero",
"deploy": "velero",
},
},
},
Expand Down Expand Up @@ -927,6 +938,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/component": Server,
oadpv1alpha1.OadpOperatorLabel: "True",
"component": "velero",
"deploy": "velero",
},
},
Replicas: pointer.Int32(1),
Expand Down Expand Up @@ -1064,6 +1076,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/component": Server,
oadpv1alpha1.OadpOperatorLabel: "True",
"component": "velero",
"deploy": "velero",
},
},
},
Expand Down Expand Up @@ -1122,6 +1135,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/component": Server,
oadpv1alpha1.OadpOperatorLabel: "True",
"component": "velero",
"deploy": "velero",
},
},
Replicas: pointer.Int32(1),
Expand Down Expand Up @@ -1249,6 +1263,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1295,6 +1310,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1451,6 +1467,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1498,6 +1515,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1668,6 +1686,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1717,6 +1736,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1874,6 +1894,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -1939,6 +1960,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -2112,6 +2134,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down Expand Up @@ -2176,6 +2199,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": Server,
"component": "velero",
"deploy": "velero",
oadpv1alpha1.OadpOperatorLabel: "True",
},
},
Expand Down

0 comments on commit 6cc6dd2

Please sign in to comment.