Skip to content

Commit f572176

Browse files
authored
Merge pull request #100 from hasbro17/add-csv-cleanup-api
Add API for cleanup spec and status
2 parents 4fbc8b5 + c95efc7 commit f572176

File tree

4 files changed

+84
-50
lines changed

4 files changed

+84
-50
lines changed

crds/operators.coreos.com_clusterserviceversions.yaml

Lines changed: 40 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,37 @@ 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 Group/Kind
4702+
type: object
4703+
required:
4704+
- group
4705+
- instances
4706+
- kind
4707+
properties:
4708+
group:
4709+
type: string
4710+
instances:
4711+
type: array
4712+
items:
4713+
type: object
4714+
required:
4715+
- name
4716+
properties:
4717+
name:
4718+
type: string
4719+
namespace:
4720+
description: Namespace can be empty for cluster-scoped resources
4721+
type: string
4722+
kind:
4723+
type: string
46854724
conditions:
46864725
description: List of conditions, a history of state transitions
46874726
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: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88

99
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
10-
1110
appsv1 "k8s.io/api/apps/v1"
1211
rbac "k8s.io/api/rbac/v1"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -304,6 +303,14 @@ type ClusterServiceVersionSpec struct {
304303
// Label selector for related resources.
305304
// +optional
306305
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"`
307314
}
308315

309316
type Maintainer struct {
@@ -381,6 +388,7 @@ const (
381388
CSVReasonDetectedClusterChange ConditionReason = "DetectedClusterChange"
382389
CSVReasonInvalidWebhookDescription ConditionReason = "InvalidWebhookDescription"
383390
CSVReasonOperatorConditionNotUpgradeable ConditionReason = "OperatorConditionNotUpgradeable"
391+
CSVReasonWaitingForCleanupToComplete ConditionReason = "WaitingOnCleanup"
384392
)
385393

386394
// HasCaResources returns true if the CSV has owned APIServices or Webhooks.
@@ -468,7 +476,7 @@ type RequirementStatus struct {
468476
Dependents []DependentStatus `json:"dependents,omitempty"`
469477
}
470478

471-
// ClusterServiceVersionStatus represents information about the status of a pod. Status may trail the actual
479+
// ClusterServiceVersionStatus represents information about the status of a CSV. Status may trail the actual
472480
// state of a system.
473481
type ClusterServiceVersionStatus struct {
474482
// Current condition of the ClusterServiceVersion
@@ -496,6 +504,30 @@ type ClusterServiceVersionStatus struct {
496504
// Time the owned APIService certs will rotate next
497505
// +optional
498506
CertsRotateAt *metav1.Time `json:"certsRotateAt,omitempty"`
507+
// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
508+
// +optional
509+
Cleanup CleanupStatus `json:"cleanup,omitempty"`
510+
}
511+
512+
// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
513+
type CleanupStatus struct {
514+
// PendingDeletion is the list of custom resource objects that are pending deletion and blocked on finalizers.
515+
// This indicates the progress of cleanup that is blocking CSV deletion or operator uninstall.
516+
// +optional
517+
PendingDeletion []ResourceList `json:"pendingDeletion,omitempty"`
518+
}
519+
520+
// ResourceList represents a list of resources which are of the same Group/Kind
521+
type ResourceList struct {
522+
Group string `json:"group"`
523+
Kind string `json:"kind"`
524+
Instances []ResourceInstance `json:"instances"`
525+
}
526+
527+
type ResourceInstance struct {
528+
Name string `json:"name"`
529+
// Namespace can be empty for cluster-scoped resources
530+
Namespace string `json:"namespace,omitempty"`
499531
}
500532

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

pkg/validation/internal/typecheck.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package internal
22

33
import (
4-
"encoding/json"
5-
"fmt"
64
"reflect"
75
"strings"
86

@@ -31,7 +29,7 @@ func checkEmptyFields(result *errors.ManifestResult, v reflect.Value, parentStru
3129
// Omitted field tags will contain ",omitempty", and ignored tags will
3230
// match "-" exactly, respectively.
3331
isOptionalField := strings.Contains(tag, ",omitempty") || tag == "-"
34-
emptyVal := isEmptyValue(fieldValue)
32+
emptyVal := fieldValue.IsZero()
3533

3634
newParentStructName := fieldType.Name
3735
if parentStructName != "" {
@@ -59,38 +57,3 @@ func updateResult(result *errors.ManifestResult, typeName string, newParentStruc
5957
result.Add(errors.ErrFieldMissing("required field missing", newParentStructName, typeName))
6058
}
6159
}
62-
63-
// Uses reflect package to check if the value of the object passed is null, returns a boolean accordingly.
64-
// TODO: replace with reflect.Kind.IsZero() in go 1.13
65-
func isEmptyValue(v reflect.Value) bool {
66-
switch v.Kind() {
67-
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
68-
// Check if the value for 'Spec.InstallStrategy.StrategySpecRaw' field is present. This field is a RawMessage value type. Without a value, the key is explicitly set to 'null'.
69-
if fieldValue, ok := v.Interface().(json.RawMessage); ok {
70-
valString := string(fieldValue)
71-
if valString == "null" {
72-
return true
73-
}
74-
}
75-
return v.Len() == 0
76-
// Currently the only CSV field with integer type is containerPort. Operator Verification Library raises a warning if containerPort field is missisng or if its value is 0.
77-
// It is an optional field so the user can ignore the warning saying this field is missing if they intend to use port 0.
78-
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
79-
return v.Int() == 0
80-
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
81-
return v.Uint() == 0
82-
case reflect.Float32, reflect.Float64:
83-
return v.Float() == 0
84-
case reflect.Interface, reflect.Ptr:
85-
return v.IsNil()
86-
case reflect.Struct:
87-
for i, n := 0, v.NumField(); i < n; i++ {
88-
if !isEmptyValue(v.Field(i)) {
89-
return false
90-
}
91-
}
92-
return true
93-
default:
94-
panic(fmt.Sprintf("%v kind is not supported.", v.Kind()))
95-
}
96-
}

0 commit comments

Comments
 (0)