Skip to content

Commit b4f1bec

Browse files
authored
Merge pull request #4541 from nojnhuh/aso-tags-1.13
[release-1.13] only consider spec in existing when reconciling ASO tags
2 parents 6bec637 + 92d4590 commit b4f1bec

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
@@ -152,9 +152,6 @@ func (r *reconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.A
152152

153153
if t, ok := spec.(TagsGetterSetter[T]); ok {
154154
if err := reconcileTags(t, existing, resourceExists, parameters); err != nil {
155-
if azure.IsOperationNotDoneError(err) && readyErr != nil {
156-
return zero, readyErr
157-
}
158155
return zero, errors.Wrap(err, "failed to reconcile tags")
159156
}
160157
}

azure/services/aso/aso_test.go

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

734-
specMock.MockTagsGetterSetter.EXPECT().GetActualTags(gomock.Any()).Return(nil)
735734
specMock.MockTagsGetterSetter.EXPECT().GetAdditionalTags().Return(nil)
736735
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(nil).Times(2)
737736
specMock.MockTagsGetterSetter.EXPECT().SetTags(gomock.Any(), gomock.Any())
@@ -823,71 +822,6 @@ func TestCreateOrUpdateResource(t *testing.T) {
823822
g.Expect(err.Error()).To(ContainSubstring("failed to reconcile tags"))
824823
})
825824

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

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)