Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.11] ASO: Return readyErr over not done err when tags fail #4380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azure/services/aso/aso.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func New(ctrlClient client.Client, clusterName string) *Service {

// CreateOrUpdateResource implements the logic for creating a new or updating an
// existing resource with ASO.
//
//nolint:gocyclo // This function is necessarily complex.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

I've looked before for any low-hanging fruit to split any decent-sized chunk of this into its own function, but there's enough shared state generated within this function that I think any new helper function would end up taking a lot of random-looking parameters and return a lot of random-looking values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mboersma @CecileRobertMichon Had to drop the lgtm to add this change, PTAL.

func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter, serviceName string) (result genruntime.MetaObject, err error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "services.aso.CreateOrUpdateResource")
defer done()
Expand Down Expand Up @@ -155,6 +157,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was the cause for the merge conflict, so this changes zero to nil from the original PR to account for the generics changes that were introduced for 1.12.

}
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