Skip to content

Commit

Permalink
Apply manifests in RKE2 templates
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov committed Jun 27, 2024
1 parent f61411d commit 62b6bd6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/combustion/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ func TestConfigureKubernetes_SuccessfulRKE2ServerWithManifests(t *testing.T) {
assert.Contains(t, contents, "export INSTALL_RKE2_ARTIFACT_PATH=$ARTEFACTS_DIR/kubernetes/install")
assert.Contains(t, contents, "sh $ARTEFACTS_DIR/kubernetes/install-k8s.sh")
assert.Contains(t, contents, "systemctl enable rke2-server.service")
assert.Contains(t, contents, "mkdir -p /var/lib/rancher/rke2/server/manifests/")
assert.Contains(t, contents, "cp $ARTEFACTS_DIR/kubernetes/manifests/* /var/lib/rancher/rke2/server/manifests/")
assert.Contains(t, contents, "mkdir -p /opt/k8s/manifests")
assert.Contains(t, contents, "cp $ARTEFACTS_DIR/kubernetes/manifests/* /opt/k8s/manifests/")
assert.Contains(t, contents, "cp $ARTEFACTS_DIR/kubernetes/registries.yaml /etc/rancher/rke2/registries.yaml")

// Config file assertions
Expand Down
34 changes: 30 additions & 4 deletions pkg/combustion/templates/rke2-multi-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,45 @@ mount /var
mkdir -p /var/lib/rancher/rke2/agent/images/
cp {{ .imagesPath }}/* /var/lib/rancher/rke2/agent/images/

umount /var

CONFIGFILE={{ .configFilePath }}/$NODETYPE.yaml

if [ "$HOSTNAME" = {{ .initialiser }} ]; then
CONFIGFILE={{ .configFilePath }}/{{ .initialiserConfigFile }}

{{- if .manifestsPath }}
mkdir -p /var/lib/rancher/rke2/server/manifests/
cp {{ .manifestsPath }}/* /var/lib/rancher/rke2/server/manifests/
mkdir -p /opt/k8s/manifests
cp {{ .manifestsPath }}/* /opt/k8s/manifests/

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Requires=rke2-server.service
After=rke2-server.service
ConditionPathExists=/var/lib/rancher/rke2/bin/kubectl
ConditionPathExists=/etc/rancher/rke2/rke2.yaml
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
Restart=on-failure
RestartSec=30
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=cp /var/lib/rancher/rke2/bin/kubectl /opt/k8s/kubectl
ExecStart=/opt/k8s/kubectl apply -f /opt/k8s/manifests --kubeconfig /etc/rancher/rke2/rke2.yaml
# Disable the service and clean up
ExecStartPost=/bin/sh -c "systemctl disable kubernetes-resources-install.service"
ExecStartPost=rm -f /etc/systemd/system/kubernetes-resources-install.service
ExecStartPost=rm -rf /opt/k8s
EOF
systemctl enable kubernetes-resources-install.service
{{- end }}
fi
umount /var

{{- if .apiHost }}
echo "{{ .apiVIP }} {{ .apiHost }}" >> /etc/hosts
{{- end }}
Expand Down
34 changes: 30 additions & 4 deletions pkg/combustion/templates/rke2-single-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,39 @@ mount /var
mkdir -p /var/lib/rancher/rke2/agent/images/
cp {{ .imagesPath }}/* /var/lib/rancher/rke2/agent/images/

umount /var

{{- if .manifestsPath }}
mkdir -p /var/lib/rancher/rke2/server/manifests/
cp {{ .manifestsPath }}/* /var/lib/rancher/rke2/server/manifests/
mkdir -p /opt/k8s/manifests
cp {{ .manifestsPath }}/* /opt/k8s/manifests/

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Requires=rke2-server.service
After=rke2-server.service
ConditionPathExists=/var/lib/rancher/rke2/bin/kubectl
ConditionPathExists=/etc/rancher/rke2/rke2.yaml
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
Restart=on-failure
RestartSec=30
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=cp /var/lib/rancher/rke2/bin/kubectl /opt/k8s/kubectl
ExecStart=/opt/k8s/kubectl apply -f /opt/k8s/manifests --kubeconfig /etc/rancher/rke2/rke2.yaml
# Disable the service and clean up
ExecStartPost=/bin/sh -c "systemctl disable kubernetes-resources-install.service"
ExecStartPost=rm -f /etc/systemd/system/kubernetes-resources-install.service
ExecStartPost=rm -rf /opt/k8s
EOF

systemctl enable kubernetes-resources-install.service
{{- end }}

umount /var

{{- if and .apiVIP .apiHost }}
echo "{{ .apiVIP }} {{ .apiHost }}" >> /etc/hosts
{{- end }}
Expand Down

0 comments on commit 62b6bd6

Please sign in to comment.