Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic ability to configure MachineSets #1

Merged
merged 11 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
parameters:
openshift4_nodes:
namespace: syn-openshift4-nodes
namespace: openshift-machine-api
defaultSpecs:
aws: {}
azure: {}
gcp:
deletePolicy: Oldest
template:
spec:
metadata:
labels: {}
providerSpec:
value:
apiVersion: gcpprovider.openshift.io/v1beta1
canIPForward: false
credentialsSecret:
name: gcp-cloud-credentials
deletionProtection: false
disks:
- autoDelete: true
boot: true
image: ${openshift4_nodes:infrastructureID}-rhcos-image
labels: null
sizeGb: 128
type: pd-ssd
kind: GCPMachineProviderSpec
machineType: n1-standard-4
metadata:
creationTimestamp: null
networkInterfaces:
- network: ${openshift4_nodes:infrastructureID}-network
subnetwork: ${openshift4_nodes:infrastructureID}-worker-subnet
projectID: ${openshift4_nodes:projectName}
region: ${cloud:region}
serviceAccounts:
- email: ${openshift4_nodes:infrastructureID}-w@${openshift4_nodes:projectName}.iam.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/cloud-platform
tags: []
userDataSecret:
name: worker-user-data

nodeGroups: {}
92 changes: 90 additions & 2 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,10 +1,98 @@
// main template for openshift4-nodes
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component

local params = inv.parameters.openshift4_nodes;

local machineSet = function(name, set)
local role = if std.objectHas(set, 'role') then set.role else 'worker';
kube._Object('machine.openshift.io/v1beta1', 'MachineSet', name)
+ { spec+: params.defaultSpecs[inv.parameters.cloud.provider] }
+ {
metadata+: {
labels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
},
namespace: params.namespace,
},
spec+: {
replicas: com.getValueOrDefault(set, 'replicas', 1),
selector+: {
matchLabels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machineset': name,
},
},
template+: {
metadata+: {
labels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machine-role': role,
'machine.openshift.io/cluster-api-machine-type': role,
'machine.openshift.io/cluster-api-machineset': name,
},
},
spec+: {
providerSpec+: {
corvus-ch marked this conversation as resolved.
Show resolved Hide resolved
value+: {
machineType: set.instanceType,
tags: [
params.infrastructureID + '-' + role,
],
zone: params.availabilityZones[0],
},
},
},
},
},
}
+ if std.objectHas(set, 'spec') then { spec+: com.makeMergeable(set.spec) } else {};

local isMultiAz = function(name)
std.objectHas(params.nodeGroups[name], 'multiAz') && params.nodeGroups[name].multiAz == true;

local zoneId = function(name)
std.reverse(std.split(name, '-'))[0];

local replicasPerZone(replicas) =
std.ceil(replicas / std.length(params.availabilityZones));

local machineSpecs = [
{ name: name, spec: params.nodeGroups[name] }
for name in std.objectFields(params.nodeGroups)
if !isMultiAz(name)
] + std.flattenArrays([
[
{
name: name + '-' + zoneId(zone),
spec: params.nodeGroups[name] {
replicas: replicasPerZone(com.getValueOrDefault(params.nodeGroups[name], 'replicas', 1)),
spec+: {
template+: {
spec+: {
providerSpec+: {
value+: {
zone: zone,
},
},
},
},
},
},
}
for zone in params.availabilityZones
]
for name in std.objectFields(params.nodeGroups)
if isMultiAz(name)
]);

local machineSets = [
machineSet(m.name, m.spec)
for m in machineSpecs
];

// Define outputs below
{
'01_machinesets': machineSets,
}