Skip to content

Commit 47af64b

Browse files
Improve resource condition/error when deletion is not possible in Azure (#4987)
* Add new DeleteAction for when Azure deletion is not possible * Support DeletionNotSupported in condition * Implement handling when delete is not permitted * Add detatch annotation * Add annotation to sample * Add comments * Add annotations for postgres samples * Fix MariaDB samples * Move addAnnotation helper onto TestContext * Update comment * Fix MariaDB test * Update samples * Fix test * Fix samples * Update more tests * Update samples * Update CRUD tests * Fix test * Update tests * Update samples * Update more tests * Fix more tests * Rename tests * Fix more tests * Update tests * Tweak test * Fix test * Fix another test * Fix test * Update another test * Fix test * Check for resource deletion by other causes * Update recording * Change type of extension * Update comments on annotation use * Update comments in samples * Clean up comment * Expose other errors as well * Fix typo. * Fix lint error. * Fix lint issues * Tidy last comments * Suppress test with owner update race
1 parent 7453010 commit 47af64b

File tree

76 files changed

+432
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+432
-81
lines changed

v2/api/dbforpostgresql/customizations/flexible_servers_firewall_rule_extensions.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ import (
1818
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
1919
)
2020

21-
var _ extensions.PreReconciliationChecker = &FlexibleServersFirewallRuleExtension{}
21+
var _ extensions.PreReconciliationOwnerChecker = &FlexibleServersFirewallRuleExtension{}
2222

23-
func (ext *FlexibleServersFirewallRuleExtension) PreReconcileCheck(
23+
func (ext *FlexibleServersFirewallRuleExtension) PreReconcileOwnerCheck(
2424
ctx context.Context,
25-
obj genruntime.MetaObject,
2625
owner genruntime.MetaObject,
2726
resourceResolver *resolver.Resolver,
2827
armClient *genericarmclient.GenericClient,
2928
log logr.Logger,
30-
next extensions.PreReconcileCheckFunc,
29+
next extensions.PreReconcileOwnerCheckFunc,
3130
) (extensions.PreReconcileCheckResult, error) {
3231
// Check to see if our owning server is ready for the database to be reconciled
3332
// Owner nil can happen if the server/owner of the firewall rule is referenced by armID
@@ -43,5 +42,5 @@ func (ext *FlexibleServersFirewallRuleExtension) PreReconcileCheck(
4342
}
4443
}
4544

46-
return next(ctx, obj, owner, resourceResolver, armClient, log)
45+
return next(ctx, owner, resourceResolver, armClient, log)
4746
}

v2/api/keyvault/customizations/vault_extensions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
var _ extensions.ARMResourceModifier = &VaultExtension{}
3535

36-
//nolint:staticcheck // Underscores for enum values is our convention in ASO
3736
const (
3837
CreateMode_Default = "default"
3938
CreateMode_Recover = "recover"
@@ -275,7 +274,7 @@ func (*VaultExtension) getOwner(
275274
var id *arm.ResourceID
276275

277276
// No need to wait for resources that don't have an owner
278-
switch owner.Result { // nolint: exhaustive
277+
switch owner.Result {
279278
case resolver.OwnerFoundKubernetes:
280279
rg, ok := owner.Owner.(*resources.ResourceGroup)
281280
if !ok {

v2/internal/controllers/crd_dataprotection_backupinstance_20231101_test.go renamed to v2/internal/controllers/dataprotection_backupinstance_crud_20231101_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func Test_DataProtection_BackupInstance_20231101_CRUD(t *testing.T) {
7171
},
7272
}
7373

74+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
75+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
76+
tc.AddAnnotation(&blobService.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
77+
7478
blobContainer := &storage.StorageAccountsBlobServicesContainer{
7579
ObjectMeta: tc.MakeObjectMeta("velero"),
7680
Spec: storage.StorageAccountsBlobServicesContainer_Spec{

v2/internal/controllers/dbformysql_flexibleserver_20210501_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ func MySQLFlexibleServer_Configuration_20220101_CRUD(tc *testcommon.KubePerTestC
244244
Value: to.Ptr("20"),
245245
},
246246
}
247+
248+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
249+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
250+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
251+
247252
tc.CreateResourceAndWait(configuration)
248253
tc.Expect(configuration.Status.Id).ToNot(BeNil())
249254
}

v2/internal/controllers/dbformysql_flexibleserver_20230630_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ func MySQLFlexibleServer_Configuration_20230630_CRUD(tc *testcommon.KubePerTestC
243243
Value: to.Ptr("20"),
244244
},
245245
}
246+
247+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
248+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
249+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
250+
246251
tc.CreateResourceAndWait(configuration)
247252
tc.Expect(configuration.Status.Id).ToNot(BeNil())
248253
}

v2/internal/controllers/dbformysql_flexibleserver_20231230_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ func MySQLFlexibleServer_Configuration_20231230_CRUD(tc *testcommon.KubePerTestC
238238
Value: to.Ptr("20"),
239239
},
240240
}
241+
242+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
243+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
244+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
245+
241246
tc.CreateResourceAndWait(configuration)
242247
tc.Expect(configuration.Status.Id).ToNot(BeNil())
243248
}

v2/internal/controllers/dbforpostgresql_flexibleserver_crud_v1api20221201_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ func FlexibleServer_Configuration_20221201_CRUD(tc *testcommon.KubePerTestContex
167167
},
168168
}
169169

170+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
171+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
172+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
173+
170174
tc.CreateResourceAndWait(configuration)
171-
// This isn't a "real" resource so it cannot be deleted directly
172-
// defer tc.DeleteResourceAndWait(configuration)
173175

174176
tc.Expect(configuration.Status.Id).ToNot(BeNil())
175177
tc.Expect(configuration.Status.Value).To(Equal(to.Ptr("READ")))

v2/internal/controllers/dbforpostgresql_flexibleserver_crud_v1api20230601preview_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ func FlexibleServer_Configuration_20230601Preview_CRUD(tc *testcommon.KubePerTes
204204
},
205205
}
206206

