From b9a1a9ae5e761b795f44d186a1a386c10fdcd8dc Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Thu, 22 Dec 2022 12:34:28 +0100 Subject: [PATCH] image: set runtime-endpoint in crictl config (#821) Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- bootstrapper/internal/kubernetes/k8sapi/k8sutil.go | 12 +++++++----- image/mkosi.skeleton/etc/crictl.yaml | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 image/mkosi.skeleton/etc/crictl.yaml diff --git a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go index 8d3cebdb8..5be769fc3 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go +++ b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go @@ -244,11 +244,13 @@ type SetupPodNetworkInput struct { // FixCilium fixes https://github.com/cilium/cilium/issues/19958 but instead of a rollout restart of // the cilium daemonset, it only restarts the local cilium pod. func (k *KubernetesUtil) FixCilium(log *logger.Logger) { + ctx := context.Background() + // wait for cilium pod to be healthy client := http.Client{} for { time.Sleep(5 * time.Second) - req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://127.0.0.1:9879/healthz", http.NoBody) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1:9879/healthz", http.NoBody) if err != nil { log.With(zap.Error(err)).Errorf("Unable to create request") continue @@ -265,7 +267,7 @@ func (k *KubernetesUtil) FixCilium(log *logger.Logger) { } // get cilium container id - out, err := exec.CommandContext(context.Background(), "/run/state/bin/crictl", "ps", "--name", "cilium-agent", "-q").CombinedOutput() + out, err := exec.CommandContext(ctx, "/run/state/bin/crictl", "ps", "--name", "cilium-agent", "-q").CombinedOutput() if err != nil { log.With(zap.Error(err)).Errorf("Getting cilium container id failed: %s", out) return @@ -278,7 +280,7 @@ func (k *KubernetesUtil) FixCilium(log *logger.Logger) { containerID := outLines[len(outLines)-2] // get cilium pod id - out, err = exec.CommandContext(context.Background(), "/run/state/bin/crictl", "inspect", "-o", "go-template", "--template", "{{ .info.sandboxID }}", containerID).CombinedOutput() + out, err = exec.CommandContext(ctx, "/run/state/bin/crictl", "inspect", "-o", "go-template", "--template", "{{ .info.sandboxID }}", containerID).CombinedOutput() if err != nil { log.With(zap.Error(err)).Errorf("Getting cilium pod id failed: %s", out) return @@ -291,12 +293,12 @@ func (k *KubernetesUtil) FixCilium(log *logger.Logger) { podID := outLines[len(outLines)-2] // stop and delete pod - out, err = exec.CommandContext(context.Background(), "/run/state/bin/crictl", "stopp", podID).CombinedOutput() + out, err = exec.CommandContext(ctx, "/run/state/bin/crictl", "stopp", podID).CombinedOutput() if err != nil { log.With(zap.Error(err)).Errorf("Stopping cilium agent pod failed: %s", out) return } - out, err = exec.CommandContext(context.Background(), "/run/state/bin/crictl", "rmp", podID).CombinedOutput() + out, err = exec.CommandContext(ctx, "/run/state/bin/crictl", "rmp", podID).CombinedOutput() if err != nil { log.With(zap.Error(err)).Errorf("Removing cilium agent pod failed: %s", out) } diff --git a/image/mkosi.skeleton/etc/crictl.yaml b/image/mkosi.skeleton/etc/crictl.yaml new file mode 100644 index 000000000..3e588cd39 --- /dev/null +++ b/image/mkosi.skeleton/etc/crictl.yaml @@ -0,0 +1 @@ +runtime-endpoint: "unix:///run/containerd/containerd.sock"