From 183140b2d5697b6c1c115cbaa325016aea3130f7 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Thu, 31 Oct 2024 16:26:10 +0100 Subject: [PATCH] Allow managing raw `MachineSets` --- class/defaults.yml | 2 + component/machine-sets.jsonnet | 9 ++- .../ROOT/pages/references/parameters.adoc | 58 +++++++++++++++++++ .../openshift4-nodes/.gitkeep.yaml | 0 .../additional_machine_sets.yaml | 45 ++++++++++++++ tests/machineconfig.yml | 42 ++++++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) delete mode 100644 tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/.gitkeep.yaml create mode 100644 tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/additional_machine_sets.yaml diff --git a/class/defaults.yml b/class/defaults.yml index 650cef7..d2f53b0 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -84,6 +84,8 @@ parameters: nodeGroups: {} + machineSets: {} + machineConfigPools: infra: {} app: {} diff --git a/component/machine-sets.jsonnet b/component/machine-sets.jsonnet index 9eea1df..399be9a 100644 --- a/component/machine-sets.jsonnet +++ b/component/machine-sets.jsonnet @@ -150,11 +150,18 @@ local machineSpecs = [ if isGCP && isMultiAz(name) ]); +local additionalMachineSets = com.generateResources(params.machineSets, function(name) kube._Object('machine.openshift.io/v1beta1', 'MachineSet', name) { + metadata+: { + namespace: params.machineApiNamespace, + }, +}); { ['machineset-' + m.name]: machineSet(m.name, m.spec) for m in machineSpecs if m.spec != null } + { - [if std.length(machineSpecs) == 0 then '.gitkeep']: {}, + [if std.length(machineSpecs) == 0 && std.length(additionalMachineSets) == 0 then '.gitkeep']: {}, +} + { + [if std.length(additionalMachineSets) > 0 then 'additional_machine_sets']: additionalMachineSets, } diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index a5d7a2c..5105272 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -488,6 +488,64 @@ See the documentation for http://localhost:2020/cilium/references/parameters.htm The script expects the ConfigMap to have a key matching each node name on which egress dummy interfaces should be configured. + +== `machineSets` + +[horizontal] +type:: dictionary +default:: `{}` +example:: ++ +[source,yaml] +---- +machineSets: + worker: + metadata: + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + spec: + deletePolicy: Oldest + replicas: 3 + selector: + matchLabels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machineset: worker + template: + metadata: + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machine-role: app + machine.openshift.io/cluster-api-machine-type: app + machine.openshift.io/cluster-api-machineset: worker + spec: + lifecycleHooks: {} + metadata: + labels: + node-role.kubernetes.io/app: "" + node-role.kubernetes.io/worker: "" + providerSpec: + value: + antiAffinityKey: worker + baseDomain: c-cluster-1.vshnmanaged.net + flavor: plus-16-4 + image: custom:rhcos-4.16 + interfaces: + - addresses: + - subnetUUID: 1971d4c3-0065-41fc-82f4-c26cf2fe4f9a + type: Private + rootVolumeSizeGB: 100 + tokenSecret: + name: cloudscale-rw-token + userDataSecret: + name: cloudscale-user-data + zone: lpg1 +---- + +A dictionary of machine sets to create on the cluster. +The resulting `MachineSet` object will have the key as the name and the value is merged into the resource. + +The MachineSet will will have the namespace from `machine_api_namespace` applied. + === Example [source,yaml] diff --git a/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/.gitkeep.yaml b/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/.gitkeep.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/additional_machine_sets.yaml b/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/additional_machine_sets.yaml new file mode 100644 index 0000000..a9a30d4 --- /dev/null +++ b/tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/additional_machine_sets.yaml @@ -0,0 +1,45 @@ +apiVersion: machine.openshift.io/v1beta1 +kind: MachineSet +metadata: + annotations: {} + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + name: worker + name: worker + namespace: openshift-machine-api +spec: + deletePolicy: Oldest + replicas: 3 + selector: + matchLabels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machineset: worker + template: + metadata: + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machine-role: app + machine.openshift.io/cluster-api-machine-type: app + machine.openshift.io/cluster-api-machineset: worker + spec: + lifecycleHooks: {} + metadata: + labels: + node-role.kubernetes.io/app: '' + node-role.kubernetes.io/worker: '' + providerSpec: + value: + antiAffinityKey: worker + baseDomain: c-cluster-1.vshnmanaged.net + flavor: plus-16-4 + image: custom:rhcos-4.16 + interfaces: + - addresses: + - subnetUUID: 1971d4c3-0065-41fc-82f4-c26cf2fe4f9a + type: Private + rootVolumeSizeGB: 100 + tokenSecret: + name: cloudscale-rw-token + userDataSecret: + name: cloudscale-user-data + zone: lpg1 diff --git a/tests/machineconfig.yml b/tests/machineconfig.yml index 276fe24..d00d0bc 100644 --- a/tests/machineconfig.yml +++ b/tests/machineconfig.yml @@ -91,3 +91,45 @@ parameters: egressInterfaces: machineConfigPools: - infra + + machineSets: + worker: + metadata: + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + spec: + deletePolicy: Oldest + replicas: 3 + selector: + matchLabels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machineset: worker + template: + metadata: + labels: + machine.openshift.io/cluster-api-cluster: c-cluster-1 + machine.openshift.io/cluster-api-machine-role: app + machine.openshift.io/cluster-api-machine-type: app + machine.openshift.io/cluster-api-machineset: worker + spec: + lifecycleHooks: {} + metadata: + labels: + node-role.kubernetes.io/app: "" + node-role.kubernetes.io/worker: "" + providerSpec: + value: + antiAffinityKey: worker + baseDomain: c-cluster-1.vshnmanaged.net + flavor: plus-16-4 + image: custom:rhcos-4.16 + interfaces: + - addresses: + - subnetUUID: 1971d4c3-0065-41fc-82f4-c26cf2fe4f9a + type: Private + rootVolumeSizeGB: 100 + tokenSecret: + name: cloudscale-rw-token + userDataSecret: + name: cloudscale-user-data + zone: lpg1