Skip to content

Commit

Permalink
Merge pull request #3733 from nojnhuh/aso-maps
Browse files Browse the repository at this point in the history
refactor ASO label/annotation updates
  • Loading branch information
k8s-ci-robot authored Jul 31, 2023
2 parents 668a1bc + fdf0610 commit b6cde9b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions azure/services/aso/aso.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/util/maps"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -156,8 +155,14 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
}
}

labels := make(map[string]string)
annotations := make(map[string]string)
labels := parameters.GetLabels()
if labels == nil {
labels = make(map[string]string)
}
annotations := parameters.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}

if existing == nil {
labels[infrav1.OwnedByClusterLabelKey] = s.clusterName
Expand All @@ -176,12 +181,14 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
annotations[ReconcilePolicyAnnotation] = ReconcilePolicyManage
}

if len(labels) > 0 {
parameters.SetLabels(maps.Merge(parameters.GetLabels(), labels))
if len(labels) == 0 {
labels = nil
}
if len(annotations) > 0 {
parameters.SetAnnotations(maps.Merge(parameters.GetAnnotations(), annotations))
parameters.SetLabels(labels)
if len(annotations) == 0 {
annotations = nil
}
parameters.SetAnnotations(annotations)

diff := cmp.Diff(existing, parameters)
if diff == "" {
Expand Down

0 comments on commit b6cde9b

Please sign in to comment.