Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: persist kubernetes config #505

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -116,6 +117,11 @@ func (c colimaApp) Start(conf config.Config) error {
log.Error(fmt.Errorf("error persisting runtime settings: %w", err))
}

// persist the kubernetes config
if err := c.setKubernetes(conf.Kubernetes); err != nil {
log.Error(fmt.Errorf("error persisting kubernetes settings: %w", err))
}

log.Println("done")

if err := generateSSHConfig(conf.SSHConfig); err != nil {
Expand Down Expand Up @@ -390,6 +396,15 @@ func (c colimaApp) setRuntime(runtime string) error {
return c.guest.Set(environment.ContainerRuntimeKey, runtime)
}

func (c colimaApp) setKubernetes(conf config.Kubernetes) error {
b, err := json.Marshal(conf)
if err != nil {
return err
}

return c.guest.Set(kubernetes.ConfigKey, string(b))
}

func (c colimaApp) currentContainerEnvironments(ctx context.Context) ([]environment.Container, error) {
var containers []environment.Container

Expand Down
3 changes: 3 additions & 0 deletions environment/container/kubernetes/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func installK3sCluster(
"--resolv-conf", "/etc/resolv.conf",
}

// disable traefik defaults
args = append(args, "--disable", "traefik")

for _, d := range disable {
args = append(args, "--disable", d)
}
Expand Down
6 changes: 3 additions & 3 deletions environment/container/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
Name = "kubernetes"
DefaultVersion = "v1.25.4+k3s1"

configKey = "kubernetes_config"
ConfigKey = "kubernetes_config"
)

func newRuntime(host environment.HostActions, guest environment.GuestActions) environment.Container {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c kubernetesRuntime) runtime() string {

func (c kubernetesRuntime) config() config.Kubernetes {
conf := config.Kubernetes{Version: DefaultVersion}
if b := c.guest.Get(configKey); b != "" {
if b := c.guest.Get(ConfigKey); b != "" {
_ = json.Unmarshal([]byte(b), &conf)
}
return conf
Expand All @@ -83,7 +83,7 @@ func (c kubernetesRuntime) setConfig(conf config.Kubernetes) error {
return fmt.Errorf("error encoding kubernetes config to json: %w", err)
}

return c.guest.Set(configKey, string(b))
return c.guest.Set(ConfigKey, string(b))
}

func (c *kubernetesRuntime) Provision(ctx context.Context) error {
Expand Down