From 40e86664507a6b9841f5aa3ac0d10d5eb0abc3a0 Mon Sep 17 00:00:00 2001 From: tyzbit <3319104+tyzbit@users.noreply.github.com> Date: Wed, 24 Jan 2024 03:35:24 -0500 Subject: [PATCH] feat(kubevip): static pod support (#520) Closes https://github.com/kairos-io/kairos/issues/1993 To use: ``` kubevip: static_pod: true ``` I'm still getting my build environment set up so unfortunately I can't test this functionality myself but the change should be straightforward. Please review with this in mind, I definitely could have missed something. Signed-off-by: Tyler Hawkins <3319104+tyzbit@users.noreply.github.com> --- internal/provider/config/config.go | 1 + internal/role/p2p/kubevip.go | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/provider/config/config.go b/internal/provider/config/config.go index 0a3de2af..5986adfd 100644 --- a/internal/provider/config/config.go +++ b/internal/provider/config/config.go @@ -45,6 +45,7 @@ type KubeVIP struct { ManifestURL string `yaml:"manifest_url,omitempty"` Interface string `yaml:"interface,omitempty"` Enable *bool `yaml:"enable,omitempty"` + StaticPod bool `yaml:"static_pod,omitempty"` } func (k KubeVIP) IsEnabled() bool { diff --git a/internal/role/p2p/kubevip.go b/internal/role/p2p/kubevip.go index afa95875..02a9846e 100644 --- a/internal/role/p2p/kubevip.go +++ b/internal/role/p2p/kubevip.go @@ -12,8 +12,8 @@ import ( providerConfig "github.com/kairos-io/provider-kairos/v2/internal/provider/config" ) -func generateKubeVIP(iface, ip string, args []string) (string, error) { - out, err := utils.SH(fmt.Sprintf("kube-vip manifest daemonset --interface %s --address %s --inCluster --taint --controlplane --arp --leaderElection %s", iface, ip, strings.Join(args, " "))) +func generateKubeVIP(command string, iface, ip string, args []string) (string, error) { + out, err := utils.SH(fmt.Sprintf("kube-vip manifest %s --interface %s --address %s --inCluster --taint --controlplane --arp --leaderElection %s", command, iface, ip, strings.Join(args, " "))) if err != nil { return "", fmt.Errorf("error: %w - %s", err, out) @@ -41,12 +41,21 @@ func downloadFromURL(url, where string) error { } func deployKubeVIP(iface, ip string, pconfig *providerConfig.Config) error { - if err := os.MkdirAll("/var/lib/rancher/k3s/server/manifests/", 0650); err != nil { + manifestDirectory := "/var/lib/rancher/k3s/server/manifests/" + if pconfig.K3sAgent.Enabled { + manifestDirectory = "/var/lib/rancher/k3s/agent/pod-manifests/" + } + if err := os.MkdirAll(manifestDirectory, 0650); err != nil { return fmt.Errorf("could not create manifest dir") } - targetFile := "/var/lib/rancher/k3s/server/manifests/kubevip.yaml" - targetCRDFile := "/var/lib/rancher/k3s/server/manifests/kubevipmanifest.yaml" + targetFile := manifestDirectory + "kubevip.yaml" + targetCRDFile := manifestDirectory + "kubevipmanifest.yaml" + + command := "daemonset" + if pconfig.KubeVIP.StaticPod { + command = "pod" + } if pconfig.KubeVIP.ManifestURL != "" { err := downloadFromURL(pconfig.KubeVIP.ManifestURL, targetCRDFile) @@ -71,7 +80,7 @@ func deployKubeVIP(iface, ip string, pconfig *providerConfig.Config) error { } } - content, err := generateKubeVIP(iface, ip, pconfig.KubeVIP.Args) + content, err := generateKubeVIP(command, iface, ip, pconfig.KubeVIP.Args) if err != nil { return fmt.Errorf("could not generate kubevip %s", err.Error()) }