diff --git a/azure/services/tags/client.go b/azure/services/tags/client.go index 6a71fb10ae4..ac8b51b59a0 100644 --- a/azure/services/tags/client.go +++ b/azure/services/tags/client.go @@ -1,5 +1,5 @@ /* -Copyright 2020 The Kubernetes Authors. +Copyright 2022 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/azure/services/tags/spec.go b/azure/services/tags/spec.go index 0233b4a9129..7f2287d03f1 100644 --- a/azure/services/tags/spec.go +++ b/azure/services/tags/spec.go @@ -17,8 +17,6 @@ limitations under the License. package tags import ( - "encoding/json" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-10-01/resources" "github.com/Azure/go-autorest/autorest/to" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" @@ -42,23 +40,10 @@ func (s *TagsSpec) TagsScope() string { // MergeParameters returns the merge parameters for a set of tags. func (s *TagsSpec) MergeParameters(existing *resources.TagsResource) (*resources.TagsPatchResource, error) { tags := make(map[string]*string) - if existing != nil { - // existingTags, ok := existing.(resources.TagsResource) - // if !ok { - // return nil, errors.Errorf("%T is not a resources.TagsResource", existing) - // } - - if existing.Properties != nil && existing.Properties.Tags != nil { - tags = existing.Properties.Tags - } + if existing != nil && existing.Properties != nil && existing.Properties.Tags != nil { + tags = existing.Properties.Tags } - // lastAppliedTags, err := jsonAnnotationToMap(s.JSONAnnotation) - // lastAppliedTags, err := s.Scope.AnnotationJSON(s.Annotation) - // if err != nil { - // return nil, err - // } - changed, createdOrUpdated, _ := getCreatedOrUpdatedTags(s.LastAppliedTags, s.Tags, tags) if !changed { // Nothing to create or update. @@ -80,26 +65,13 @@ func (s *TagsSpec) MergeParameters(existing *resources.TagsResource) (*resources // NewAnnotation returns the new annotation for a set of tags. func (s *TagsSpec) NewAnnotation(existing *resources.TagsResource) (map[string]interface{}, error) { tags := make(map[string]*string) - if existing != nil { - // existingTags, ok := existing.(resources.TagsResource) - // if !ok { - // return nil, errors.Errorf("%T is not a resources.TagsResource", existing) - // } - - if existing.Properties != nil && existing.Properties.Tags != nil { - tags = existing.Properties.Tags - } + if existing != nil && existing.Properties != nil && existing.Properties.Tags != nil { + tags = existing.Properties.Tags } - // lastAppliedTags, err := jsonAnnotationToMap(s.JSONAnnotation) - // lastAppliedTags, err := s.Scope.AnnotationJSON(s.Annotation) - // if err != nil { - // return nil, err - // } - changed, _, newAnnotation := getCreatedOrUpdatedTags(s.LastAppliedTags, s.Tags, tags) if !changed { - // Nothing to create or update. + // Nothing created or updated. return nil, nil } @@ -108,12 +80,6 @@ func (s *TagsSpec) NewAnnotation(existing *resources.TagsResource) (map[string]i // DeleteParameters returns the delete parameters for a set of tags. func (s *TagsSpec) DeleteParameters(existing *resources.TagsResource) (*resources.TagsPatchResource, error) { - // lastAppliedTags, err := jsonAnnotationToMap(s.JSONAnnotation) - // lastAppliedTags, err := s.Scope.AnnotationJSON(s.Annotation) - // if err != nil { - // return nil, err - // } - changed, deleted := getDeletedTags(s.LastAppliedTags, s.Tags) if !changed { // Nothing to delete, return nil @@ -132,19 +98,6 @@ func (s *TagsSpec) DeleteParameters(existing *resources.TagsResource) (*resource return nil, nil } -// jsonAnnotationToMap returns a map[string]interface from a JSON annotation. -func jsonAnnotationToMap(jsonAnnotation string) (map[string]interface{}, error) { - out := map[string]interface{}{} - if len(jsonAnnotation) == 0 { - return out, nil - } - err := json.Unmarshal([]byte(jsonAnnotation), &out) - if err != nil { - return out, err - } - return out, nil -} - // getCreatedOrUpdatedTags determines which tags to which to add. func getCreatedOrUpdatedTags(lastAppliedTags map[string]interface{}, desiredTags map[string]string, currentTags map[string]*string) (bool, map[string]string, map[string]interface{}) { // Bool tracking if we found any changed state. diff --git a/azure/services/tags/tags.go b/azure/services/tags/tags.go index fe3eb701b0a..97aba2ab302 100644 --- a/azure/services/tags/tags.go +++ b/azure/services/tags/tags.go @@ -1,5 +1,5 @@ /* -Copyright 2020 The Kubernetes Authors. +Copyright 2022 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.