Skip to content

Commit 6d656f9

Browse files
authored
Merge pull request #4380 from nojnhuh/aso-tags-and-ready-error
[release-1.11] ASO: Return readyErr over not done err when tags fail
2 parents 7f2ea36 + 7bf55a1 commit 6d656f9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

azure/services/aso/aso.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func New(ctrlClient client.Client, clusterName string) *Service {
6565

6666
// CreateOrUpdateResource implements the logic for creating a new or updating an
6767
// existing resource with ASO.
68+
//
69+
//nolint:gocyclo // This function is necessarily complex.
6870
func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter, serviceName string) (result genruntime.MetaObject, err error) {
6971
ctx, log, done := tele.StartSpanWithLogger(ctx, "services.aso.CreateOrUpdateResource")
7072
defer done()
@@ -155,6 +157,9 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
155157

156158
if t, ok := spec.(TagsGetterSetter); ok {
157159
if err := reconcileTags(t, existing, parameters); err != nil {
160+
if azure.IsOperationNotDoneError(err) && readyErr != nil {
161+
return nil, readyErr
162+
}
158163
return nil, errors.Wrap(err, "failed to reconcile tags")
159164
}
160165
}

azure/services/aso/aso_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,71 @@ func TestCreateOrUpdateResource(t *testing.T) {
822822
g.Expect(err.Error()).To(ContainSubstring("failed to reconcile tags"))
823823
})
824824

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

0 commit comments

Comments
 (0)