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-6140 | feat: allow customization of the domain prefix when creating a cluster and prints it out in the describe cluster command #605

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 23 additions & 2 deletions cmd/ocm/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const (

var args struct {
// positional args
clusterName string
clusterName string
domainPrefix string

// flags
interactive bool
Expand Down Expand Up @@ -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)"

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 5 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func NewDefaultIngressSpec() DefaultIngressSpec {
type Spec struct {
// Basic configs
Name string
DomainPrefix string
Region string
Provider string
CCS CCS
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions pkg/cluster/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading