From 98598f25b554b8a30654997ef6703038f832e9a9 Mon Sep 17 00:00:00 2001 From: Richard Vanderpool <49568690+rvanderp3@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:30:02 -0400 Subject: [PATCH] add zones to machinepool specification --- .../data/install.openshift.io_installconfigs.yaml | 15 +++++++++++++++ pkg/types/vsphere/machinepool.go | 5 +++++ pkg/types/vsphere/validation/machinepool.go | 9 +++++++++ pkg/types/vsphere/validation/machinepool_test.go | 8 ++++++++ 4 files changed, 37 insertions(+) diff --git a/data/data/install.openshift.io_installconfigs.yaml b/data/data/install.openshift.io_installconfigs.yaml index 764b9bdbf00..d341a63e948 100644 --- a/data/data/install.openshift.io_installconfigs.yaml +++ b/data/data/install.openshift.io_installconfigs.yaml @@ -522,6 +522,11 @@ spec: format: int32 type: integer type: object + zones: + description: Zones defines available zones + items: + type: string + type: array type: object type: object replicas: @@ -980,6 +985,11 @@ spec: format: int32 type: integer type: object + zones: + description: Zones defines available zones + items: + type: string + type: array type: object type: object replicas: @@ -2234,6 +2244,11 @@ spec: format: int32 type: integer type: object + zones: + description: Zones defines available zones + items: + type: string + type: array type: object diskType: description: DiskType is the name of the disk provisioning type, diff --git a/pkg/types/vsphere/machinepool.go b/pkg/types/vsphere/machinepool.go index 13039ecd812..99b45ea89c7 100644 --- a/pkg/types/vsphere/machinepool.go +++ b/pkg/types/vsphere/machinepool.go @@ -23,6 +23,11 @@ type MachinePool struct { // // +optional OSDisk `json:"osDisk"` + + // Zones defines available zones + // + // +omitempty + Zones []string `json:"zones,omitempty"` } // OSDisk defines the disk for a virtual machine. diff --git a/pkg/types/vsphere/validation/machinepool.go b/pkg/types/vsphere/validation/machinepool.go index c3b468346c5..8d1e97e628c 100644 --- a/pkg/types/vsphere/validation/machinepool.go +++ b/pkg/types/vsphere/validation/machinepool.go @@ -1,6 +1,7 @@ package validation import ( + "github.com/openshift/installer/pkg/validate" "k8s.io/apimachinery/pkg/util/validation/field" "github.com/openshift/installer/pkg/types/vsphere" @@ -24,5 +25,13 @@ func ValidateMachinePool(p *vsphere.MachinePool, fldPath *field.Path) field.Erro if p.NumCoresPerSocket >= 0 && p.NumCPUs >= 0 && p.NumCoresPerSocket > p.NumCPUs { allErrs = append(allErrs, field.Invalid(fldPath.Child("coresPerSocket"), p.NumCoresPerSocket, "cores per socket must be less than number of CPUs")) } + if len(p.Zones) > 0 { + for _, zone := range p.Zones { + err := validate.ClusterName1035(zone) + if err != nil { + allErrs = append(allErrs, field.Invalid(fldPath.Child("zones"), p.Zones, err.Error())) + } + } + } return allErrs } diff --git a/pkg/types/vsphere/validation/machinepool_test.go b/pkg/types/vsphere/validation/machinepool_test.go index 6138723b217..c14bd143aaa 100644 --- a/pkg/types/vsphere/validation/machinepool_test.go +++ b/pkg/types/vsphere/validation/machinepool_test.go @@ -52,6 +52,14 @@ func TestValidateMachinePool(t *testing.T) { NumCoresPerSocket: 8, }, expectedErrMsg: `^test-path\.coresPerSocket: Invalid value: 8: cores per socket must be less than number of CPUs$`, + }, { + name: "invalid zone name", + pool: &vsphere.MachinePool{ + Zones: []string{ + "Zone%^@112233", + }, + }, + expectedErrMsg: `^test-path.zones: Invalid value: \[\]string{"Zone%\^@112233"}: cluster name must begin with a lower-case letter$`, }, } for _, tc := range cases {