Skip to content

Commit

Permalink
OCM-5941 | add enable delete protection parameter
Browse files Browse the repository at this point in the history
Added --enable-delete-protection argument to the edit option.

Signed-off-by: Alba Hita Catala <[email protected]>
  • Loading branch information
ahitacat committed Mar 4, 2024
1 parent 1095264 commit 1caf2d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 18 additions & 3 deletions cmd/ocm/edit/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

var args struct {
// Basic options
expirationTime string
expirationDuration time.Duration

expirationTime string
expirationDuration time.Duration
enableDeleteProtection bool
// Networking options
private bool

Expand Down Expand Up @@ -119,6 +119,12 @@ func init() {
"A file contains a PEM-encoded X.509 certificate bundle that will be "+
"added to the nodes' trusted certificate store.")

flags.BoolVar(
&args.enableDeleteProtection,
"enable-delete-protection",
false,
"Enable cluster delete protection against accidental cluster deletion.",
)
}

func isGCPNetworkEmpty(network *cmv1.GCPNetwork) bool {
Expand Down Expand Up @@ -222,6 +228,15 @@ func run(cmd *cobra.Command, argv []string) error {
noProxy = args.clusterWideProxy.NoProxy
}

var enableDeleteProtection bool
if cmd.Flags().Changed("enable-delete-protection") {
enableDeleteProtection = args.enableDeleteProtection
err := c.UpdateDeleteProtection(clusterCollection, cluster.ID(), enableDeleteProtection)
if err != nil {
return err
}
}

var additionalTrustBundleFile *string
var additionalTrustBundleFileValue string
if cmd.Flags().Changed("additional-trust-bundle-file") {
Expand Down
10 changes: 9 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ func UpdateCluster(client *cmv1.ClustersClient, clusterID string, config Spec) e
if err != nil {
return err
}

_, err = client.Cluster(clusterID).Update().Body(clusterSpec).Send()
if err != nil {
return err
Expand All @@ -589,6 +588,15 @@ func UpdateCluster(client *cmv1.ClustersClient, clusterID string, config Spec) e
return nil
}

func UpdateDeleteProtection(client *cmv1.ClustersClient, clusterID string, enable bool) error {
deleteProtection, _ := cmv1.NewDeleteProtection().Enabled(enable).Build()
_, err := client.Cluster(clusterID).DeleteProtection().Update().Body(deleteProtection).Send()
if err != nil {
return err
}
return nil
}

func buildCompute(config Spec, clusterNodesBuilder *cmv1.ClusterNodesBuilder) *cmv1.ClusterNodesBuilder {
if config.Autoscaling.Enabled {
autoscalingBuilder := cmv1.NewMachinePoolAutoscaling()
Expand Down

0 comments on commit 1caf2d0

Please sign in to comment.