Skip to content

Commit c2dcb64

Browse files
committed
add finalizer virtualworkspace
On-behalf-of: SAP <[email protected]> Signed-off-by: Simon Bein <[email protected]>
1 parent 839e897 commit c2dcb64

35 files changed

+2016
-13
lines changed

config/crds/core.kcp.io_logicalclusters.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ spec:
6969
DirectlyDeletable indicates that this logical cluster can be directly deleted by the user
7070
from within by deleting the LogicalCluster object.
7171
type: boolean
72+
finalizers:
73+
description: |-
74+
Finalizers are set on creation by the system and copied to status when
75+
finalization starts.
76+
items:
77+
description: |-
78+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
79+
finalizer controller.
80+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
81+
type: string
82+
type: array
7283
initializers:
7384
description: |-
7485
initializers are set on creation by the system and copied to status when
@@ -176,6 +187,18 @@ spec:
176187
- type
177188
type: object
178189
type: array
190+
finalizers:
191+
description: |-
192+
Finalizers are set on creation by the system and must be cleared
193+
by a controller before the logical cluster can be deleted. The LogicalCluster object
194+
will stay in the phase "Deleting" until all finalizers are cleared.
195+
items:
196+
description: |-
197+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
198+
finalizer controller.
199+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
200+
type: string
201+
type: array
179202
initializers:
180203
description: |-
181204
initializers are set on creation by the system and must be cleared

config/crds/tenancy.kcp.io_workspaces.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ spec:
279279
- type
280280
type: object
281281
type: array
282+
finalizers:
283+
description: |-
284+
finalizers must be cleared by a controller before the workspace is being
285+
deleted.
286+
items:
287+
description: |-
288+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
289+
finalizer controller.
290+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
291+
type: string
292+
type: array
282293
initializers:
283294
description: |-
284295
initializers must be cleared by a controller before the workspace is ready

config/crds/tenancy.kcp.io_workspacetypes.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ spec:
157157
type: object
158158
type: array
159159
type: object
160+
finalizer:
161+
description: |-
162+
Finalizer determines if this WorkspaceType has an associated finalizing
163+
controller. These controllers are used to add functionality to a Workspace;
164+
all controllers must finish their work before the Workspace is being deleted.
165+
166+
One finalizing controller is supported per WorkspaceType; the identifier
167+
for this finalizer will be a colon-delimited string using the workspace in which
168+
the WorkspaceType is defined, and the type's name. For example, if a
169+
WorkspaceType `example` is created in the `root:org` workspace, the implicit
170+
finalizer name is `root:org:example`.
171+
type: boolean
160172
initializer:
161173
description: |-
162174
initializer determines if this WorkspaceType has an associated initializing

config/root-phase0/apiexport-tenancy.kcp.io.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ spec:
1414
crd: {}
1515
- group: tenancy.kcp.io
1616
name: workspaces
17-
schema: v250421-25d98218b.workspaces.tenancy.kcp.io
17+
schema: v250820-d9a41c325.workspaces.tenancy.kcp.io
1818
storage:
1919
crd: {}
2020
- group: tenancy.kcp.io
2121
name: workspacetypes
22-
schema: v250806-4c99c4583.workspacetypes.tenancy.kcp.io
22+
schema: v250603-d4d365c8e.workspacetypes.tenancy.kcp.io
2323
storage:
2424
crd: {}
2525
status: {}

config/root-phase0/apiresourceschema-logicalclusters.core.kcp.io.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v241020-fce06d31d.logicalclusters.core.kcp.io
5+
name: v250820-d9a41c325.logicalclusters.core.kcp.io
66
spec:
77
group: core.kcp.io
88
names:
@@ -67,6 +67,17 @@ spec:
6767
DirectlyDeletable indicates that this logical cluster can be directly deleted by the user
6868
from within by deleting the LogicalCluster object.
6969
type: boolean
70+
finalizers:
71+
description: |-
72+
Finalizers are set on creation by the system and copied to status when
73+
finalization starts.
74+
items:
75+
description: |-
76+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
77+
finalizer controller.
78+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
79+
type: string
80+
type: array
7081
initializers:
7182
description: |-
7283
initializers are set on creation by the system and copied to status when
@@ -174,6 +185,18 @@ spec:
174185
- type
175186
type: object
176187
type: array
188+
finalizers:
189+
description: |-
190+
Finalizers are set on creation by the system and must be cleared
191+
by a controller before the logical cluster can be deleted. The LogicalCluster object
192+
will stay in the phase "Deleting" until all finalizers are cleared.
193+
items:
194+
description: |-
195+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
196+
finalizer controller.
197+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
198+
type: string
199+
type: array
177200
initializers:
178201
description: |-
179202
initializers are set on creation by the system and must be cleared

