Skip to content

Commit

Permalink
OCM-6407 | edit option sends an empty payload
Browse files Browse the repository at this point in the history
This commit adds a variable to check if one of the arguments that need
to update the cluster is used, to not send an almost empty payload.

Signed-off-by: Alba Hita Catala <[email protected]>
  • Loading branch information
ahitacat committed Feb 28, 2024
1 parent 1095264 commit e336e15
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/ocm/edit/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var Cmd = &cobra.Command{
Example: ` # Edit a cluster named "mycluster" to make it private
ocm edit cluster mycluster --private`,
RunE: run,
Args: cobra.MinimumNArgs(2),
}

func init() {
Expand Down Expand Up @@ -132,8 +133,9 @@ func wasClusterWideProxyReceived(httpProxy, httpsProxy, noProxy, additionalTrust
}

func run(cmd *cobra.Command, argv []string) error {
// Check that there is exactly one cluster name, identifir or external identifier in the
// Check that there is exactly one cluster name, identifier or external identifier in the
// command line arguments:
var clusterNeedsUpdate bool
if len(argv) != 1 {
return fmt.Errorf(
"Expected exactly one cluster name, identifier or external identifier " +
Expand Down Expand Up @@ -176,11 +178,13 @@ func run(cmd *cobra.Command, argv []string) error {
var private *bool
if cmd.Flags().Changed("private") {
private = &args.private
clusterNeedsUpdate = true
}

var channelGroup string
if cmd.Flags().Changed("channel-group") {
channelGroup = args.channelGroup
clusterNeedsUpdate = true
}

var httpProxy *string
Expand All @@ -192,6 +196,7 @@ func run(cmd *cobra.Command, argv []string) error {
}
}
httpProxy = args.clusterWideProxy.HTTPProxy
clusterNeedsUpdate = true
}

var httpsProxy *string
Expand All @@ -203,6 +208,7 @@ func run(cmd *cobra.Command, argv []string) error {
}
}
httpsProxy = args.clusterWideProxy.HTTPSProxy
clusterNeedsUpdate = true
}

var noProxy *string
Expand All @@ -220,6 +226,7 @@ func run(cmd *cobra.Command, argv []string) error {
}
}
noProxy = args.clusterWideProxy.NoProxy
clusterNeedsUpdate = true
}

var additionalTrustBundleFile *string
Expand All @@ -233,6 +240,7 @@ func run(cmd *cobra.Command, argv []string) error {
}
}
additionalTrustBundleFile = &additionalTrustBundleFileValue
clusterNeedsUpdate = true
}

if len(cluster.AWS().SubnetIDs()) == 0 && isGCPNetworkEmpty(cluster.GCPNetwork()) &&
Expand Down Expand Up @@ -268,9 +276,11 @@ func run(cmd *cobra.Command, argv []string) error {
}
clusterConfig.ClusterWideProxy = clusterWideProxy

err = c.UpdateCluster(clusterCollection, cluster.ID(), clusterConfig)
if err != nil {
return fmt.Errorf("Failed to update cluster: %v", err)
if clusterNeedsUpdate {
err = c.UpdateCluster(clusterCollection, cluster.ID(), clusterConfig)
if err != nil {
return fmt.Errorf("Failed to update cluster: %v", err)
}
}

return nil
Expand Down

0 comments on commit e336e15

Please sign in to comment.