From 498c54eb1ab4e12767d2b7beeda146c457c6f084 Mon Sep 17 00:00:00 2001 From: tithakka Date: Wed, 27 Sep 2023 16:47:34 -0400 Subject: [PATCH] Filtered OCM versions for marketplace gcp clusters --- cmd/ocm/create/cluster/cmd.go | 14 ++++++++++---- cmd/ocm/list/version/cmd.go | 10 +++++++++- pkg/cluster/versions.go | 5 ++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/ocm/create/cluster/cmd.go b/cmd/ocm/create/cluster/cmd.go index 5250278d..8da6ef6c 100644 --- a/cmd/ocm/create/cluster/cmd.go +++ b/cmd/ocm/create/cluster/cmd.go @@ -22,6 +22,7 @@ import ( "io" "net" "os" + "strconv" "strings" "time" @@ -400,16 +401,16 @@ func GetDefaultClusterFlavors(connection *sdk.Connection, flavour string) (dMach } func getVersionOptions(connection *sdk.Connection) ([]arguments.Option, error) { - options, _, err := getVersionOptionsWithDefault(connection, "") + options, _, err := getVersionOptionsWithDefault(connection, "", nil) return options, err } -func getVersionOptionsWithDefault(connection *sdk.Connection, channelGroup string) ( +func getVersionOptionsWithDefault(connection *sdk.Connection, channelGroup string, gcpMarketplaceEnabled *string) ( options []arguments.Option, defaultVersion string, err error, ) { // Check and set the cluster version versionList, defaultVersion, err := c.GetEnabledVersions( - connection.ClustersMgmt().V1(), channelGroup) + connection.ClustersMgmt().V1(), channelGroup, gcpMarketplaceEnabled) if err != nil { return } @@ -551,7 +552,12 @@ func preRun(cmd *cobra.Command, argv []string) error { return err } - versions, defaultVersion, err := getVersionOptionsWithDefault(connection, args.channelGroup) + var gcpMarketplaceEnabled string + if isGcpMarketplaceSubscriptionType { + gcpMarketplaceEnabled = strconv.FormatBool(isGcpMarketplaceSubscriptionType) + } + versions, defaultVersion, err := getVersionOptionsWithDefault(connection, args.channelGroup, + &gcpMarketplaceEnabled) if err != nil { return err } diff --git a/cmd/ocm/list/version/cmd.go b/cmd/ocm/list/version/cmd.go index dcdce401..a4cb56c6 100644 --- a/cmd/ocm/list/version/cmd.go +++ b/cmd/ocm/list/version/cmd.go @@ -27,6 +27,7 @@ import ( var args struct { defaultVersion bool channelGroup string + gcpMarketplace string } var Cmd = &cobra.Command{ @@ -55,6 +56,13 @@ func init() { "stable", "List only versions from the specified channel group", ) + + fs.StringVar( + &args.gcpMarketplace, + "gcp-marketplace", + "", + "List only versions that support 'marketplace-gcp' subscription type", + ) } func run(cmd *cobra.Command, argv []string) error { @@ -66,7 +74,7 @@ func run(cmd *cobra.Command, argv []string) error { defer connection.Close() client := connection.ClustersMgmt().V1() - versions, defaultVersion, err := cluster.GetEnabledVersions(client, args.channelGroup) + versions, defaultVersion, err := cluster.GetEnabledVersions(client, args.channelGroup, &args.gcpMarketplace) if err != nil { return fmt.Errorf("Can't retrieve versions: %v", err) } diff --git a/pkg/cluster/versions.go b/pkg/cluster/versions.go index 6b56330b..d42e0484 100644 --- a/pkg/cluster/versions.go +++ b/pkg/cluster/versions.go @@ -42,12 +42,15 @@ func EnsureOpenshiftVPrefix(v string) string { // GetEnabledVersions returns the versions with enabled=true, and the one that has default=true. // The returned strings are the IDs without "openshift-v" prefix (e.g. "4.6.0-rc.4-candidate") // sorted in approximate SemVer order (handling of text parts is somewhat arbitrary). -func GetEnabledVersions(client *cmv1.Client, channelGroup string) ( +func GetEnabledVersions(client *cmv1.Client, channelGroup string, gcpMarketplaceEnabled *string) ( versions []string, defaultVersion string, err error) { collection := client.Versions() page := 1 size := 100 filter := "enabled = 'true'" + if gcpMarketplaceEnabled != nil && *gcpMarketplaceEnabled != "" { + filter = fmt.Sprintf("%s AND gcp_marketplace_enabled = '%s'", filter, *gcpMarketplaceEnabled) + } if channelGroup != "" { filter = fmt.Sprintf("%s AND channel_group = '%s'", filter, channelGroup) }