Skip to content

Commit

Permalink
Merge pull request #102 from vkareh/versions-stable-channel-group
Browse files Browse the repository at this point in the history
versions: Allow querying for channel-groups
  • Loading branch information
vkareh authored Sep 14, 2020
2 parents f161c9e + 44397f1 commit b33283d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func validateVersion(version string, versionList []string) (string, error) {
}

func getVersionList(client *cmv1.Client) (versionList []string, err error) {
versions, err := versions.GetVersions(client)
versions, err := versions.GetVersions(client, "stable")
if err != nil {
err = fmt.Errorf("Failed to retrieve versions: %s", err)
return
Expand Down
17 changes: 6 additions & 11 deletions cmd/list/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var args struct {
channel string
channelGroup string
}

var Cmd = &cobra.Command{
Expand All @@ -46,12 +46,12 @@ var Cmd = &cobra.Command{
func init() {
flags := Cmd.Flags()
flags.StringVar(
&args.channel,
"channel",
"",
&args.channelGroup,
"channel-group",
"stable",
"List only versions from the specified channel group",
)
flags.MarkHidden("channel")
flags.MarkHidden("channel-group")
}

func run(cmd *cobra.Command, _ []string) {
Expand All @@ -78,7 +78,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Fetching versions")
versions, err := versions.GetVersions(ocmClient)
versions, err := versions.GetVersions(ocmClient, args.channelGroup)
if err != nil {
reporter.Errorf("Failed to fetch versions: %v", err)
os.Exit(1)
Expand All @@ -97,11 +97,6 @@ func run(cmd *cobra.Command, _ []string) {
if !version.Enabled() {
continue
}
if cmd.Flags().Changed("channel") {
if args.channel != version.ChannelGroup() {
continue
}
}
fmt.Fprintf(writer,
"%s\t\t%t\n",
version.ID(),
Expand Down
10 changes: 8 additions & 2 deletions pkg/ocm/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@ limitations under the License.
package versions

import (
"fmt"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
)

func GetVersions(client *cmv1.Client) (versions []*cmv1.Version, err error) {
func GetVersions(client *cmv1.Client, channelGroup string) (versions []*cmv1.Version, err error) {
collection := client.Versions()
page := 1
size := 100
filter := "enabled = 'true'"
if channelGroup != "" {
filter = fmt.Sprintf("%s AND channel_group = '%s'", filter, channelGroup)
}
for {
var response *cmv1.VersionsListResponse
response, err = collection.List().
Search("enabled = 'true'").
Search(filter).
Order("default desc, id asc").
Page(page).
Size(size).
Expand Down

0 comments on commit b33283d

Please sign in to comment.