Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DeletePolicy to IBMPowerVSImage Spec #566

Merged
merged 1 commit into from
Feb 18, 2022
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
6 changes: 6 additions & 0 deletions api/v1beta1/ibmpowervsimage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type IBMPowerVSImageSpec struct {
// +kubebuilder:validation:Enum=tier1;tier3
// +optional
StorageType string `json:"storageType,omitempty"`

// DeletePolicy defines the policy used to identify images to be preserved beyond the lifecycle of associated cluster.
// +kubebuilder:default=delete
// +kubebuilder:validation:Enum=delete;retain
// +optional
DeletePolicy string `json:"deletePolicy,omitempty"`
}

// IBMPowerVSImageStatus defines the observed state of IBMPowerVSImage
Expand Down
8 changes: 8 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ var (
PowerVSImageStateImporting = PowerVSImageState("importing")
)

// DeletePolicy defines the policy used to identify images to be preserved.
type DeletePolicy string

var (
// DeletePolicyRetain is the string representing an image to be retained.
DeletePolicyRetain = DeletePolicy("retain")
)

// NetworkInterface holds the network interface information like subnet id.
type NetworkInterface struct {
// Subnet ID of the network interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ spec:
to.
minLength: 1
type: string
deletePolicy:
default: delete
description: DeletePolicy defines the policy used to identify images
to be preserved beyond the lifecycle of associated cluster.
enum:
- delete
- retain
type: string
object:
description: Cloud Object Storage image filename
type: string
Expand Down
10 changes: 6 additions & 4 deletions controllers/ibmpowervsimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ func (r *IBMPowerVSImageReconciler) reconcileDelete(scope *scope.PowerVSImageSco
}
return ctrl.Result{}, nil
}
if err := scope.DeleteImage(); err != nil {
scope.Info("error deleting IBMPowerVSImage")
return ctrl.Result{}, errors.Wrapf(err, "error deleting IBMPowerVSImage %s/%s", scope.IBMPowerVSImage.Namespace, scope.IBMPowerVSImage.Name)
}

if scope.IBMPowerVSImage.Spec.DeletePolicy != string(v1beta1.DeletePolicyRetain) {
if err := scope.DeleteImage(); err != nil {
scope.Info("error deleting IBMPowerVSImage")
return ctrl.Result{}, errors.Wrapf(err, "error deleting IBMPowerVSImage %s/%s", scope.IBMPowerVSImage.Namespace, scope.IBMPowerVSImage.Name)
}
}
return ctrl.Result{}, nil
}

Expand Down