Skip to content

Commit a22366f

Browse files
authored
Merge pull request #4540 from nojnhuh/aso-tags-1.12
[release-1.12] only consider spec in existing when reconciling ASO tags
2 parents 219b8bc + de1098e commit a22366f

File tree

8 files changed

+1
-135
lines changed

8 files changed

+1
-135
lines changed

azure/services/aso/aso.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ func (r *reconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.A
156156

157157
if t, ok := spec.(TagsGetterSetter[T]); ok {
158158
if err := reconcileTags(t, existing, resourceExists, parameters); err != nil {
159-
if azure.IsOperationNotDoneError(err) && readyErr != nil {
160-
return zero, readyErr
161-
}
162159
return zero, errors.Wrap(err, "failed to reconcile tags")
163160
}
164161
}

azure/services/aso/aso_test.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ func TestCreateOrUpdateResource(t *testing.T) {
727727
})
728728
specMock.MockASOResourceSpecGetter.EXPECT().WasManaged(gomock.Any()).Return(false)
729729

730-
specMock.MockTagsGetterSetter.EXPECT().GetActualTags(gomock.Any()).Return(nil)
731730
specMock.MockTagsGetterSetter.EXPECT().GetAdditionalTags().Return(nil)
732731
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(nil).Times(2)
733732
specMock.MockTagsGetterSetter.EXPECT().SetTags(gomock.Any(), gomock.Any())
@@ -819,71 +818,6 @@ func TestCreateOrUpdateResource(t *testing.T) {
819818
g.Expect(err.Error()).To(ContainSubstring("failed to reconcile tags"))
820819
})
821820

822-
t.Run("with tags not done error and readyErr", func(t *testing.T) {
823-
g := NewGomegaWithT(t)
824-
825-
sch := runtime.NewScheme()
826-
g.Expect(asoresourcesv1.AddToScheme(sch)).To(Succeed())
827-
c := fakeclient.NewClientBuilder().
828-
WithScheme(sch).
829-
Build()
830-
s := New[*asoresourcesv1.ResourceGroup](c, clusterName)
831-
832-
mockCtrl := gomock.NewController(t)
833-
specMock := struct {
834-
*mock_azure.MockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup]
835-
*mock_aso.MockTagsGetterSetter[*asoresourcesv1.ResourceGroup]
836-
}{
837-
MockASOResourceSpecGetter: mock_azure.NewMockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup](mockCtrl),
838-
MockTagsGetterSetter: mock_aso.NewMockTagsGetterSetter[*asoresourcesv1.ResourceGroup](mockCtrl),
839-
}
840-
specMock.MockASOResourceSpecGetter.EXPECT().ResourceRef().Return(&asoresourcesv1.ResourceGroup{
841-
ObjectMeta: metav1.ObjectMeta{
842-
Name: "name",
843-
Namespace: "namespace",
844-
},
845-
})
846-
specMock.MockASOResourceSpecGetter.EXPECT().Parameters(gomockinternal.AContext(), gomock.Any()).DoAndReturn(func(_ context.Context, group *asoresourcesv1.ResourceGroup) (*asoresourcesv1.ResourceGroup, error) {
847-
return group, nil
848-
})
849-
850-
existing := &asoresourcesv1.ResourceGroup{
851-
ObjectMeta: metav1.ObjectMeta{
852-
Name: "name",
853-
Namespace: "namespace",
854-
Labels: map[string]string{
855-
infrav1.OwnedByClusterLabelKey: clusterName,
856-
},
857-
Annotations: map[string]string{
858-
asoannotations.ReconcilePolicy: string(asoannotations.ReconcilePolicyManage),
859-
},
860-
},
861-
Spec: asoresourcesv1.ResourceGroup_Spec{
862-
Tags: map[string]string{"desired": "tags"},
863-
},
864-
Status: asoresourcesv1.ResourceGroup_STATUS{
865-
Tags: map[string]string{"actual": "tags"},
866-
Conditions: []conditions.Condition{
867-
{
868-
Type: conditions.ConditionTypeReady,
869-
Status: metav1.ConditionFalse,
870-
Message: "not ready :(",
871-
},
872-
},
873-
},
874-
}
875-
876-
specMock.MockTagsGetterSetter.EXPECT().GetActualTags(gomock.Any()).Return(existing.Status.Tags)
877-
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(existing.Spec.Tags)
878-
879-
ctx := context.Background()
880-
g.Expect(c.Create(ctx, existing)).To(Succeed())
881-
882-
result, err := s.CreateOrUpdateResource(ctx, specMock, "service")
883-
g.Expect(result).To(BeNil())
884-
g.Expect(err.Error()).To(ContainSubstring("not ready :("))
885-
})
886-
887821
t.Run("reconcile policy annotation resets after un-pause", func(t *testing.T) {
888822
g := NewGomegaWithT(t)
889823

azure/services/aso/interfaces.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type Reconciler[T genruntime.MetaObject] interface {
3636
type TagsGetterSetter[T genruntime.MetaObject] interface {
3737
GetAdditionalTags() infrav1.Tags
3838
GetDesiredTags(resource T) infrav1.Tags
39-
GetActualTags(resource T) infrav1.Tags
4039
SetTags(resource T, tags infrav1.Tags)
4140
}
4241

azure/services/aso/mock_aso/aso_mock.go

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/services/aso/tags.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ package aso
1818

1919
import (
2020
"encoding/json"
21-
"reflect"
2221

23-
asoannotations "github.com/Azure/azure-service-operator/v2/pkg/common/annotations"
2422
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
2523
"github.com/pkg/errors"
2624
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
27-
"sigs.k8s.io/cluster-api-provider-azure/azure"
2825
"sigs.k8s.io/cluster-api-provider-azure/azure/converters"
2926
"sigs.k8s.io/cluster-api-provider-azure/azure/services/tags"
3027
"sigs.k8s.io/cluster-api-provider-azure/util/maps"
@@ -49,17 +46,7 @@ func reconcileTags[T genruntime.MetaObject](t TagsGetterSetter[T], existing T, r
4946
}
5047
}
5148

52-
existingTags = t.GetActualTags(existing)
53-
// Wait for tags to converge so we know for sure which ones are deleted from additionalTags (and
54-
// should be deleted) and which were added manually (and should be kept).
55-
if !reflect.DeepEqual(t.GetDesiredTags(existing), existingTags) &&
56-
existing.GetAnnotations()[asoannotations.ReconcilePolicy] == string(asoannotations.ReconcilePolicyManage) {
57-
return azure.WithTransientError(azure.NewOperationNotDoneError(&infrav1.Future{
58-
Type: createOrUpdateFutureType,
59-
ResourceGroup: existing.GetNamespace(),
60-
Name: existing.GetName(),
61-
}), requeueInterval)
62-
}
49+
existingTags = t.GetDesiredTags(existing)
6350
}
6451

6552
existingTagsMap := converters.TagsToMap(existingTags)

azure/services/aso/tags_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ package aso
1818

1919
import (
2020
"encoding/json"
21-
"errors"
2221
"testing"
2322

2423
asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
25-
asoannotations "github.com/Azure/azure-service-operator/v2/pkg/common/annotations"
2624
. "github.com/onsi/gomega"
2725
"go.uber.org/mock/gomock"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2927
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
30-
"sigs.k8s.io/cluster-api-provider-azure/azure"
3128
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso/mock_aso"
3229
)
3330

@@ -97,7 +94,6 @@ func TestReconcileTags(t *testing.T) {
9794
tagsLastAppliedAnnotation: string(lastAppliedTagsJSON),
9895
})
9996
}
100-
tag.EXPECT().GetActualTags(existing).Return(test.existingTags)
10197
tag.EXPECT().GetDesiredTags(existing).Return(test.existingTags)
10298
tag.EXPECT().GetAdditionalTags().Return(test.additionalTagsSpec)
10399