config/root-phase0/apiresourceschema-workspaces.tenancy.kcp.io.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v250421-25d98218b.workspaces.tenancy.kcp.io
5+
name: v250820-d9a41c325.workspaces.tenancy.kcp.io
66
spec:
77
group: tenancy.kcp.io
88
names:
@@ -277,6 +277,17 @@ spec:
277277
- type
278278
type: object
279279
type: array
280+
finalizers:
281+
description: |-
282+
finalizers must be cleared by a controller before the workspace is being
283+
deleted.
284+
items:
285+
description: |-
286+
LogicalClusterFinalizer is a unique string corresponding to a logical cluster
287+
finalizer controller.
288+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(:[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:[a-z0-9][a-z0-9]([-a-z0-9]*[a-z0-9])?))|(system:.+)$
289+
type: string
290+
type: array
280291
initializers:
281292
description: |-
282293
initializers must be cleared by a controller before the workspace is ready

config/root-phase0/apiresourceschema-workspacetypes.tenancy.kcp.io.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v250806-4c99c4583.workspacetypes.tenancy.kcp.io
5+
name: v250603-d4d365c8e.workspacetypes.tenancy.kcp.io
66
spec:
77
group: tenancy.kcp.io
88
names:
@@ -155,6 +155,18 @@ spec:
155155
type: object
156156
type: array
157157
type: object
158+
finalizer:
159+
description: |-
160+
Finalizer determines if this WorkspaceType has an associated finalizing
161+
controller. These controllers are used to add functionality to a Workspace;
162+
all controllers must finish their work before the Workspace is being deleted.
163+
164+
One finalizing controller is supported per WorkspaceType; the identifier
165+
for this finalizer will be a colon-delimited string using the workspace in which
166+
the WorkspaceType is defined, and the type's name. For example, if a
167+
WorkspaceType `example` is created in the `root:org` workspace, the implicit
168+
finalizer name is `root:org:example`.
169+
type: boolean
158170
initializer:
159171
description: |-
160172
initializer determines if this WorkspaceType has an associated initializing

pkg/admission/logicalcluster/admission.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ func (o *plugin) Admit(ctx context.Context, a admission.Attributes, _ admission.
111111

112112
logicalCluster.Status.Initializers = logicalCluster.Spec.Initializers
113113

114+
logicalCluster.Status.Finalizers = logicalCluster.Spec.Finalizers
115+
114116
return updateUnstructured(u, logicalCluster)
115117
}
116118

pkg/openapi/zz_generated.openapi.go

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/reconciler/core/logicalcluster/logicalcluster_reconcile_metadata.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/klog/v2"
2727

2828
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
29+
"github.com/kcp-dev/kcp/sdk/apis/tenancy/finalization"
2930
"github.com/kcp-dev/kcp/sdk/apis/tenancy/initialization"
3031
tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1"
3132
)
@@ -39,7 +40,7 @@ func (r *metaDataReconciler) reconcile(ctx context.Context, logicalCluster *core
3940

4041
expected := string(logicalCluster.Status.Phase)
4142
if !logicalCluster.DeletionTimestamp.IsZero() {
42-
expected = "Deleting"
43+
expected = string(corev1alpha1.LogicalClusterPhaseDeleting)
4344
}
4445
if got := logicalCluster.Labels[tenancyv1alpha1.WorkspacePhaseLabel]; got != expected {
4546
if logicalCluster.Labels == nil {
@@ -49,6 +50,7 @@ func (r *metaDataReconciler) reconcile(ctx context.Context, logicalCluster *core
4950
changed = true
5051
}
5152

53+
// add initializers from the status as hashed labels
5254
initializerKeys := sets.New[string]()
5355
for _, initializer := range logicalCluster.Status.Initializers {
5456
key, value := initialization.InitializerToLabel(initializer)
@@ -62,13 +64,36 @@ func (r *metaDataReconciler) reconcile(ctx context.Context, logicalCluster *core
6264
}
6365
}
6466

67+
// add finalizers from the status as hashed labels
68+
finalizerKeys := sets.New[string]()
69+
for _, finalizer := range logicalCluster.Status.Finalizers {
70+
key, value := finalization.FinalizerToLabel(finalizer)
71+
finalizerKeys.Insert(key)
72+
if got, expected := logicalCluster.Labels[key], value; got != expected {
73+
if logicalCluster.Labels == nil {
74+
logicalCluster.Labels = map[string]string{}
75+
}
76+
logicalCluster.Labels[key] = value
77+
changed = true
78+
}
79+
}
80+
81+
// remove any initializers/finalizers from labels, which have been
82+
// removed in the status
6583
for key := range logicalCluster.Labels {
6684
if strings.HasPrefix(key, tenancyv1alpha1.WorkspaceInitializerLabelPrefix) {
6785
if !initializerKeys.Has(key) {
6886
delete(logicalCluster.Labels, key)
6987
changed = true
7088
}
7189
}
90+
91+
if strings.HasPrefix(key, tenancyv1alpha1.WorkspaceFinalizerLabelPrefix) {
92+
if !finalizerKeys.Has(key) {
93+
delete(logicalCluster.Labels, key)
94+
changed = true
95+
}
96+
}
7297
}
7398

7499
if logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseReady {

0 commit comments

Comments
 (0)