Skip to content

Commit

Permalink
k3s: fix persistence of kubernetes config (#505)
Browse files Browse the repository at this point in the history
* app: persist the kubernetes config

* k3s: disable trafefik by defaults

* Revert "k3s: disable trafefik by defaults"

This reverts commit 9c20e4a.
  • Loading branch information
hftsin authored Dec 14, 2022
1 parent 86de81a commit 77a42c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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
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

0 comments on commit 77a42c6

Please sign in to comment.