Skip to content

Commit

Permalink
Clean comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Mar 31, 2022
1 parent 6ce5e8c commit 5bb4bb7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 54 deletions.
2 changes: 1 addition & 1 deletion azure/services/tags/client.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
57 changes: 5 additions & 52 deletions azure/services/tags/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion azure/services/tags/tags.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 5bb4bb7

Please sign in to comment.