Skip to content

Commit 8cff066

Browse files
authored
Merge pull request #37 from projectsyn/feat/refactor-plan-management
Add support for arbitrary configurations in `Plan` resources
2 parents 4b2ebf7 + 423b965 commit 8cff066

File tree

7 files changed

+327
-152
lines changed

7 files changed

+327
-152
lines changed

class/defaults.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ parameters:
1414
service_account: system-upgrade
1515
plan_polling_interval: "15m"
1616
suc_image: docker.io/rancher/system-upgrade-controller:v0.6.2
17-
floodgate_url: https://floodgate.syn.vshn.net/
17+
floodgate_url: https://floodgate.syn.vshn.net
1818
disable_grafana_dashboard: false
19-
plans: []

component/main.jsonnet

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -153,49 +153,82 @@ local deployment = kube.Deployment('system-upgrade-controller') {
153153
},
154154
};
155155

156-
local plan = [
156+
local optionalKey(p, k) =
157+
if std.objectHas(p, k) then k;
158+
159+
local convertLegacyPlan(p) = std.trace(
160+
'Converting legacy SUC plan "%(name)s", please update your config' % p,
161+
{
162+
spec: {
163+
concurrency: p.concurrency,
164+
[optionalKey(p, 'channel')]: p.channel,
165+
[optionalKey(p, 'version')]: p.version,
166+
upgrade: {
167+
image: p.image,
168+
[optionalKey(p, 'command')]: p.command,
169+
// todo verify old structure
170+
[optionalKey(p, 'args')]: p.args,
171+
},
172+
},
173+
[optionalKey(p, 'push_gateway')]: p.push_gateway,
174+
label_selectors: {
175+
[l.key]: l
176+
for l in p.label_selectors
177+
},
178+
tolerations: {
179+
[t.key]: t
180+
for t in com.getValueOrDefault(p, 'tolerations', [])
181+
},
182+
floodgate: {
183+
day: p.day,
184+
hour: p.hour,
185+
},
186+
}
187+
);
188+
189+
local planConfigs =
190+
if !std.objectHas(params, 'plans') then
191+
{}
192+
else if std.isArray(params.plans) then
193+
{
194+
[p.name]: convertLegacyPlan(p)
195+
for p in params.plans
196+
}
197+
else
198+
params.plans;
199+
200+
local plans = [
201+
local p = planConfigs[pname];
202+
local pspec = p.spec;
157203

158-
local channel = (
159-
if std.objectHas(p, 'channel') then
160-
p.channel
204+
local fixup_command(command) =
205+
if std.type(command) == 'string' then
206+
[ command ]
207+
else if std.type(command) == 'array' then
208+
command
161209
else
162-
params.floodgate_url + 'window/' + p.day + '/' + p.hour
163-
);
164-
165-
local args(p) =
166-
if std.objectHas(p, 'args') then (
167-
if std.type(p.args) == 'array' then
168-
if std.objectHas(p, 'push_gateway') then
169-
std.prune(p.args + [ p.push_gateway ])
170-
else
171-
p.args
172-
else
173-
error 'Field `args` of plan "%(name)s" is not an array' % p
174-
) else (
175-
if std.objectHas(p, 'push_gateway') then
176-
[ p.push_gateway ]
177-
else
178-
null
179-
);
180-
181-
local command(p) =
182-
if std.objectHas(p, 'command') then (
183-
if std.type(p.command) == 'string' then (
184-
[ p.command ]
185-
)
186-
else (
187-
if std.type(p.command) == 'array' then (
188-
p.command
189-
) else
190-
error 'Field `command` of plan "%(name)s" is not an array nor a string' % p
191-
)
192-
) else
193-
null;
194-
195-
local version = if std.objectHas(p, 'version') then p.version;
196-
197-
suc.Plan(p.name, channel, version, p.label_selectors, p.concurrency, p.tolerations, p.image, command(p), args(p))
198-
for p in params.plans
210+
error 'Field `spec.upgrade.command` of plan "%s" is not an array nor a string' % pname;
211+
212+
local tolerations = com.getValueOrDefault(p, 'tolerations', {});
213+
214+
local sp = suc.Plan(pname, p.label_selectors, tolerations) {
215+
spec+: com.makeMergeable(p.spec),
216+
};
217+
local needsFG = !std.objectHas(sp.spec, 'channel') && !std.objectHas(sp.spec, 'version');
218+
219+
sp {
220+
spec+: {
221+
[if needsFG then 'channel']: suc.floodgate_channel(p.floodgate),
222+
upgrade+: {
223+
command: fixup_command(super.command),
224+
[if std.objectHas(p, 'push_gateway') then 'args']+:
225+
[ p.push_gateway ],
226+
},
227+
},
228+
}
229+
230+
for pname in std.sort(std.objectFields(planConfigs))
231+
if planConfigs[pname] != null
199232
];
200233

201234
local controller_definition = {
@@ -208,7 +241,7 @@ local controller_definition = {
208241
};
209242

210243
local plans_definition = {
211-
'05_plans': plan,
244+
'05_plans': plans,
212245
};
213246

214247
if params.plans_only then

docs/modules/ROOT/pages/index.adoc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@ See the xref:references/parameters.adoc[parameters] reference for further detail
66

77
== Example for Ubuntu 20.04 (Focal)
88

9-
A minimal example to maintain all nodes of a cluster running Kubernetes 1.18 and Ubuntu 20.04 starting Tuesday at 22:00 having a node label `plan.upgrade.cattle.io/focal`:
9+
A minimal example to maintain all nodes with label `plan.upgrade.cattle.io/focal` of a cluster running Kubernetes 1.18 and Ubuntu 20.04 starting Tuesday at 22:00:
1010

1111
```
1212
parameters:
1313
system_upgrade_controller:
1414
job_kubectl_image: rancher/kubectl:v1.18.0
1515
disable_grafana_dashboard: true
1616
plans:
17-
- name: system-upgrade
18-
concurrency: 1
19-
image: docker.io/projectsyn/suc-ubuntu-focal
20-
command: /scripts/run.sh
21-
# push_gateway: platform-prometheus-pushgateway.syn-synsights.svc:9091
22-
push_gateway: 10.43.129.22:9091
23-
day: 2 # Tuesday
24-
hour: 22
17+
focal:
18+
spec:
19+
concurrency: 1
20+
upgrade:
21+
image: docker.io/projectsyn/suc-ubuntu-focal
22+
command: /scripts/run.sh
23+
# push_gateway: platform-prometheus-pushgateway.syn-synsights.svc:9091
24+
push_gateway: 10.43.129.22:9091
25+
floodgate:
26+
day: 2 # Tuesday
27+
hour: 22
2528
label_selectors:
26-
- {key: plan.upgrade.cattle.io/focal, operator: Exists}
29+
plan.upgrade.cattle.io/focal:
30+
operator: Exists
2731
tolerations:
28-
- key: node-role.kubernetes.io/controlplane
32+
node-role.kubernetes.io/controlplane:
2933
operator: Exists
30-
- key: node-role.kubernetes.io/etcd
34+
node-role.kubernetes.io/etcd:
3135
operator: Exists
3236
```

0 commit comments

Comments
 (0)