Skip to content

Commit

Permalink
Apply manifests in k3s 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 a8d81ac commit f61411d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
32 changes: 28 additions & 4 deletions pkg/combustion/templates/k3s-multi-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,43 @@ mount /var
mkdir -p /var/lib/rancher/k3s/agent/images/
cp {{ .imagesPath }}/* /var/lib/rancher/k3s/agent/images/

umount /var

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

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

{{- if .manifestsPath }}
mkdir -p /var/lib/rancher/k3s/server/manifests/
cp {{ .manifestsPath }}/* /var/lib/rancher/k3s/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=k3s.service
After=k3s.service
ConditionPathExists=/opt/bin/kubectl
ConditionPathExists=/etc/rancher/k3s/k3s.yaml
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
Restart=on-failure
RestartSec=30
ExecStart=/opt/bin/kubectl apply -f /opt/k8s/manifests --kubeconfig=/etc/rancher/k3s/k3s.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 and .apiVIP .apiHost }}
echo "{{ .apiVIP }} {{ .apiHost }}" >> /etc/hosts
{{- end }}
Expand Down
32 changes: 28 additions & 4 deletions pkg/combustion/templates/k3s-single-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ mount /var
mkdir -p /var/lib/rancher/k3s/agent/images/
cp {{ .imagesPath }}/* /var/lib/rancher/k3s/agent/images/

umount /var

{{- if .manifestsPath }}
mkdir -p /var/lib/rancher/k3s/server/manifests/
cp {{ .manifestsPath }}/* /var/lib/rancher/k3s/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=k3s.service
After=k3s.service
ConditionPathExists=/opt/bin/kubectl
ConditionPathExists=/etc/rancher/k3s/k3s.yaml
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
Restart=on-failure
RestartSec=30
ExecStart=/opt/bin/kubectl apply -f /opt/k8s/manifests --kubeconfig=/etc/rancher/k3s/k3s.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 f61411d

Please sign in to comment.