Skip to content

Commit

Permalink
updated controller logic to detect nil maps
Browse files Browse the repository at this point in the history
Signed-off-by: Disaiah Bennett <[email protected]>
  • Loading branch information
dislbenn committed Sep 26, 2023
1 parent 02d90c1 commit a598f43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 4 additions & 0 deletions controllers/backplaneconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ func (r *MultiClusterEngineReconciler) ensureOpenShiftNamespaceLabel(ctx context
return ctrl.Result{Requeue: true}, err
}

if existingNs.Labels == nil || len(existingNs.Labels) == 0 {
existingNs.Labels = make(map[string]string)
}

if _, ok := existingNs.Labels[utils.OpenShiftClusterMonitoringLabel]; !ok {
log.Info(fmt.Sprintf("Adding label: %s to namespace: %s", utils.OpenShiftClusterMonitoringLabel,
backplaneConfig.Spec.TargetNamespace))
Expand Down
3 changes: 1 addition & 2 deletions controllers/backplaneconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ var _ = Describe("BackplaneConfig controller", func() {
// Create target namespace
err = k8sClient.Create(context.Background(), &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: DestinationNamespace,
Labels: make(map[string]string),
Name: DestinationNamespace,
},
Spec: corev1.NamespaceSpec{},
})
Expand Down

0 comments on commit a598f43

Please sign in to comment.