Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 40 additions & 1 deletion crds/operators.coreos.com_clusterserviceversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ spec:
type: string
version:
type: string
cleanup:
description: Cleanup specifies the cleanup behaviour when the CSV gets deleted
type: object
required:
- enabled
properties:
enabled:
type: boolean
customresourcedefinitions:
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."
type: object
Expand Down Expand Up @@ -4671,7 +4679,7 @@ spec:
webhookPath:
type: string
status:
description: ClusterServiceVersionStatus represents information about the status of a pod. Status may trail the actual state of a system.
description: ClusterServiceVersionStatus represents information about the status of a CSV. Status may trail the actual state of a system.
type: object
properties:
certsLastUpdated:
Expand All @@ -4682,6 +4690,37 @@ spec:
description: Time the owned APIService certs will rotate next
type: string
format: date-time
cleanup:
description: CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
type: object
properties:
pendingDeletion:
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.
type: array
items:
description: ResourceList represents a list of resources which are of the same Group/Kind
type: object
required:
- group
- instances
- kind
properties:
group:
type: string
instances:
type: array
items:
type: object
required:
- name
properties:
name:
type: string
namespace:
description: Namespace can be empty for cluster-scoped resources
type: string
kind:
type: string
conditions:
description: List of conditions, a history of state transitions
type: array
Expand Down
18 changes: 9 additions & 9 deletions crds/zz_defs.go

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions pkg/operators/v1alpha1/clusterserviceversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

admissionregistrationv1 "k8s.io/api/admissionregistration/v1"

appsv1 "k8s.io/api/apps/v1"
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -303,6 +302,14 @@ type ClusterServiceVersionSpec struct {
// Label selector for related resources.
// +optional
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,2,opt,name=selector"`

// Cleanup specifies the cleanup behaviour when the CSV gets deleted
// +optional
Cleanup CleanupSpec `json:"cleanup,omitempty"`
}

type CleanupSpec struct {
Enabled bool `json:"enabled"`
}

type Maintainer struct {
Expand Down Expand Up @@ -380,6 +387,7 @@ const (
CSVReasonDetectedClusterChange ConditionReason = "DetectedClusterChange"
CSVReasonInvalidWebhookDescription ConditionReason = "InvalidWebhookDescription"
CSVReasonOperatorConditionNotUpgradeable ConditionReason = "OperatorConditionNotUpgradeable"
CSVReasonWaitingForCleanupToComplete ConditionReason = "WaitingOnCleanup"
)

// HasCaResources returns true if the CSV has owned APIServices or Webhooks.
Expand Down Expand Up @@ -467,7 +475,7 @@ type RequirementStatus struct {
Dependents []DependentStatus `json:"dependents,omitempty"`
}

// ClusterServiceVersionStatus represents information about the status of a pod. Status may trail the actual
// ClusterServiceVersionStatus represents information about the status of a CSV. Status may trail the actual
// state of a system.
type ClusterServiceVersionStatus struct {
// Current condition of the ClusterServiceVersion
Expand Down Expand Up @@ -495,6 +503,30 @@ type ClusterServiceVersionStatus struct {
// Time the owned APIService certs will rotate next
// +optional
CertsRotateAt *metav1.Time `json:"certsRotateAt,omitempty"`
// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
// +optional
Cleanup CleanupStatus `json:"cleanup,omitempty"`
}

// CleanupStatus represents information about the status of cleanup while a CSV is pending deletion
type CleanupStatus struct {
// 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.
// +optional
PendingDeletion []ResourceList `json:"pendingDeletion,omitempty"`
}

// ResourceList represents a list of resources which are of the same Group/Kind
type ResourceList struct {
Group string `json:"group"`
Kind string `json:"kind"`
Instances []ResourceInstance `json:"instances"`
}

type ResourceInstance struct {
Name string `json:"name"`
// Namespace can be empty for cluster-scoped resources
Namespace string `json:"namespace,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
39 changes: 1 addition & 38 deletions pkg/validation/internal/typecheck.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package internal

import (
"encoding/json"
"fmt"
"reflect"
"strings"

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

newParentStructName := fieldType.Name
if parentStructName != "" {
Expand Down Expand Up @@ -59,38 +57,3 @@ func updateResult(result *errors.ManifestResult, typeName string, newParentStruc
result.Add(errors.ErrFieldMissing("required field missing", newParentStructName, typeName))
}
}

// Uses reflect package to check if the value of the object passed is null, returns a boolean accordingly.
// TODO: replace with reflect.Kind.IsZero() in go 1.13
func isEmptyValue(v reflect.Value) bool {
switch v.Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
// 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'.
if fieldValue, ok := v.Interface().(json.RawMessage); ok {
valString := string(fieldValue)
if valString == "null" {
return true
}
}
return v.Len() == 0
// 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.
// It is an optional field so the user can ignore the warning saying this field is missing if they intend to use port 0.
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.Interface, reflect.Ptr:
return v.IsNil()
case reflect.Struct:
for i, n := 0, v.NumField(); i < n; i++ {
if !isEmptyValue(v.Field(i)) {
return false
}
}
return true
default:
panic(fmt.Sprintf("%v kind is not supported.", v.Kind()))
}
}