Skip to content

Commit

Permalink
Support creating ControlPlaneMachineSet (#82)
Browse files Browse the repository at this point in the history
* Support creating ControlPlaneMachineSet

If using a NodeGroup named `master` a ControlPlaneMachineSet will be created
instead of a normal MachineSet.

* Apply suggestions from code review

Co-authored-by: Simon Gerber <[email protected]>

---------

Co-authored-by: Simon Gerber <[email protected]>
  • Loading branch information
DebakelOrakel and simu authored Jun 18, 2024
1 parent 7ae447b commit ee01f07
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 7 deletions.
78 changes: 71 additions & 7 deletions component/machine-sets.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ local params = inv.parameters.openshift4_nodes;

local isGCP = inv.parameters.facts.cloud == 'gcp';

local machineSet = function(name, set)
local role = if std.objectHas(set, 'role') then set.role else name;
kube._Object('machine.openshift.io/v1beta1', 'MachineSet', name)
+ { spec+: params.defaultSpecs[inv.parameters.facts.cloud] }
+ {
local machineSetSpecs = function(name, set, role)
kube._Object('machine.openshift.io/v1beta1', 'MachineSet', name) {
spec+: params.defaultSpecs[inv.parameters.facts.cloud],
} + {
metadata+: {
annotations+: com.getValueOrDefault(set, 'annotations', {}),
labels+: {
Expand Down Expand Up @@ -55,8 +54,73 @@ local machineSet = function(name, set)
},
},
},
}
+ if std.objectHas(set, 'spec') then { spec+: com.makeMergeable(set.spec) } else {};
};

local cpMachineSetSpecs = function(set)
kube._Object('machine.openshift.io/v1', 'ControlPlaneMachineSet', 'cluster') {
spec+: {
template+: {
machines_v1beta1_machine_openshift_io: {
spec+: {
providerSpec+: {
value+: params.defaultSpecs[inv.parameters.facts.cloud].template.spec.providerSpec.value,
},
},
},
},
},
} + {
metadata+: {
annotations+: std.get(set, 'annotations', {}),
namespace: params.machineApiNamespace,
},
spec+: {
replicas: std.get(set, 'replicas', 1),
selector+: {
matchLabels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machine-role': 'master',
'machine.openshift.io/cluster-api-machine-type': 'master',
},
},
state: 'Inactive',
strategy+: {
type: 'OnDelete',
},
template+: {
machineType+: 'machines_v1beta1_machine_openshift_io',
machines_v1beta1_machine_openshift_io+: {
failureDomains+: {
platform: '',
},
metadata+: {
labels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machine-role': 'master',
'machine.openshift.io/cluster-api-machine-type': 'master',
},
},
spec+: {
[if isGCP then 'providerSpec']+: {
value+: {
machineType: set.instanceType,
tags: [
params.infrastructureID + '-master',
],
zone: params.availabilityZones[0],
},
},
},
},
},
},
};

local machineSet = function(name, set)
local role = std.get(set, 'role', name);
local spec = com.makeMergeable(std.get(set, 'spec', {}));
if role == 'master' then cpMachineSetSpecs(set) { spec+: spec }
else machineSetSpecs(name, set, role) { spec+: spec };

local isMultiAz = function(name)
com.getValueOrDefault(params.nodeGroups[name], 'multiAz', false);
Expand Down
3 changes: 3 additions & 0 deletions tests/gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ parameters:
- europe-west6-c

nodeGroups:
master:
replicas: 5
instanceType: super-trooper
infra:
instanceType: n1-standard-8
multiAz: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: machine.openshift.io/v1
kind: ControlPlaneMachineSet
metadata:
annotations: {}
labels:
name: cluster
name: cluster
namespace: openshift-machine-api
spec:
replicas: 5
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: infra-id
machine.openshift.io/cluster-api-machine-role: master
machine.openshift.io/cluster-api-machine-type: master
state: Inactive
strategy:
type: OnDelete
template:
machineType: machines_v1beta1_machine_openshift_io
machines_v1beta1_machine_openshift_io:
failureDomains:
platform: ''
metadata:
labels:
machine.openshift.io/cluster-api-cluster: infra-id
machine.openshift.io/cluster-api-machine-role: master
machine.openshift.io/cluster-api-machine-type: master
spec:
providerSpec:
value:
apiVersion: gcpprovider.openshift.io/v1beta1
canIPForward: false
credentialsSecret:
name: gcp-cloud-credentials
deletionProtection: false
disks:
- autoDelete: true
boot: true
image: infra-id-rhcos-image
labels: null
sizeGb: 128
type: pd-ssd
kind: GCPMachineProviderSpec
machineType: super-trooper
metadata:
creationTimestamp: null
networkInterfaces:
- network: infra-id-network
subnetwork: infra-id-worker-subnet
projectID: cluster-test
region: rma1
serviceAccounts:
- email: [email protected]
scopes:
- https://www.googleapis.com/auth/cloud-platform
tags:
- infra-id-master
userDataSecret:
name: worker-user-data
zone: europe-west6-a

0 comments on commit ee01f07

Please sign in to comment.