From c9f044fbe331efc27fb6647a3fc3ff58d0303fa9 Mon Sep 17 00:00:00 2001 From: Mulham Raee Date: Thu, 13 Jun 2024 14:11:05 +0200 Subject: [PATCH 1/3] fixed infra-id not being defaulted first - fixed platfrom specifc validation not being executed --- cmd/cluster/aws/create.go | 3 --- cmd/cluster/azure/create.go | 3 --- cmd/cluster/core/create.go | 34 +++++++++++++++++++++------------- cmd/cluster/none/create.go | 3 --- cmd/cluster/powervs/create.go | 4 ---- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/cmd/cluster/aws/create.go b/cmd/cluster/aws/create.go index a143c5e1ce..80e770b240 100644 --- a/cmd/cluster/aws/create.go +++ b/cmd/cluster/aws/create.go @@ -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) } diff --git a/cmd/cluster/azure/create.go b/cmd/cluster/azure/create.go index faf4ad48d1..b0d9ab162e 100644 --- a/cmd/cluster/azure/create.go +++ b/cmd/cluster/azure/create.go @@ -303,9 +303,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) } diff --git a/cmd/cluster/core/create.go b/cmd/cluster/core/create.go index a840368093..28407be252 100644 --- a/cmd/cluster/core/create.go +++ b/cmd/cluster/core/create.go @@ -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", @@ -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 { @@ -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 { @@ -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 { diff --git a/cmd/cluster/none/create.go b/cmd/cluster/none/create.go index 16be8ff88b..81c1283805 100644 --- a/cmd/cluster/none/create.go +++ b/cmd/cluster/none/create.go @@ -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) } diff --git a/cmd/cluster/powervs/create.go b/cmd/cluster/powervs/create.go index b101efd227..8cdd0487c9 100644 --- a/cmd/cluster/powervs/create.go +++ b/cmd/cluster/powervs/create.go @@ -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) } From ebcd7206e87125819164ae1f2f502d1b29a10e56 Mon Sep 17 00:00:00 2001 From: Mulham Raee Date: Thu, 13 Jun 2024 15:12:12 +0200 Subject: [PATCH 2/3] don't set HostedCluster.Spec.ClusterID for azure create --- cmd/cluster/azure/create.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/cluster/azure/create.go b/cmd/cluster/azure/create.go index b0d9ab162e..eb2d94fd53 100644 --- a/cmd/cluster/azure/create.go +++ b/cmd/cluster/azure/create.go @@ -147,7 +147,6 @@ 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, From 48180fb2b16214c72de607f1e6b828e949f77a9d Mon Sep 17 00:00:00 2001 From: Mulham Raee Date: Thu, 13 Jun 2024 15:47:53 +0200 Subject: [PATCH 3/3] fixed azure CLI not passing the correct platfrom spec infra - ResourceGroupName, VNetID and SubnetID --- cmd/cluster/azure/create.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/cluster/azure/create.go b/cmd/cluster/azure/create.go index eb2d94fd53..8eb4b9542e 100644 --- a/cmd/cluster/azure/create.go +++ b/cmd/cluster/azure/create.go @@ -152,11 +152,11 @@ func (o *CreateOptions) ApplyPlatformSpecifics(cluster *hyperv1.HostedCluster) e 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, },