diff --git a/controllers/podlabels/abstract.go b/controllers/podlabels/abstract.go index 6f2575c3..4fdacbf3 100644 --- a/controllers/podlabels/abstract.go +++ b/controllers/podlabels/abstract.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/go-logr/logr" - "github.com/pkg/errors" + "github.com/pkg/errors" //nolint:depguard corev1 "k8s.io/api/core/v1" apierr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/fields" @@ -55,12 +55,14 @@ func (r *podLabelsReconciler) Reconcile(ctx context.Context, request ctrl.Reques return reconcile.Result{}, err } + _, err = controllerutil.CreateOrUpdate(ctx, r.client, r.obj, func() (err error) { r.obj.SetLabels(r.sync(r.obj.GetLabels(), tenant.Spec.PodOptions.AdditionalMetadata.Labels)) r.obj.SetAnnotations(r.sync(r.obj.GetAnnotations(), tenant.Spec.PodOptions.AdditionalMetadata.Annotations)) return nil }) + return reconcile.Result{}, err } @@ -91,7 +93,7 @@ func (r *podLabelsReconciler) getTenant(ctx context.Context, namespacedName type func (r *podLabelsReconciler) sync(available map[string]string, tenantSpec map[string]string) map[string]string { if tenantSpec != nil { if available == nil { - return tenantSpec + available = tenantSpec } else { for key, value := range tenantSpec { if available[key] != value { diff --git a/pkg/api/pod_options.go b/pkg/api/pod_options.go index d0fb0492..84ac2ad0 100644 --- a/pkg/api/pod_options.go +++ b/pkg/api/pod_options.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Clastix Labs +// Copyright 2020-2021 Project Capsule Authors. // SPDX-License-Identifier: Apache-2.0 package api