Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM 3768 | Feat | Filtered OCM versions for marketplace gcp clusters #556

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
gcpMarketplace 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.gcpMarketplace,
"gcp-marketplace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be marketplace-gcp instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

"",
"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.gcpMarketplace)
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
Loading