From f833e22ef34fabe0dc54b2fdbf9ab2fd8a029376 Mon Sep 17 00:00:00 2001
From: Janne Mareike Koschinski <janne@kuschku.de>
Date: Tue, 3 Jan 2023 01:22:03 +0100
Subject: [PATCH] fix: correct issues with k8s install

---
 config/kubernetes.bu        | 36 +++++++++++++++---------------------
 config/kubernetes/repo.conf |  4 ++--
 2 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/config/kubernetes.bu b/config/kubernetes.bu
index 93a651a..9542823 100644
--- a/config/kubernetes.bu
+++ b/config/kubernetes.bu
@@ -33,42 +33,35 @@ storage:
       contents:
         inline: |-
           export KUBECONFIG=/etc/kubernetes/admin.conf
-    - path: /usr/local/bin/cilium
-      mode: 0755
-      contents:
-        source: https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz
-        compression: gzip
 systemd:
   units:
     - name: kubernetes-install.service
       enabled: true
       contents: |
         [Unit]
-        Description=Install Overlay Packages
-        Requires=NetworkManager-wait-online.service
-        Requires=zincati.service
-        After=NetworkManager-wait-online.service
-        After=zincati.service
-        Before=multi-user.target
-
+        Description=Kubernetes Install
+        Wants=network-online.target
+        After=network-online.target
+        # We run before `zincati.service` to avoid conflicting rpm-ostree transactions.
+        Before=zincati.service
+        ConditionPathExists=!/var/lib/%N.stamp
         [Service]
         Type=oneshot
         RemainAfterExit=yes
-        ExecStart=rpm-ostree install kubelet kubeadm kubectl helm cri-o --idempotent --reboot
-
+        ExecStart=/bin/sh -c "curl -L https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz | tar xzf - -C /usr/local/bin/"
+        ExecStart=/usr/bin/rpm-ostree install --apply-live --allow-inactive kubelet kubeadm kubectl helm cri-o
+        ExecStart=/bin/touch /var/lib/%N.stamp
         [Install]
-        RequiredBy=multi-user.target
         WantedBy=multi-user.target
     - name: kubernetes-init.service
-      enabled: true
       contents: |
         [Unit]
         Description=Initialize Kubernetes Cluster
-        Requires=NetworkManager-wait-online.service
-        Requires=kubernetes-install.service
-        After=NetworkManager-wait-online.service
-        After=kubernetes-install.service
-        Before=multi-user.target
+        Wants=network-online.target
+        Wants=kubernetes-install.target
+        After=network-online.target
+        After=kubernetes-install.target
+        ConditionPathExists=!/var/lib/%N.stamp
 
         [Service]
         Type=oneshot
@@ -90,5 +83,6 @@ systemd:
             --set hubble.relay.enabled=true \
             --set hubble.ui.enabled=true \
             --set kubeProxyReplacement=disabled
+        ExecStartPost=/bin/touch /var/lib/%N.stamp
         [Install]
         WantedBy=multi-user.target
\ No newline at end of file
diff --git a/config/kubernetes/repo.conf b/config/kubernetes/repo.conf
index 65eda50..9d12c2a 100644
--- a/config/kubernetes/repo.conf
+++ b/config/kubernetes/repo.conf
@@ -3,5 +3,5 @@ name=Kubernetes
 baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
 enabled=1
 gpgcheck=1
-repo_gpgcheck=1
-gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
+gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
+#exclude=kubelet kubeadm kubectl
-- 
GitLab