Skip to content

Commit

Permalink
Rework manifest install logic (#523)
Browse files Browse the repository at this point in the history
* rework manifest install logic

* feedback and changes
  • Loading branch information
dbw7 authored Aug 14, 2024
1 parent 258f120 commit fa484c8
Show file tree
Hide file tree
Showing 5 changed files with 102 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
26 changes: 25 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,10 +38,33 @@ 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
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 [[ "$output" != *"AlreadyExists"* ]]; then
failed=true
fi
fi
echo "$output"
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
Requires=k3s.service
PartOf=k3s.service
After=k3s.service
ConditionPathExists=/opt/bin/kubectl
ConditionPathExists=/etc/rancher/k3s/k3s.yaml
Expand All @@ -53,7 +76,8 @@ 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
ExecStartPre=/bin/sh -c 'until systemctl is-active --quiet k3s.service; do sleep 10; done'
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
26 changes: 25 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,10 +12,33 @@ umount /var
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
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 [[ "$output" != *"AlreadyExists"* ]]; then
failed=true
fi
fi
echo "$output"
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
Requires=k3s.service
PartOf=k3s.service
After=k3s.service
ConditionPathExists=/opt/bin/kubectl
ConditionPathExists=/etc/rancher/k3s/k3s.yaml
Expand All @@ -27,7 +50,8 @@ 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
ExecStartPre=/bin/sh -c 'until systemctl is-active --quiet k3s.service; do sleep 10; done'
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
26 changes: 25 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,10 +38,33 @@ 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
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 [[ "$output" != *"AlreadyExists"* ]]; then
failed=true
fi
fi
echo "$output"
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
Requires=rke2-server.service
PartOf=rke2-server.service
After=rke2-server.service
ConditionPathExists=/var/lib/rancher/rke2/bin/kubectl
ConditionPathExists=/etc/rancher/rke2/rke2.yaml
Expand All @@ -54,8 +77,9 @@ Type=oneshot
Restart=on-failure
RestartSec=60
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=/bin/sh -c 'until systemctl is-active --quiet rke2-server.service; do sleep 10; done'
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
26 changes: 25 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,10 +12,33 @@ umount /var
mkdir -p /opt/eib-k8s/manifests
cp {{ .manifestsPath }}/* /opt/eib-k8s/manifests/

cat <<- 'EOF' > /opt/eib-k8s/create_manifests.sh
#!/bin/bash
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 [[ "$output" != *"AlreadyExists"* ]]; then
failed=true
fi
fi
echo "$output"
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
Requires=rke2-server.service
PartOf=rke2-server.service
After=rke2-server.service
ConditionPathExists=/var/lib/rancher/rke2/bin/kubectl
ConditionPathExists=/etc/rancher/rke2/rke2.yaml
Expand All @@ -28,8 +51,9 @@ Type=oneshot
Restart=on-failure
RestartSec=60
# Copy kubectl in order to avoid SELinux permission issues
ExecStartPre=/bin/sh -c 'until systemctl is-active --quiet rke2-server.service; do sleep 10; done'
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 fa484c8

Please sign in to comment.