mirror of
https://github.com/kairos-io/provider-kairos.git
synced 2025-09-23 12:07:03 +00:00
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>
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user