Skip to content

Instantly share code, notes, and snippets.

@nastacio
Last active October 19, 2022 01:11
Show Gist options
  • Save nastacio/7e66f871e395cdbec759d832416f7093 to your computer and use it in GitHub Desktop.
Save nastacio/7e66f871e395cdbec759d832416f7093 to your computer and use it in GitHub Desktop.
Clone and modify machine sets in OCP cluster
#!/bin/sh
infra_id=$(kubectl get Infrastructure cluster -o jsonpath='{.status.infrastructureName}')
instance_size=${1:-c5a.xlarge}
kubectl get MachineSet \
-n openshift-machine-api \
-l hive.openshift.io/machine-pool=worker \
-l hive.openshift.io/managed=true \
-o yaml \
| yq 'del (.items[].status)' \
| yq 'del (.items[].metadata.annotations)' \
| yq 'del (.items[].metadata.uid)' \
| yq 'del (.items[].metadata.resourceVersion)' \
| yq 'del (.items[].metadata.generation)' \
| yq 'del (.items[].metadata.creationTimestamp)' \
| yq 'del (.items[].metadata.labels."hive.openshift.io/managed")' \
| yq 'del (.items[].metadata.labels."hive.openshift.io/machine-pool")' \
| yq '.items[].metadata.labels += { "machine.sourcepatch.com/interruptible": "true" }' \
| yq '.items[].spec.template.metadata.labels += { "machine.sourcepatch.com/interruptible": "true" }' \
| yq '.items[].spec.template.spec.providerSpec.value.spotMarketOptions={}' \
| yq '.items[].spec.template.spec.taints += [{ "effect": "NoSchedule", "key": "workload.sourcepatch.com/interruptible", "value": "true" }]' \
| yq '.items[].spec.template.spec.metadata.labels += { "sourcepatch.com/node.interruptible": "true"}' \
| yq ".items[].spec.template.spec.providerSpec.value.instanceType= \"${instance_size:?}\"" \
| sed "s/name: ${infra_id:?}-worker/name: ${infra_id:?}-worker-spot/" \
| sed "s/machineset: ${infra_id:?}-worker/machineset: ${infra_id:?}-worker-spot/" \
| kubectl apply -f -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment