Skip to content

Commit

Permalink
Move most values to component defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Haeusler committed Jun 30, 2020
1 parent d882847 commit 0d6c246
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 62 deletions.
41 changes: 40 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
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: []
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: {}
87 changes: 26 additions & 61 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,57 @@ 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 machine = function(name, spec)
local machineSpec = if std.objectHas(spec, 'spec') then spec.spec else {};
local type = if std.objectHas(spec, 'type') then spec.type else 'worker';
com.namespaced('openshift-machine-api', kube._Object('machine.openshift.io/v1beta1', 'MachineSet', name) {
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: if std.objectHas(spec, 'replicas') then spec.replicas else 1,
selector: {
matchLabels: {
spec+: {
replicas: if std.objectHas(set, 'replicas') then set.replicas else 1,
selector+: {
matchLabels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machineset': name,
},
},
template: {
metadata: {
creationTimestamp: null,
labels: {
template+: {
metadata+: {
labels+: {
'machine.openshift.io/cluster-api-cluster': params.infrastructureID,
'machine.openshift.io/cluster-api-machine-role': type,
'machine.openshift.io/cluster-api-machine-type': type,
'machine.openshift.io/cluster-api-machine-role': role,
'machine.openshift.io/cluster-api-machine-type': role,
'machine.openshift.io/cluster-api-machineset': name,
},
},
spec: {
metadata: {
creationTimestamp: null,
},
spec+: {
providerSpec+: {
value+: {
apiVersion: 'gcpprovider.openshift.io/v1beta1',
canIPForward: false,
credentialsSecret: {
name: 'gcp-cloud-credentials',
},
deletionProtection: false,
disks: [
{
autoDelete: true,
boot: true,
image: params.infrastructureID + '-rhcos-image',
labels: null,
sizeGb: 128,
type: 'pd-ssd',
},
],
kind: 'GCPMachineProviderSpec',
machineType: spec.instanceType,
metadata: {
creationTimestamp: null,
},
machineType: set.instanceType,
networkInterfaces: [
{
network: params.infrastructureID + '-network',
subnetwork: params.infrastructureID + '-worker-subnet',
},
],
projectID: params.projectName,
region: params.region,
serviceAccounts: [
{
email: params.infrastructureID + '-w@' + params.projectName + '.iam.gserviceaccount.com',
scopes: [
'https://www.googleapis.com/auth/cloud-platform',
],
subnetwork: params.infrastructureID + '-' + role + '-subnet',
},
],
tags: [
params.infrastructureID + '-worker',
params.infrastructureID + '-' + role,
],
userDataSecret: {
name: 'worker-user-data',
},
zone: params.availabilityZones[0],
},
},
} + machineSpec,
},
},
},
});
}
+ if std.objectHas(set, 'spec') then { spec+: set.spec } else {};

local isMultiAz = function(name)
std.objectHas(params.nodeGroups[name], 'multiAz') && params.nodeGroups[name].multiAz == true;
Expand All @@ -103,7 +68,7 @@ local machineSpecs = [
] + std.flattenArrays([
[
local spec = {
spec: {
spec+: {
providerSpec+: {
value+: {
zone: zone,
Expand All @@ -118,12 +83,12 @@ local machineSpecs = [
if isMultiAz(name)
]);

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

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

0 comments on commit 0d6c246

Please sign in to comment.