Skip to content

Commit 1db4717

Browse files
authored
Merge pull request #4152 from nojnhuh/aso-no-wait-for-ready
[release-1.11] don't wait for ASO resources to be ready for updates
2 parents 174bca0 + 8945377 commit 1db4717

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

azure/services/aso/aso.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
7575

7676
log = log.WithValues("service", serviceName, "resource", resourceName, "namespace", resourceNamespace)
7777

78+
var readyErr error
7879
var adopt bool
7980
var existing genruntime.MetaObject
8081
if err := s.Client.Get(ctx, client.ObjectKeyFromObject(resource), resource); err != nil {
@@ -96,7 +97,6 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
9697
if !readyExists {
9798
return nil, azure.WithTransientError(errors.New("ready status unknown"), requeueInterval)
9899
}
99-
var readyErr error
100100
if cond := conds[i]; cond.Status != metav1.ConditionTrue {
101101
switch {
102102
case cond.Reason == conditions.ReasonAzureResourceNotFound.Name &&
@@ -124,9 +124,10 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
124124

125125
if readyErr != nil {
126126
if conds[i].Severity == conditions.ConditionSeverityError {
127-
return nil, azure.WithTerminalError(readyErr)
127+
readyErr = azure.WithTerminalError(readyErr)
128+
} else {
129+
readyErr = azure.WithTransientError(readyErr, requeueInterval)
128130
}
129-
return nil, azure.WithTransientError(readyErr, requeueInterval)
130131
}
131132
}
132133
}
@@ -199,6 +200,11 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
199200

200201
diff := cmp.Diff(existing, parameters)
201202
if diff == "" {
203+
if readyErr != nil {
204+
// Only return this error when the resource is up to date in order to permit updates from
205+
// Parameters which may fix the resource's current state.
206+
return nil, readyErr
207+
}
202208
log.V(2).Info("resource up to date")
203209
return existing, nil
204210
}

azure/services/aso/aso_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func TestCreateOrUpdateResource(t *testing.T) {
175175
Namespace: "namespace",
176176
},
177177
})
178+
specMock.EXPECT().Parameters(gomockinternal.AContext(), gomock.Not(gomock.Nil())).DoAndReturn(func(_ context.Context, group *asoresourcesv1.ResourceGroup) (*asoresourcesv1.ResourceGroup, error) {
179+
return group, nil
180+
})
181+
specMock.EXPECT().WasManaged(gomock.Any()).Return(false)
178182

179183
ctx := context.Background()
180184
g.Expect(c.Create(ctx, &asoresourcesv1.ResourceGroup{
@@ -184,6 +188,9 @@ func TestCreateOrUpdateResource(t *testing.T) {
184188
Labels: map[string]string{
185189
infrav1.OwnedByClusterLabelKey: clusterName,
186190
},
191+
Annotations: map[string]string{
192+
asoannotations.PerResourceSecret: "cluster-aso-secret",
193+
},
187194
},
188195
Status: asoresourcesv1.ResourceGroup_STATUS{
189196
Conditions: []conditions.Condition{
@@ -203,6 +210,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
203210
var recerr azure.ReconcileError
204211
g.Expect(errors.As(err, &recerr)).To(BeTrue())
205212
g.Expect(recerr.IsTransient()).To(BeTrue())
213+
g.Expect(recerr.IsTerminal()).To(BeFalse())
206214
})
207215

208216
t.Run("resource is not ready in reconciling state", func(t *testing.T) {
@@ -223,6 +231,10 @@ func TestCreateOrUpdateResource(t *testing.T) {
223231
Namespace: "namespace",
224232
},
225233
})
234+
specMock.EXPECT().Parameters(gomockinternal.AContext(), gomock.Not(gomock.Nil())).DoAndReturn(func(_ context.Context, group *asoresourcesv1.ResourceGroup) (*asoresourcesv1.ResourceGroup, error) {
235+
return group, nil
236+
})
237+
specMock.EXPECT().WasManaged(gomock.Any()).Return(false)
226238

227239
ctx := context.Background()
228240
g.Expect(c.Create(ctx, &asoresourcesv1.ResourceGroup{
@@ -232,6 +244,9 @@ func TestCreateOrUpdateResource(t *testing.T) {
232244
Labels: map[string]string{
233245
infrav1.OwnedByClusterLabelKey: clusterName,
234246
},
247+
Annotations: map[string]string{
248+
asoannotations.PerResourceSecret: "cluster-aso-secret",
249+
},
235250
},
236251
Status: asoresourcesv1.ResourceGroup_STATUS{
237252
Conditions: []conditions.Condition{
@@ -268,6 +283,10 @@ func TestCreateOrUpdateResource(t *testing.T) {
268283
Namespace: "namespace",
269284
},
270285
})
286+
specMock.EXPECT().Parameters(gomockinternal.AContext(), gomock.Not(gomock.Nil())).DoAndReturn(func(_ context.Context, group *asoresourcesv1.ResourceGroup) (*asoresourcesv1.ResourceGroup, error) {
287+
return group, nil
288+
})
289+
specMock.EXPECT().WasManaged(gomock.Any()).Return(false)
271290

272291
ctx := context.Background()
273292
g.Expect(c.Create(ctx, &asoresourcesv1.ResourceGroup{
@@ -277,6 +296,9 @@ func TestCreateOrUpdateResource(t *testing.T) {
277296
Labels: map[string]string{
278297
infrav1.OwnedByClusterLabelKey: clusterName,
279298
},
299+
Annotations: map[string]string{
300+
asoannotations.PerResourceSecret: "cluster-aso-secret",
301+
},
280302
},
281303
Status: asoresourcesv1.ResourceGroup_STATUS{
282304
Conditions: []conditions.Condition{
@@ -296,6 +318,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
296318
var recerr azure.ReconcileError
297319
g.Expect(errors.As(err, &recerr)).To(BeTrue())
298320
g.Expect(recerr.IsTerminal()).To(BeTrue())
321+
g.Expect(recerr.IsTransient()).To(BeFalse())
299322
})
300323

301324
t.Run("error getting existing resource", func(t *testing.T) {

0 commit comments

Comments
 (0)