Skip to content

Commit

Permalink
vsphere: k8s version defaulting was not ok
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
(cherry picked from commit b6735d0)
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
  • Loading branch information
jkremser committed Oct 25, 2023
1 parent b3d4808 commit a56020c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions cmd/template/cluster/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ func (f *flag) Init(cmd *cobra.Command) {
_ = cmd.Flags().MarkHidden(flagGCPMachineDeploymentReplicas)
_ = cmd.Flags().MarkHidden(flagGCPMachineDeploymentInstanceType)

_ = cmd.Flags().MarkHidden(flagVSphereImageTemplate)

_ = cmd.Flags().MarkHidden(flagClusterCatalog)
_ = cmd.Flags().MarkHidden(flagClusterVersion)
_ = cmd.Flags().MarkHidden(flagDefaultAppsCatalog)
Expand Down Expand Up @@ -434,10 +436,17 @@ func (f *flag) Validate(cmd *cobra.Command) error {
if !validateCIDR(f.VSphere.ServiceLoadBalancerCIDR) {
return microerror.Maskf(invalidFlagError, "--%s must be a valid CIDR", flagVSphereServiceLoadBalancerCIDR)
}
ver, err := cmd.Flags().GetString(flagKubernetesVersion)
if err != nil || ver == "" {
if !cmd.Flags().Changed(flagKubernetesVersion) {
f.KubernetesVersion = defaultVSphereKubernetesVersion
}
// todo: add validation for flagVSphereImageTemplate
placeholders := strings.Count(f.VSphere.ImageTemplate, "%s")
if placeholders > 1 {
return microerror.Maskf(invalidFlagError, "--%s must contain at most one occurrence of '%%s' where k8s version will be injected", flagVSphereImageTemplate)
}
if placeholders == 1 {
f.VSphere.ImageTemplate = fmt.Sprintf(f.VSphere.ImageTemplate, f.KubernetesVersion)
}
if f.VSphere.Worker.Replicas < 1 {
return microerror.Maskf(invalidFlagError, "--%s must be greater than 0", flagVSphereWorkerReplicas)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/template/cluster/provider/capv.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func getMachineTemplate(machineTemplate *VSphereMachineTemplate, clusterConfig *
NumCPUs: machineTemplate.NumCPUs,
MemoryMiB: machineTemplate.MemoryMiB,
ResourcePool: config.ResourcePool,
Template: fmt.Sprintf(config.ImageTemplate, clusterConfig.KubernetesVersion),
Template: config.ImageTemplate,
}
}

Expand Down

0 comments on commit a56020c

Please sign in to comment.