Skip to content

Commit

Permalink
rework manifest install logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Aug 9, 2024
1 parent d091334 commit e5e9412
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Bug Fixes

* [#491](https://github.com/suse-edge/edge-image-builder/issues/491) - Large Helm manifests fail to install

---

# v1.1.0-rc1
Expand Down
24 changes: 23 additions & 1 deletion pkg/combustion/templates/k3s-multi-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ CONFIGFILE={{ .configFilePath }}/{{ .initialiserConfigFile }}
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
set -x
failed=false
for file in /opt/eib-k8s/manifests/*; do
output=$(/opt/bin/kubectl create -f "$file" --kubeconfig=/etc/rancher/k3s/k3s.yaml 2>&1)
if [ $? != 0 ]; then
if ! echo "$output" | grep -q "AlreadyExists"; then
failed=true
fi
fi
done
if [ $failed = "true" ]; then
exit 1
fi
EOF

chmod +x /opt/eib-k8s/create_manifests.sh

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Expand All @@ -53,7 +75,7 @@ WantedBy=multi-user.target
Type=oneshot
Restart=on-failure
RestartSec=60
ExecStart=/opt/bin/kubectl apply -f /opt/eib-k8s/manifests --kubeconfig=/etc/rancher/k3s/k3s.yaml
ExecStart=/opt/eib-k8s/create_manifests.sh
# 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
Expand Down
24 changes: 23 additions & 1 deletion pkg/combustion/templates/k3s-single-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ umount /var
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
set -x
failed=false
for file in /opt/eib-k8s/manifests/*; do
output=$(/opt/bin/kubectl create -f "$file" --kubeconfig=/etc/rancher/k3s/k3s.yaml 2>&1)
if [ $? != 0 ]; then
if ! echo "$output" | grep -q "AlreadyExists"; then
failed=true
fi
fi
done
if [ $failed = "true" ]; then
exit 1
fi
EOF

chmod +x /opt/eib-k8s/create_manifests.sh

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Expand All @@ -27,7 +49,7 @@ WantedBy=multi-user.target
Type=oneshot
Restart=on-failure
RestartSec=60
ExecStart=/opt/bin/kubectl apply -f /opt/eib-k8s/manifests --kubeconfig=/etc/rancher/k3s/k3s.yaml
ExecStart=/opt/eib-k8s/create_manifests.sh
# 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
Expand Down
24 changes: 23 additions & 1 deletion pkg/combustion/templates/rke2-multi-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ CONFIGFILE={{ .configFilePath }}/{{ .initialiserConfigFile }}
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
set -x
failed=false
for file in /opt/eib-k8s/manifests/*; do
output=$(/opt/eib-k8s/kubectl create -f "$file" --kubeconfig /etc/rancher/rke2/rke2.yaml 2>&1)
if [ $? != 0 ]; then
if ! echo "$output" | grep -q "AlreadyExists"; then
failed=true
fi
fi
done
if [ $failed = "true" ]; then
exit 1
fi
EOF

chmod +x /opt/eib-k8s/create_manifests.sh

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Expand All @@ -55,7 +77,7 @@ Restart=on-failure
RestartSec=60
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=cp /var/lib/rancher/rke2/bin/kubectl /opt/eib-k8s/kubectl
ExecStart=/opt/eib-k8s/kubectl apply -f /opt/eib-k8s/manifests --kubeconfig /etc/rancher/rke2/rke2.yaml
ExecStart=/opt/eib-k8s/create_manifests.sh
# 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
Expand Down
24 changes: 23 additions & 1 deletion pkg/combustion/templates/rke2-single-node-installer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ umount /var
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
set -x
failed=false
for file in /opt/eib-k8s/manifests/*; do
output=$(/opt/eib-k8s/kubectl create -f "$file" --kubeconfig /etc/rancher/rke2/rke2.yaml 2>&1)
if [ $? != 0 ]; then
if ! echo "$output" | grep -q "AlreadyExists"; then
failed=true
fi
fi
done
if [ $failed = "true" ]; then
exit 1
fi
EOF

chmod +x /opt/eib-k8s/create_manifests.sh

cat <<- EOF > /etc/systemd/system/kubernetes-resources-install.service
[Unit]
Description=Kubernetes Resources Install
Expand All @@ -29,7 +51,7 @@ Restart=on-failure
RestartSec=60
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=cp /var/lib/rancher/rke2/bin/kubectl /opt/eib-k8s/kubectl
ExecStart=/opt/eib-k8s/kubectl apply -f /opt/eib-k8s/manifests --kubeconfig /etc/rancher/rke2/rke2.yaml
ExecStart=/opt/eib-k8s/create_manifests.sh
# 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
Expand Down

0 comments on commit e5e9412

Please sign in to comment.