From c1e3231848ddda5cb8202b10a1edf84a2bae7615 Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Tue, 25 Oct 2022 16:36:03 +0200 Subject: [PATCH] Preinstall kubelet systemd unit in OS images (#365) --- .../internal/kubernetes/k8sapi/constants.go | 17 +++---- .../internal/kubernetes/k8sapi/k8sutil.go | 15 +------ image/mkosi.finalize | 7 --- .../system-preset/30-constellation.preset | 5 ++- .../usr/lib/systemd/system/kubelet.service | 21 +++++++++ internal/versions/versions.go | 44 ++++++++----------- 6 files changed, 51 insertions(+), 58 deletions(-) create mode 100644 image/mkosi.skeleton/usr/lib/systemd/system/kubelet.service diff --git a/bootstrapper/internal/kubernetes/k8sapi/constants.go b/bootstrapper/internal/kubernetes/k8sapi/constants.go index 41ad876dc..f4b016034 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/constants.go +++ b/bootstrapper/internal/kubernetes/k8sapi/constants.go @@ -8,14 +8,11 @@ package k8sapi const ( // Paths and permissions necessary for Kubernetes installation. - cniPluginsDir = "/opt/cni/bin" - binDir = "/run/state/bin" - kubeadmPath = "/run/state/bin/kubeadm" - kubeletPath = "/run/state/bin/kubelet" - kubeletServiceEtcPath = "/run/systemd/system/kubelet.service" - kubeletServiceStatePath = "/run/state/systemd/system/kubelet.service" - kubeadmConfEtcPath = "/run/systemd/system/kubelet.service.d/10-kubeadm.conf" - kubeadmConfStatePath = "/run/state/systemd/system/kubelet.service.d/10-kubeadm.conf" - executablePerm = 0o544 - systemdUnitPerm = 0o644 + cniPluginsDir = "/opt/cni/bin" + binDir = "/run/state/bin" + kubeadmPath = "/run/state/bin/kubeadm" + kubeletPath = "/run/state/bin/kubelet" + kubeletServicePath = "/usr/lib/systemd/system/kubelet.service" + executablePerm = 0o544 + systemdUnitPerm = 0o644 ) diff --git a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go index eaab4794d..854b80fa2 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go +++ b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go @@ -34,7 +34,6 @@ import ( "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/versions" - "github.com/icholy/replace" "github.com/spf13/afero" "go.uber.org/zap" "golang.org/x/text/transform" @@ -93,16 +92,6 @@ func (k *KubernetesUtil) InstallComponents(ctx context.Context, version versions ); err != nil { return fmt.Errorf("installing crictl: %w", err) } - if err := k.inst.Install( - ctx, versionConf.KubeletServiceURL, []string{kubeletServiceEtcPath, kubeletServiceStatePath}, systemdUnitPerm, false, replace.String("/usr/bin", binDir), - ); err != nil { - return fmt.Errorf("installing kubelet service: %w", err) - } - if err := k.inst.Install( - ctx, versionConf.KubeadmConfURL, []string{kubeadmConfEtcPath, kubeadmConfStatePath}, systemdUnitPerm, false, replace.String("/usr/bin", binDir), - ); err != nil { - return fmt.Errorf("installing kubeadm conf: %w", err) - } if err := k.inst.Install( ctx, versionConf.KubeletURL, []string{kubeletPath}, executablePerm, false, ); err != nil { @@ -119,7 +108,7 @@ func (k *KubernetesUtil) InstallComponents(ctx context.Context, version versions return fmt.Errorf("installing kubectl: %w", err) } - return enableSystemdUnit(ctx, kubeletServiceEtcPath) + return enableSystemdUnit(ctx, kubeletServicePath) } func (k *KubernetesUtil) InitCluster( @@ -434,7 +423,7 @@ func (k *KubernetesUtil) JoinCluster(ctx context.Context, joinConfig []byte, pee func (k *KubernetesUtil) StartKubelet() error { ctx, cancel := context.WithTimeout(context.TODO(), kubeletStartTimeout) defer cancel() - if err := enableSystemdUnit(ctx, kubeletServiceEtcPath); err != nil { + if err := enableSystemdUnit(ctx, kubeletServicePath); err != nil { return fmt.Errorf("enabling kubelet systemd unit: %w", err) } return startSystemdUnit(ctx, "kubelet.service") diff --git a/image/mkosi.finalize b/image/mkosi.finalize index 643f343f5..77b1066d4 100755 --- a/image/mkosi.finalize +++ b/image/mkosi.finalize @@ -5,12 +5,5 @@ set -euxo pipefail -# recreate kubelet systemd unit after reboot. -# tmpfile config has to be written late as it interferes with the systemd-nspawn build environment -cat >"${BUILDROOT}/usr/lib/tmpfiles.d/kubelet-service.conf" <