Skip to content

Commit

Permalink
ASO: Return readyErr over not done err when tags fail
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Dec 13, 2023
1 parent 7f2ea36 commit d6ed634
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions azure/services/aso/aso.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso

if t, ok := spec.(TagsGetterSetter); ok {
if err := reconcileTags(t, existing, parameters); err != nil {
if azure.IsOperationNotDoneError(err) && readyErr != nil {
return nil, readyErr
}
return nil, errors.Wrap(err, "failed to reconcile tags")
}
}
Expand Down
65 changes: 65 additions & 0 deletions azure/services/aso/aso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,71 @@ func TestCreateOrUpdateResource(t *testing.T) {
g.Expect(err.Error()).To(ContainSubstring("failed to reconcile tags"))
})

t.Run("with tags not done error and readyErr", func(t *testing.T) {
g := NewGomegaWithT(t)

sch := runtime.NewScheme()
g.Expect(asoresourcesv1.AddToScheme(sch)).To(Succeed())
c := fakeclient.NewClientBuilder().
WithScheme(sch).
Build()
s := New(c, clusterName)

mockCtrl := gomock.NewController(t)
specMock := struct {
*mock_azure.MockASOResourceSpecGetter
*mock_aso.MockTagsGetterSetter
}{
MockASOResourceSpecGetter: mock_azure.NewMockASOResourceSpecGetter(mockCtrl),
MockTagsGetterSetter: mock_aso.NewMockTagsGetterSetter(mockCtrl),
}
specMock.MockASOResourceSpecGetter.EXPECT().ResourceRef().Return(&asoresourcesv1.ResourceGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
})
specMock.MockASOResourceSpecGetter.EXPECT().Parameters(gomockinternal.AContext(), gomock.Any()).DoAndReturn(func(_ context.Context, group *asoresourcesv1.ResourceGroup) (*asoresourcesv1.ResourceGroup, error) {
return group, nil
})

existing := &asoresourcesv1.ResourceGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
Labels: map[string]string{
infrav1.OwnedByClusterLabelKey: clusterName,
},
Annotations: map[string]string{
asoannotations.ReconcilePolicy: string(asoannotations.ReconcilePolicyManage),
},
},
Spec: asoresourcesv1.ResourceGroup_Spec{
Tags: map[string]string{"desired": "tags"},
},
Status: asoresourcesv1.ResourceGroup_STATUS{
Tags: map[string]string{"actual": "tags"},
Conditions: []conditions.Condition{
{
Type: conditions.ConditionTypeReady,
Status: metav1.ConditionFalse,
Message: "not ready :(",
},
},
},
}

specMock.MockTagsGetterSetter.EXPECT().GetActualTags(gomock.Any()).Return(existing.Status.Tags, nil)
specMock.MockTagsGetterSetter.EXPECT().GetDesiredTags(gomock.Any()).Return(existing.Spec.Tags, nil)

ctx := context.Background()
g.Expect(c.Create(ctx, existing)).To(Succeed())

result, err := s.CreateOrUpdateResource(ctx, specMock, "service")
g.Expect(result).To(BeNil())
g.Expect(err.Error()).To(ContainSubstring("not ready :("))
})

t.Run("reconcile policy annotation resets after un-pause", func(t *testing.T) {
g := NewGomegaWithT(t)

Expand Down

0 comments on commit d6ed634

Please sign in to comment.