diff --git a/cmd/ocm/create/cluster/cmd.go b/cmd/ocm/create/cluster/cmd.go index 1633b64e..0ac972a5 100644 --- a/cmd/ocm/create/cluster/cmd.go +++ b/cmd/ocm/create/cluster/cmd.go @@ -56,7 +56,8 @@ const ( var args struct { // positional args - clusterName string + clusterName string + domainPrefix string // flags interactive bool @@ -99,7 +100,8 @@ var args struct { defaultIngressNamespaceOwnershipPolicy string } -const clusterNameHelp = "will be used when generating a sub-domain for your cluster on openshiftapps.com." +const clusterNameHelp = "The name can be used as the identifier of the cluster." + + " The maximum length is 54 characters. Once set, the cluster name cannot be changed" const subnetTemplate = "%s (%s)" @@ -174,6 +176,19 @@ func init() { arguments.SetQuestion(fs, "version", "OpenShift version:") Cmd.RegisterFlagCompletionFunc("version", arguments.MakeCompleteFunc(getVersionOptions)) + fs.StringVar( + &args.domainPrefix, + "domain-prefix", + "", + "An optional unique domain prefix of the cluster. If not provided, the cluster name will be "+ + "used if it contains at most 15 characters, otherwise a generated value will be used. This "+ + "will be used when generating a sub-domain for your cluster. It must be unique and consist "+ + "of lowercase alphanumeric,characters or '-', start with an alphabetic character, and end with "+ + "an alphanumeric character. The maximum length is 15 characters. Once set, the cluster domain "+ + "prefix cannot be changed", + ) + arguments.SetQuestion(fs, "domain-prefix", "Domain Prefix:") + fs.StringVar( &args.channelGroup, "channel-group", @@ -680,6 +695,11 @@ func preRun(cmd *cobra.Command, argv []string) error { return err } + err = arguments.PromptString(fs, "domain-prefix") + if err != nil { + return err + } + return nil } @@ -710,6 +730,7 @@ func run(cmd *cobra.Command, argv []string) error { clusterConfig := c.Spec{ Name: args.clusterName, + DomainPrefix: args.domainPrefix, Region: args.region, Provider: args.provider, CCS: args.ccs, diff --git a/go.mod b/go.mod index 9e0b67b7..c031029f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/nwidger/jsoncolor v0.3.2 github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.8 - github.com/openshift-online/ocm-sdk-go v0.1.398 + github.com/openshift-online/ocm-sdk-go v0.1.405 github.com/openshift/rosa v1.2.24 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index 7fdfe2e4..e05fecb6 100644 --- a/go.sum +++ b/go.sum @@ -312,8 +312,8 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ= -github.com/openshift-online/ocm-sdk-go v0.1.398 h1:6C1mDcPxzG4jSduOaWixTTI5gSEO+Jm7OW/00jVoWGI= -github.com/openshift-online/ocm-sdk-go v0.1.398/go.mod h1:tke8vKcE7eHKyRbkJv6qo4ljo919zhx04uyQTcgF5cQ= +github.com/openshift-online/ocm-sdk-go v0.1.405 h1:ozU85KTekcp6Qhsu7zwicjB03k1W0uslRbrkF1ctLSg= +github.com/openshift-online/ocm-sdk-go v0.1.405/go.mod h1:zeh3RU78O6HVpiUhwXRNcF3FmiaSP4SeqoQAzow0vZE= github.com/openshift/rosa v1.2.24 h1:vv0yYnWHx6CCPEAau/0rS54P2ksaf+uWXb1TQPWxiYE= github.com/openshift/rosa v1.2.24/go.mod h1:MVXB27O3PF8WoOic23I03mmq6/9kVxpFx6FKyLMCyrQ= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 1b03f3d8..7b6fb71c 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -57,6 +57,7 @@ func NewDefaultIngressSpec() DefaultIngressSpec { type Spec struct { // Basic configs Name string + DomainPrefix string Region string Provider string CCS CCS @@ -327,6 +328,10 @@ func CreateCluster(cmv1Client *cmv1.Client, config Spec, dryRun bool) (*cmv1.Clu BillingModel(cmv1.BillingModel(config.SubscriptionType)). Properties(clusterProperties) + if config.DomainPrefix != "" { + clusterBuilder = clusterBuilder.DomainPrefix(config.DomainPrefix) + } + clusterBuilder = clusterBuilder.Version( cmv1.NewVersion(). ID(config.Version).ChannelGroup(config.ChannelGroup)) diff --git a/pkg/cluster/describe.go b/pkg/cluster/describe.go index d03005fc..d91ba09a 100644 --- a/pkg/cluster/describe.go +++ b/pkg/cluster/describe.go @@ -166,11 +166,13 @@ func PrintClusterDescription(connection *sdk.Connection, cluster *cmv1.Cluster) "ID: %s\n"+ "External ID: %s\n"+ "Name: %s\n"+ + "Domain Prefix: %s\n"+ "Display Name: %s\n"+ "State: %s %s\n", cluster.ID(), cluster.ExternalID(), cluster.Name(), + cluster.DomainPrefix(), sub.DisplayName(), cluster.State(), provisioningStatus,