Skip to content

Commit d61fcde

Browse files
committed
Fix CRICTL versioning, add config path param
1 parent 260c8ff commit d61fcde

File tree

5 files changed

+92
-14
lines changed

5 files changed

+92
-14
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ require (
88
github.com/gorilla/mux v1.8.0
99
github.com/pkg/errors v0.9.1
1010
github.com/sirupsen/logrus v1.8.1
11+
golang.org/x/mod v0.3.0
1112
gopkg.in/yaml.v2 v2.2.8 // indirect
1213
)

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
186186
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
187187
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
188188
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
189+
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
189190
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
190191
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
191192
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

k8s/configmap.yaml

+68-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,73 @@ metadata:
55
app: zippo
66
name: zippo-config
77
data:
8-
config: |
8+
zippo.tmpl: |
99
variant: fcos
1010
version: 1.1.0
11+
12+
passwd:
13+
users:
14+
- name: {{ .SSHUser }}
15+
ssh_authorized_keys:
16+
- {{ .SSHPubkey }}
17+
18+
systemd:
19+
units:
20+
# Bootstrap service
21+
- name: bootstrap.service
22+
enabled: true
23+
contents: |
24+
[Unit]
25+
Description=Bootstrap script
26+
27+
# Make sure we have networking up and running
28+
Wants=network-online.target
29+
After=network-online.target
30+
31+
# We run before `zincati.service` to avoid conflicting rpm-ostree transactions.
32+
Before=zincati.service
33+
ConditionPathExists=!/var/lib/%N.stamp
34+
35+
[Service]
36+
Type=oneshot
37+
RemainAfterExit=yes
38+
ExecStart=/usr/local/bin/bootstrap.sh
39+
ExecStart=/bin/touch /var/lib/%N.stamp
40+
41+
[Install]
42+
WantedBy=multi-user.target
43+
dropins:
44+
- name: boostrap-rpms.conf
45+
contents: |
46+
[Service]
47+
Environment="BOOTSTRAP_RPMS="
48+
Environment="CNI_VERSION={{ .CNIVersion }}"
49+
Environment="CRICTL_VERSION={{ .CRICtlVersion }}"
50+
51+
52+
storage:
53+
files:
54+
- path: /etc/hostname
55+
mode: 0644
56+
contents:
57+
inline: |
58+
{{ .Hostname }}
59+
60+
# Bootstrap script
61+
- path: /usr/local/bin/bootstrap.sh
62+
mode: 0755
63+
contents:
64+
inline: |
65+
#!/bin/bash
66+
set -euo pipefail
67+
68+
# Disable swap
69+
swapoff -a
70+
71+
# Install package dependencies if needed
72+
/usr/bin/rpm-ostree install --apply-live --allow-inactive --idempotent $BOOTSTRAP_RPMS
73+
74+
# Install CNI, CRICTL
75+
mkdir -p /opt/cni/bin
76+
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
77+
curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | tar -C /usr/local/bin -xz

k8s/deployment.yaml

+9-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ spec:
2323
- --ssh-user=core
2424
- --ssh-pubkey=
2525
- --k8s=v1.20.0
26-
- --template=/etc/zippo/zippo.yaml
26+
- --template=/etc/zippo/templates/zippo.tmpl
27+
- --config=/etc/zippo/config.yaml
2728
volumeMounts:
2829
- name: zippo-etc
2930
mountPath: /etc/zippo
31+
- name: zippo-etc-template
32+
mountPath: /etc/zippo/templates
3033
volumes:
3134
- name: zippo-etc
35+
emptyDir: {}
36+
- name: zippo-etc-template
3237
configMap:
3338
name: zippo-config
3439
items:
35-
- key: config
36-
- path: config.yaml
40+
- key: zippo.tmpl
41+
path: zippo.tmpl
42+
3743

main.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
zippo "github.com/jan0ski/zippo/pkg"
88
log "github.com/sirupsen/logrus"
9+
"golang.org/x/mod/semver"
910
)
1011

1112
var (
@@ -16,16 +17,18 @@ var (
1617
k8sVersion string
1718
cniVersion string
1819
templatePath string
20+
configPath string
1921
)
2022

2123
func init() {
2224
flag.StringVar(&listenAddr, "address", "0.0.0.0", "listen address of the server")
23-
flag.IntVar(&listenPort, "port", 8080, "key to add to `authorized_hosts` for ssh access")
25+
flag.IntVar(&listenPort, "port", 8080, "listen port of the server")
2426
flag.StringVar(&sshUser, "ssh-user", "core", "initial user available via ssh")
2527
flag.StringVar(&sshPubkey, "ssh-pubkey", "", "key to add to `authorized_hosts` for ssh access")
26-
flag.StringVar(&k8sVersion, "k8s", "v1.20.14", "Kubernetes version to install")
27-
flag.StringVar(&cniVersion, "cni-version", "v0.8.2", "CNI version to install")
28-
flag.StringVar(&templatePath, "template", "/etc/zippo/config.tmpl", "path to Butane template")
28+
flag.StringVar(&k8sVersion, "k8s-version", "v1.23.0", "Kubernetes version to install")
29+
flag.StringVar(&cniVersion, "cni-version", "v1.0.0", "CNI version to install")
30+
flag.StringVar(&templatePath, "template", "/etc/zippo/templates/config.tmpl", "path to Butane template to render")
31+
flag.StringVar(&configPath, "config", "/etc/zippo/config.yaml", "path to place rendered config")
2932
flag.Parse()
3033
}
3134

@@ -42,16 +45,16 @@ type args struct {
4245
func main() {
4346
// Don't set `Hostname`, it's populated from the host header
4447
args := args{
45-
Hostname: "{{ .Hostname }}",
46-
SSHUser: sshUser,
47-
SSHPubkey: sshPubkey,
48-
K8sVersion: k8sVersion,
49-
CRICtlVersion: k8sVersion,
48+
Hostname: "{{ .Hostname }}",
49+
SSHUser: sshUser,
50+
SSHPubkey: sshPubkey,
51+
K8sVersion: k8sVersion,
52+
// CRICTL only has major/minor releases
53+
CRICtlVersion: semver.MajorMinor(k8sVersion) + ".0",
5054
CNIVersion: cniVersion,
5155
}
5256

5357
// populate config file with rendered template
54-
configPath := "/etc/zippo/config.yaml"
5558
template, err := zippo.Render(templatePath, args)
5659
if err != nil {
5760
log.Fatalf(err.Error())

0 commit comments

Comments
 (0)