Skip to content

Commit

Permalink
Merge pull request #4210 from muraee/fix-cli
Browse files Browse the repository at this point in the history
HOSTEDCP-1542: Fixed infra-id not being defaulted first
  • Loading branch information
openshift-merge-bot[bot] authored Jun 14, 2024
2 parents 2b6f01a + 48180fb commit 049c72e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
3 changes: 0 additions & 3 deletions cmd/cluster/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command {
}

func CreateCluster(ctx context.Context, opts *core.CreateOptions, awsOpts *CreateOptions) error {
if err := core.Validate(ctx, opts); err != nil {
return err
}
return core.CreateCluster(ctx, opts, awsOpts)
}

Expand Down
12 changes: 4 additions & 8 deletions cmd/cluster/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,16 @@ func (o *CreateOptions) ApplyPlatformSpecifics(cluster *hyperv1.HostedCluster) e
PublicZoneID: o.infra.PublicZoneID,
PrivateZoneID: o.infra.PrivateZoneID,
}
cluster.Spec.ClusterID = o.infra.InfraID

cluster.Spec.Platform = hyperv1.PlatformSpec{
Type: hyperv1.AzurePlatform,
Azure: &hyperv1.AzurePlatformSpec{
Credentials: corev1.LocalObjectReference{Name: credentialSecret(cluster.Namespace, cluster.Name).Name},
Location: o.Location,
ResourceGroupName: o.ResourceGroupName,
VnetID: o.VnetID,
SubnetID: o.SubnetID,
SubscriptionID: o.creds.SubscriptionID,
Location: o.infra.Location,
ResourceGroupName: o.infra.ResourceGroupName,
VnetID: o.infra.VNetID,
SubnetID: o.infra.SubnetID,
MachineIdentityID: o.infra.MachineIdentityID,
SecurityGroupID: o.infra.SecurityGroupID,
},
Expand Down Expand Up @@ -303,9 +302,6 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command {
}

func CreateCluster(ctx context.Context, opts *core.CreateOptions, azureOpts *CreateOptions) error {
if err := core.Validate(ctx, opts); err != nil {
return err
}
return core.CreateCluster(ctx, opts, azureOpts)
}

Expand Down
34 changes: 21 additions & 13 deletions cmd/cluster/core/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ func prototypeResources(opts *CreateOptions) (*resources, error) {
}
}

if len(opts.InfraID) == 0 {
opts.InfraID = infraid.New(opts.Name)
}

prototype.Namespace = &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
Expand Down Expand Up @@ -531,6 +527,17 @@ func GetAPIServerAddressByNode(ctx context.Context, l logr.Logger) (string, erro
}

func Validate(ctx context.Context, opts *CreateOptions) error {
if opts.Wait && opts.NodePoolReplicas < 1 {
return errors.New("--wait requires --node-pool-replicas > 0")
}

// Validate HostedCluster name follows RFC1123 standard
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
errs := validation.IsDNS1123Label(opts.Name)
if len(errs) > 0 {
return fmt.Errorf("HostedCluster name failed RFC1123 validation: %s", strings.Join(errs[:], " "))
}

if !opts.Render && opts.RenderInto != "" {
client, err := util.GetClient()
if err != nil {
Expand All @@ -545,13 +552,6 @@ func Validate(ctx context.Context, opts *CreateOptions) error {
}
}

// Validate HostedCluster name follows RFC1123 standard
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
errs := validation.IsDNS1123Label(opts.Name)
if len(errs) > 0 {
return fmt.Errorf("HostedCluster name failed RFC1123 validation: %s", strings.Join(errs[:], " "))
}

// Validate arch is only hyperv1.ArchitectureAMD64 or hyperv1.ArchitectureARM64 or hyperv1.ArchitecturePPC64LE
arch := strings.ToLower(opts.Arch)
switch arch {
Expand Down Expand Up @@ -587,8 +587,16 @@ type Platform interface {
}

func CreateCluster(ctx context.Context, opts *CreateOptions, platform Platform) error {
if opts.Wait && opts.NodePoolReplicas < 1 {
return errors.New("--wait requires --node-pool-replicas > 0")
if len(opts.InfraID) == 0 {
opts.InfraID = infraid.New(opts.Name)
}

if err := Validate(ctx, opts); err != nil {
return err
}

if err := platform.Validate(ctx, opts); err != nil {
return err
}

if err := platform.Complete(ctx, opts); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions cmd/cluster/none/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command {
}

func CreateCluster(ctx context.Context, opts *core.CreateOptions, noneOpts *CreateOptions) error {
if err := core.Validate(ctx, opts); err != nil {
return err
}
return core.CreateCluster(ctx, opts, noneOpts)
}
4 changes: 0 additions & 4 deletions cmd/cluster/powervs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command {
}

func CreateCluster(ctx context.Context, opts *core.CreateOptions, powerVsOpts *CreateOptions) error {
var err error
if err = core.Validate(ctx, opts); err != nil {
return err
}
return core.CreateCluster(ctx, opts, powerVsOpts)
}

Expand Down

0 comments on commit 049c72e

Please sign in to comment.