Skip to content

Commit

Permalink
Merge pull request #556 from tirthct/ocm-3768
Browse files Browse the repository at this point in the history
OCM 3768 | Feat | Filtered OCM versions for marketplace gcp clusters
  • Loading branch information
gdbranco authored Sep 28, 2023
2 parents d0de10d + 0aca318 commit 5d97615
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
14 changes: 10 additions & 4 deletions cmd/ocm/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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, "", "")
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
}
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/ocm/list/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
var args struct {
defaultVersion bool
channelGroup string
marketplaceGcp string
}

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -55,6 +56,13 @@ func init() {
"stable",
"List only versions from the specified channel group",
)

fs.StringVar(
&args.marketplaceGcp,
"marketplace-gcp",
"",
"List only versions that support 'marketplace-gcp' subscription type",
)
}

func run(cmd *cobra.Command, argv []string) error {
Expand All @@ -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.marketplaceGcp)
if err != nil {
return fmt.Errorf("Can't retrieve versions: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
filter = fmt.Sprintf("%s AND gcp_marketplace_enabled = '%s'", filter, gcpMarketplaceEnabled)
}
if channelGroup != "" {
filter = fmt.Sprintf("%s AND channel_group = '%s'", filter, channelGroup)
}
Expand Down

0 comments on commit 5d97615

Please sign in to comment.