Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
689df05
Add new DeleteAction for when Azure deletion is not possible
theunrepentantgeek Oct 16, 2025
2dc13f9
Support DeletionNotSupported in condition
theunrepentantgeek Oct 16, 2025
3f18ff3
Implement handling when delete is not permitted
theunrepentantgeek Oct 16, 2025
cd8cada
Add detatch annotation
theunrepentantgeek Oct 20, 2025
8122ea6
Add annotation to sample
theunrepentantgeek Oct 20, 2025
46d10ec
Add comments
theunrepentantgeek Oct 20, 2025
7d1a321
Add annotations for postgres samples
theunrepentantgeek Oct 20, 2025
ca1ab33
Fix MariaDB samples
theunrepentantgeek Oct 21, 2025
39a5597
Move addAnnotation helper onto TestContext
theunrepentantgeek Oct 21, 2025
9b81866
Update comment
theunrepentantgeek Oct 21, 2025
23e7eca
Fix MariaDB test
theunrepentantgeek Oct 21, 2025
cd52d64
Update samples
theunrepentantgeek Oct 22, 2025
a2c8196
Fix test
theunrepentantgeek Oct 22, 2025
d4a1b4b
Fix samples
theunrepentantgeek Oct 22, 2025
8f62941
Update more tests
theunrepentantgeek Oct 23, 2025
97c4e27
Update samples
theunrepentantgeek Oct 24, 2025
3f3e991
Update CRUD tests
theunrepentantgeek Oct 24, 2025
df5f34a
Fix test
theunrepentantgeek Oct 24, 2025
69f2176
Update tests
theunrepentantgeek Oct 28, 2025
c1c2a7e
Update samples
theunrepentantgeek Oct 29, 2025
328dc82
Update more tests
theunrepentantgeek Oct 29, 2025
2e9d63a
Fix more tests
theunrepentantgeek Oct 29, 2025
0876a21
Rename tests
theunrepentantgeek Oct 29, 2025
059dd69
Fix more tests
theunrepentantgeek Oct 29, 2025
67dfa04
Update tests
theunrepentantgeek Oct 30, 2025
4f0e78d
Tweak test
theunrepentantgeek Oct 30, 2025
fc39fd8
Fix test
theunrepentantgeek Nov 2, 2025
7b843df
Fix another test
theunrepentantgeek Nov 3, 2025
b346274
Fix test
theunrepentantgeek Nov 4, 2025
689c2b3
Update another test
theunrepentantgeek Nov 5, 2025
a4c5049
Fix test
theunrepentantgeek Nov 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

. "github.com/onsi/gomega"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -71,6 +72,8 @@ func Test_DataProtection_BackupInstance_20231101_CRUD(t *testing.T) {
},
}

addAnnotation(&blobService.ObjectMeta, "serviceoperator.azure.com/reconcile-policy", "detach-on-delete")