@@ -128,27 +124,4 @@ func TestReconcileTags(t *testing.T) {
128124
err := reconcileTags[*asoresourcesv1.ResourceGroup](tag, existing, existing != nil, nil)
129125
g.Expect(err).To(HaveOccurred())
130126
})
131-
132-
t.Run("existing tags not up to date", func(t *testing.T) {
133-
g := NewWithT(t)
134-
135-
mockCtrl := gomock.NewController(t)
136-
tag := mock_aso.NewMockTagsGetterSetter[*asoresourcesv1.ResourceGroup](mockCtrl)
137-
138-
existing := &asoresourcesv1.ResourceGroup{
139-
ObjectMeta: metav1.ObjectMeta{
140-
Annotations: map[string]string{
141-
asoannotations.ReconcilePolicy: string(asoannotations.ReconcilePolicyManage),
142-
},
143-
},
144-
}
145-
tag.EXPECT().GetActualTags(existing).Return(infrav1.Tags{"new": "value"})
146-
tag.EXPECT().GetDesiredTags(existing).Return(infrav1.Tags{"old": "tag"})
147-
148-
err := reconcileTags[*asoresourcesv1.ResourceGroup](tag, existing, existing != nil, nil)
149-
g.Expect(azure.IsOperationNotDoneError(err)).To(BeTrue())
150-
var recerr azure.ReconcileError
151-
g.Expect(errors.As(err, &recerr)).To(BeTrue())
152-
g.Expect(recerr.IsTransient()).To(BeTrue())
153-
})
154127
}

azure/services/groups/spec.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ func (*GroupSpec) GetDesiredTags(resource *asoresourcesv1.ResourceGroup) infrav1
8686
return resource.Spec.Tags
8787
}
8888

89-
// GetActualTags implements aso.TagsGetterSetter.
90-
func (*GroupSpec) GetActualTags(resource *asoresourcesv1.ResourceGroup) infrav1.Tags {
91-
return resource.Status.Tags
92-
}
93-
9489
// SetTags implements aso.TagsGetterSetter.
9590
func (*GroupSpec) SetTags(resource *asoresourcesv1.ResourceGroup, tags infrav1.Tags) {
9691
resource.Spec.Tags = tags

azure/services/managedclusters/spec.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,6 @@ func (*ManagedClusterSpec) GetDesiredTags(resource *asocontainerservicev1.Manage
601601
return resource.Spec.Tags
602602
}
603603

604-
// GetActualTags implements aso.TagsGetterSetter.
605-
func (*ManagedClusterSpec) GetActualTags(resource *asocontainerservicev1.ManagedCluster) infrav1.Tags {
606-
return resource.Status.Tags
607-
}
608-
609604
// SetTags implements aso.TagsGetterSetter.
610605
func (*ManagedClusterSpec) SetTags(resource *asocontainerservicev1.ManagedCluster, tags infrav1.Tags) {
611606
resource.Spec.Tags = tags

0 commit comments

Comments
 (0)