7575# get_aws_ms creates a MachineSet for AWS Cloud Provider
7676get_aws_ms () {
7777
78- if [ " $# " -lt 6 ]; then
78+ if [ " $# " -lt 4 ]; then
7979 error-exit incorrect parameter count for get_aws_ms $#
8080 fi
8181
8282 local infraID=$1
83- local region=$2
84- local az=$3
85- local provider=$4
86- local winver=$5
87- local byoh=$6
83+ local linuxWorkerSpec=$2
84+ local winver=$3
85+ local byoh=$4
8886
8987 local filter=" Windows_Server-2022-English-Core-Base-????.??.??"
9088 if [ " $winver " == " 2019" ]; then
9189 filter=" Windows_Server-2019-English-Core-Base-????.??.??"
9290 fi
9391
92+
93+ local az=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.placement.availibilityZone)
94+ local region=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.placement.region)
95+ #
9496 # get the AMI id for the Windows VM
9597 ami_id=$( aws ec2 describe-images --region " ${region} " --filters " Name=name,Values=$filter " " Name=is-public, Values=true" --query " reverse(sort_by(Images, &CreationDate))[*].{name: Name, id: ImageId}" --output json | jq -r ' .[0].id' )
9698 if [ -z " $ami_id " ]; then
9799 error-exit " unable to find AMI ID for Windows Server 2019 1809"
98100 fi
99101
100102 cat << EOF
101- $( get_spec $infraID $az $provider $byoh )
103+ $( get_spec $infraID $az aws $byoh )
102104 providerSpec:
103105 value:
104106 ami:
@@ -140,16 +142,14 @@ EOF
140142# get_azure_ms creates a MachineSet for Azure Cloud Provider
141143get_azure_ms () {
142144
143- if [ " $# " -lt 6 ]; then
145+ if [ " $# " -lt 4 ]; then
144146 error-exit incorrect parameter count for get_azure_ms $#
145147 fi
146148
147149 local infraID=$1
148- local region=$2
149- local az=$3
150- local provider=$4
151- local winver=$5
152- local byoh=$6
150+ local linuxWorkerSpec=$2
151+ local winver=$3
152+ local byoh=$4
153153
154154 local sku=" 2022-datacenter-smalldisk"
155155 local release=" latest"
@@ -159,15 +159,21 @@ get_azure_ms() {
159159 sku=" 2019-datacenter-with-containers-smalldisk"
160160 release=" 17763.6293.240905"
161161 fi
162+ local az=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.zone | sed ' s/null/""/g' )
163+ local region=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.location)
164+ local loadBalancer=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.publicLoadBalancer)
162165
163166 cat << EOF
164- $( get_spec $infraID $az $provider $byoh )
167+ $( get_spec $infraID $az azure $byoh )
165168 providerSpec:
166169 value:
167170 apiVersion: azureproviderconfig.openshift.io/v1beta1
168171 credentialsSecret:
169172 name: azure-cloud-credentials
170173 namespace: openshift-machine-api
174+ diagnostics:
175+ boot:
176+ storageAccountType: AzureManaged
171177 image:
172178 offer: WindowsServer
173179 publisher: MicrosoftWindowsServer
@@ -185,42 +191,44 @@ $(get_spec $infraID $az $provider $byoh)
185191 storageAccountType: Premium_LRS
186192 osType: Windows
187193 publicIP: false
194+ publicLoadBalancer: $loadBalancer
188195 resourceGroup: ${infraID} -rg
189196 subnet: ${infraID} -worker-subnet
190197 userDataSecret:
191198 name: windows-user-data
192199 namespace: openshift-machine-api
193200 vmSize: Standard_D2s_v3
194201 vnet: ${infraID} -vnet
195- zone: " ${az} "
202+ zone: $az
196203EOF
197204}
198205
199206# get_gcp_ms creates a MachineSet for Google Cloud Platform
200207get_gcp_ms () {
201- if [ " $# " -lt 6 ]; then
208+ if [ " $# " -lt 4 ]; then
202209 error-exit incorrect parameter count for get_gcp_ms $#
203210 fi
204211
205212 local infraID=$1
206- local region=$2
207- local az=$3
208- local provider=$4
209- local winver=$5
210- local byoh=$6
213+ local linuxWorkerSpec=$2
214+ local winver=$3
215+ local byoh=$4
211216
212217 local image=" projects/windows-cloud/global/images/family/windows-2022-core"
213218 if [ " $winver " == " 2019" ]; then
214219 image=" projects/windows-cloud/global/images/family/windows-2019-core"
215220 fi
216221
222+ local az=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.zone)
223+ local region=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.region)
224+ local projectID=$( echo " $linuxWorkerSpec " | jq -r .providerSpec.value.projectID)
225+
217226 # For GCP the zone field returns the region + zone, like: `us-central1-a`.
218227 # Installer created MachineSets only append the `-a` portion, so we should do the same.
219228 local az_suffix=$( echo $az | awk -F " -" ' {print $NF}' )
220- local projectID=$( oc get infrastructure cluster -ojsonpath={.status.platformStatus.gcp.projectID})
221229
222230 cat << EOF
223- $( get_spec $infraID $az_suffix $provider $byoh )
231+ $( get_spec $infraID $az_suffix gce $byoh )
224232 providerSpec:
225233 value:
226234 apiVersion: machine.openshift.io/v1beta1
@@ -256,13 +264,12 @@ EOF
256264# get_vsphere_ms creates a MachineSet for vSphere Cloud Provider
257265get_vsphere_ms () {
258266
259- if [ " $# " -lt 3 ]; then
267+ if [ " $# " -lt 2 ]; then
260268 error-exit incorrect parameter count for get_vsphere_ms $#
261269 fi
262270
263271 local infraID=$1
264- local provider=$2
265- local byoh=$3
272+ local byoh=$2
266273
267274 # set golden image template name
268275 # TODO: read from parameter
@@ -276,10 +283,10 @@ get_vsphere_ms() {
276283 -l machine.openshift.io/cluster-api-machine-role=worker \
277284 -o jsonpath=" {.items[0].spec.providerSpec.value}" \
278285 ) || {
279- error-exit " error getting providerSpec for ${provider} cluster ${infraID} "
286+ error-exit " error getting providerSpec for cluster ${infraID} "
280287 }
281288 if [ -z " $providerSpec " ]; then
282- error-exit " cannot find providerSpec for ${provider} cluster ${infraID} "
289+ error-exit " cannot find providerSpec for cluster ${infraID} "
283290 fi
284291 # get credentialsSecret
285292 credentialsSecret=$( echo " ${providerSpec} " | jq -r ' .credentialsSecret.name' )
@@ -293,7 +300,7 @@ get_vsphere_ms() {
293300 server=$( echo " ${providerSpec} " | jq -r ' .workspace.server' )
294301 # build machineset
295302 cat << EOF
296- $( get_spec $infraID " " $provider $byoh )
303+ $( get_spec $infraID " " vsphere $byoh )
297304 providerSpec:
298305 value:
299306 apiVersion: vsphereprovider.openshift.io/v1beta1
@@ -321,13 +328,12 @@ EOF
321328# get_nutanix_ms creates a MachineSet for Nutanix
322329get_nutanix_ms () {
323330
324- if [ " $# " -lt 3 ]; then
331+ if [ " $# " -lt 2 ]; then
325332 error-exit incorrect parameter count for get_nutanix_ms $#
326333 fi
327334
328335 local infraID=$1
329- local provider=$2
330- local byoh=$3
336+ local byoh=$2
331337
332338 # set Windows Server 2022 image name
333339 imageName=" nutanix-windows-server-openshift.qcow2"
@@ -347,7 +353,7 @@ get_nutanix_ms() {
347353 subnetId=$( echo " ${providerSpec} " | jq -r ' .subnets[0].uuid' )
348354 # build machineset
349355 cat << EOF
350- $( get_spec $infraID " " $provider $byoh )
356+ $( get_spec $infraID " " nutanix $byoh )
351357 providerSpec:
352358 value:
353359 apiVersion: machine.openshift.io/v1
@@ -414,28 +420,24 @@ platform="$(oc get infrastructure cluster -ojsonpath={.spec.platformSpec.type})"
414420# Gets the Infrastructure Id for the cluster like `pmahajan-azure-68p9l-gv45m`
415421infraID=" $( oc get -o jsonpath=' {.status.infrastructureName}{"\n"}' infrastructure cluster) "
416422
417- # Determines the region based on existing MachinesSets like `us-east-1` for aws or `centralus` for azure
418- region=" $( oc get machines -n openshift-machine-api | grep -w " Running" | awk ' {print $4}' | head -1) "
419-
420- # Determines the availability zone based on existing MachinesSets like `us-east-1a` for aws or `2` for azure
421- az=" $( oc get machines -n openshift-machine-api | grep -w " Running" | awk ' {print $5}' | head -1) "
423+ linuxWorkerSpec=$( oc get machines -n openshift-machine-api -l machine.openshift.io/cluster-api-machine-role=worker -ojsonpath={.items[0].spec})
422424
423425# Creates/deletes a MachineSet for Cloud Provider
424426case " $platform " in
425427 AWS)
426- ms=$( get_aws_ms $infraID $region $az $platform $winver $byoh )
428+ ms=$( get_aws_ms $infraID $linuxWorkerSpec $winver $byoh )
427429 ;;
428430 Azure)
429- ms=$( get_azure_ms $infraID $region $az $platform $winver $byoh )
431+ ms=$( get_azure_ms $infraID $linuxWorkerSpec $winver $byoh )
430432 ;;
431433 GCP)
432- ms=$( get_gcp_ms $infraID $region $az $platform $winver $byoh )
434+ ms=$( get_gcp_ms $infraID $linuxWorkerSpec $winver $byoh )
433435 ;;
434436 VSphere)
435- ms=$( get_vsphere_ms $infraID $platform $ byoh)
437+ ms=$( get_vsphere_ms $infraID $byoh )
436438 ;;
437439 Nutanix)
438- ms=$( get_nutanix_ms $infraID $platform $ byoh)
440+ ms=$( get_nutanix_ms $infraID $byoh )
439441 ;;
440442 * )
441443 error-exit " platform '$platform ' is not yet supported by this script"
0 commit comments