blobContainer := &storage.StorageAccountsBlobServicesContainer{
ObjectMeta: tc.MakeObjectMeta("velero"),
Spec: storage.StorageAccountsBlobServicesContainer_Spec{
Expand Down Expand Up @@ -308,3 +311,17 @@ func newBackupInstanceManagedCluster(tc *testcommon.KubePerTestContext, rg *reso
}
return cluster
}

func addAnnotation(
obj *v1.ObjectMeta,
key string,
value string,
) {
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}

annotations[key] = value
obj.SetAnnotations(annotations)
}
5 changes: 3 additions & 2 deletions v2/internal/reconcilers/arm/azure_generic_arm_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const (
type DeleteAction string

const (
DeleteActionBeginDelete = DeleteAction("BeginDelete")
DeleteActionMonitorDelete = DeleteAction("MonitorDelete")
DeleteActionBeginDelete = DeleteAction("BeginDelete")
DeleteActionMonitorDelete = DeleteAction("MonitorDelete")
DeleteActionNotPossibleInAzure = DeleteAction("NotPossibleInAzure")
)

type (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-service-operator/v2/internal/reconcilers/arm/errorclassification"
"github.com/Azure/azure-service-operator/v2/internal/reflecthelpers"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/common/annotations"
"github.com/Azure/azure-service-operator/v2/pkg/common/labels"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
Expand Down Expand Up @@ -129,6 +130,11 @@ func (r *azureDeploymentReconcilerInstance) DetermineDeleteAction() (DeleteActio
return DeleteActionMonitorDelete, r.MonitorDelete, nil
}

if !genruntime.ResourceOperationDelete.IsSupportedBy(r.Obj) {
// Resource doesn't support delete, so we just remove the finalizer and stop managing it
return DeleteActionNotPossibleInAzure, r.DeleteNotPossibleInAzure, nil
}

return DeleteActionBeginDelete, r.StartDeleteOfResource, nil
}

Expand Down Expand Up @@ -205,6 +211,23 @@ func (r *azureDeploymentReconcilerInstance) MonitorDelete(ctx context.Context) (
return ctrl.Result{Requeue: true, RequeueAfter: retryAfter}, nil
}

// DeleteNotPossibleInAzure is used when the underlying Azure resource doesn't support direct deletion, so we return an error.
func (r *azureDeploymentReconcilerInstance) DeleteNotPossibleInAzure(ctx context.Context) (ctrl.Result, error) {
msg := fmt.Sprintf(
"Resource does not support deletion in Azure; set annotation %s: %s to permit deletion in Kubernetes",
annotations.ReconcilePolicy,
annotations.ReconcilePolicyDetachOnDelete)
r.Log.V(Verbose).Info(msg)
r.Recorder.Event(r.Obj, v1.EventTypeNormal, string(DeleteActionNotPossibleInAzure), msg)

// Return a meaningful error so that the Ready condition is updated to show the user why the resource can't yet be deleted.
return ctrl.Result{},
conditions.NewReadyConditionImpactingError(
eris.New(msg),
conditions.ConditionSeverityError,
conditions.ReasonDeletionNotSupported)
}

func (r *azureDeploymentReconcilerInstance) BeginCreateOrUpdateResource(
ctx context.Context,
) (ctrl.Result, error) {
Expand Down
1 change: 1 addition & 0 deletions v2/pkg/genruntime/conditions/ready_condition_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
ReasonReconcileBlocked = Reason{Name: "ReconciliationBlocked", RetryClassification: retry.Slow}
ReasonReconcilePostponed = Reason{Name: "ReconciliationPostponed", RetryClassification: retry.Slow}
ReasonPostReconcileFailure = Reason{Name: "PostReconciliationFailure", RetryClassification: retry.Slow}
ReasonDeletionNotSupported = Reason{Name: "DeletionNotSupportedInAzure", RetryClassification: retry.None}
)

// ReasonFailed is a catch-all error code for when we don't have a more specific error classification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: StorageAccountsBlobService
metadata:
name: sqlstorageservice
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: asotestsqlstorageref
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersAdvancedThreatProtectionSetting
metadata:
name: aso-sample-atp
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-sqlserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersAuditingSetting
metadata:
name: aso-sample-audit
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-sqlserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersConnectionPolicy
metadata:
name: aso-sample-connpolicy
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-sqlserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesAdvancedThreatProtectionSetting
metadata:
name: aso-sample-atp
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesAuditingSetting
metadata:
name: aso-sample-audit
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesBackupLongTermRetentionPolicy
metadata:
name: aso-sample-longterm-backup-policy
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesBackupShortTermRetentionPolicy
metadata:
name: aso-sample-shortterm-backup-policy
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesSecurityAlertPolicy
metadata:
name: aso-sample-alertpolicy
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersDatabasesTransparentDataEncryption
metadata:
name: aso-sample-encrypt
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: ServersSecurityAlertPolicy
metadata:
name: aso-sample-alertpolicy
namespace: default
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: aso-sample-sqlserver
Expand Down
Loading