Skip to content

Commit 93ba7a7

Browse files
committed
Add API for cleanup spec and status
This commit introduces the operand cleanup API that allows configuring the CSV to enable cleanup of CRs managed by this CSV's operator when the CSV is deleted. This also includes a status.cleanup block that will be used to show the progress of cleanup.
1 parent 718d279 commit 93ba7a7

File tree

3 files changed

+115
-11
lines changed

3 files changed

+115
-11
lines changed

crds/operators.coreos.com_clusterserviceversions.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ spec:
288288
type: string
289289
version:
290290
type: string
291+
cleanup:
292+
description: Cleanup specifies the cleanup behaviour when the CSV gets deleted
293+
type: object
294+
required:
295+
- enabled
296+
properties:
297+
enabled:
298+
type: boolean
291299
customresourcedefinitions:
292300
description: "CustomResourceDefinitions declares all of the CRDs managed or required by an operator being ran by ClusterServiceVersion. \n If the CRD is present in the Owned list, it is implicitly required."
293301
type: object
@@ -4671,7 +4679,7 @@ spec:
46714679
webhookPath:
46724680
type: string
46734681
status:
4674-
description: ClusterServiceVersionStatus represents information about the status of a pod. Status may trail the actual state of a system.
4682+
description: ClusterServiceVersionStatus represents information about the status of a CSV. Status may trail the actual state of a system.
46754683
type: object
46764684
properties:
46774685
certsLastUpdated:
@@ -4682,6 +4690,41 @@ spec:
46824690
description: Time the owned APIService certs will rotate next
46834691
type: string
46844692
format: date-time
4693+
cleanup:
4694+
description: CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
4695+
type: object
4696+
properties:
4697+
pendingDeletion:
4698+
description: PendingDeletion is the list of custom resource objects that are pending deletion and blocked on finalizers. This indicates the progress of cleanup that is blocking CSV deletion or operator uninstall.
4699+
type: array
4700+
items:
4701+
description: ResourceList represents a list of resources which are of the same GVK
4702+
type: object
4703+
required:
4704+
- group
4705+
- instances
4706+
- kind
4707+
- version
4708+
properties:
4709+
group:
4710+
type: string
4711+
instances:
4712+
type: array
4713+
items:
4714+
description: NamespacedName represents the name and namespace of a resource
4715+
type: object
4716+
required:
4717+
- name
4718+
properties:
4719+
name:
4720+
type: string
4721+
namespace:
4722+
description: Namespace can be empty for cluster-scoped resources
4723+
type: string
4724+
kind:
4725+
type: string
4726+
version:
4727+
type: string
46854728
conditions:
46864729
description: List of conditions, a history of state transitions
46874730
type: array

crds/zz_defs.go

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

pkg/operators/v1alpha1/clusterserviceversion_types.go

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ type ClusterServiceVersionSpec struct {
303303
// Label selector for related resources.
304304
// +optional
305305
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,2,opt,name=selector"`
306+
307+
// Cleanup specifies the cleanup behaviour when the CSV gets deleted
308+
// +optional
309+
Cleanup CleanupSpec `json:"cleanup,omitempty"`
310+
}
311+
312+
type CleanupSpec struct {
313+
Enabled bool `json:"enabled"`
306314
}
307315

308316
type Maintainer struct {
@@ -467,7 +475,7 @@ type RequirementStatus struct {
467475
Dependents []DependentStatus `json:"dependents,omitempty"`
468476
}
469477

470-
// ClusterServiceVersionStatus represents information about the status of a pod. Status may trail the actual
478+
// ClusterServiceVersionStatus represents information about the status of a CSV. Status may trail the actual
471479
// state of a system.
472480
type ClusterServiceVersionStatus struct {
473481
// Current condition of the ClusterServiceVersion
@@ -495,6 +503,59 @@ type ClusterServiceVersionStatus struct {
495503
// Time the owned APIService certs will rotate next
496504
// +optional
497505
CertsRotateAt *metav1.Time `json:"certsRotateAt,omitempty"`
506+
// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
507+
// +optional
508+
Cleanup CleanupStatus `json:"cleanup,omitempty"`
509+
}
510+
511+
// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
512+
type CleanupStatus struct {
513+
// PendingDeletion is the list of custom resource objects that are pending deletion and blocked on finalizers.
514+
// This indicates the progress of cleanup that is blocking CSV deletion or operator uninstall.
515+
// +optional
516+
PendingDeletion []ResourceList `json:"pendingDeletion,omitempty"`
517+
}
518+
519+
// ResourceList represents a list of resources which are of the same GVK
520+
type ResourceList struct {
521+
Group string `json:"group"`
522+
Version string `json:"version"`
523+
Kind string `json:"kind"`
524+
Instances []NamespacedName `json:"instances"`
525+
}
526+
527+
// NamespacedName represents the name and namespace of a resource
528+
type NamespacedName struct {
529+
Name string `json:"name"`
530+
// Namespace can be empty for cluster-scoped resources
531+
Namespace string `json:"namespace,omitempty"`
532+
}
533+
534+
// HasFinalizer returns true if the CSV has the specified finalizer string
535+
func (c *ClusterServiceVersion) HasFinalizer(finalizer string) bool {
536+
for _, f := range c.Finalizers {
537+
if f == finalizer {
538+
return true
539+
}
540+
}
541+
return false
542+
}
543+
544+
// AppendFinalizer appends the specified finalizer to the CSV
545+
func (c *ClusterServiceVersion) AppendFinalizer(finalizer string) {
546+
c.Finalizers = append(c.Finalizers, finalizer)
547+
}
548+
549+
// RemoveFinalizer removes the specified finalizer from the CSV if it exists
550+
func (c *ClusterServiceVersion) RemoveFinalizer(finalizer string) {
551+
result := []string{}
552+
for _, f := range c.Finalizers {
553+
if f == finalizer {
554+
continue
555+
}
556+
result = append(result, f)
557+
}
558+
c.Finalizers = result
498559
}
499560

500561
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

0 commit comments

Comments
 (0)