Skip to content

Commit

Permalink
feat(kubevip): static pod support (#520)
Browse files Browse the repository at this point in the history
Closes kairos-io/kairos#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>
  • Loading branch information
tyzbit authored Jan 24, 2024
1 parent 05d3833 commit 40e8666
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 15 additions & 6 deletions internal/role/p2p/kubevip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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())
}
Expand Down

0 comments on commit 40e8666

Please sign in to comment.