207+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
208+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
209+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
210+
207211
tc.CreateResourceAndWait(configuration)
208-
// This isn't a "real" resource so it cannot be deleted directly
209-
// defer tc.DeleteResourceAndWait(configuration)
210212

211213
tc.Expect(configuration.Status.Id).ToNot(BeNil())
212214
tc.Expect(configuration.Status.Value).To(Equal(to.Ptr("READ")))

v2/internal/controllers/dbforpostgresql_flexibleserver_crud_v1api20240801_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,11 @@ func FlexibleServer_Configuration_20240801_CRUD(tc *testcommon.KubePerTestContex
226226
},
227227
}
228228

229+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
230+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
231+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
232+
229233
tc.CreateResourceAndWait(configuration)
230-
// This isn't a "real" resource so it cannot be deleted directly
231-
// defer tc.DeleteResourceAndWait(configuration)
232234

233235
tc.Expect(configuration.Status.Id).ToNot(BeNil())
234236
tc.Expect(configuration.Status.Value).To(Equal(to.Ptr("READ")))
@@ -261,9 +263,11 @@ func FlexibleServer_AdvancedThreatProtection_20240801_CRUD(tc *testcommon.KubePe
261263
},
262264
}
263265

266+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
267+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
268+
tc.AddAnnotation(&threatProtection.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
269+
264270
tc.CreateResourceAndWait(threatProtection)
265-
// This isn't a "real" resource so it cannot be deleted directly
266-
// defer tc.DeleteResourceAndWait(threatProtection)
267271

268272
tc.Expect(threatProtection.Status.Id).ToNot(BeNil())
269273
}

v2/internal/controllers/dbforpostgresql_flexibleserver_crud_v1api20250801_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,11 @@ func FlexibleServer_Configuration_20250801_CRUD(tc *testcommon.KubePerTestContex
241241
},
242242
}
243243

244+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
245+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
246+
tc.AddAnnotation(&configuration.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
247+
244248
tc.CreateResourceAndWait(configuration)
245-
// This isn't a "real" resource so it cannot be deleted directly
246-
// defer tc.DeleteResourceAndWait(configuration)
247249

248250
tc.Expect(configuration.Status.Id).ToNot(BeNil())
249251
tc.Expect(configuration.Status.Value).To(Equal(to.Ptr("READ")))
@@ -276,9 +278,11 @@ func FlexibleServer_AdvancedThreatProtection_20250801_CRUD(tc *testcommon.KubePe
276278
},
277279
}
278280

281+
// Don't try to delete directly, this is not a real resource - to delete it in Azure you must delete its parent.
282+
// We can delete it from the cluster by applying this annotation, but this won't change anything in Azure.
283+
tc.AddAnnotation(&threatProtection.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")
284+
279285
tc.CreateResourceAndWait(threatProtection)
280-
// This isn't a "real" resource so it cannot be deleted directly
281-
// defer tc.DeleteResourceAndWait(threatProtection)
282286

283287
tc.Expect(threatProtection.Status.Id).ToNot(BeNil())
284288
}

0 commit comments

Comments
 (0)