Skip to content

Commit

Permalink
Add DeletePolicy to IBMPowerVSImage Spec
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab committed Feb 18, 2022
1 parent 14fcd03 commit 84fa466
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
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

0 comments on commit 84fa466

Please sign in to comment.