Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7cd75c1
feat: add create k0s setup from config.yaml
OliverTrautvetter Dec 10, 2025
cdd6ee8
Merge branch 'main' into deploy_k0s_install-config
OliverTrautvetter Dec 10, 2025
5a907ab
chore(docs): Auto-update docs and licenses
OliverTrautvetter Dec 10, 2025
3035990
ref: use deferred functions for cleanup in k0s and node installers
OliverTrautvetter Dec 10, 2025
8892ce0
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Dec 10, 2025
ad86e8e
chore(docs): Auto-update docs and licenses
OliverTrautvetter Dec 10, 2025
c79fc3d
ref: refactor install-config integration tests for improved clarity a…
OliverTrautvetter Dec 15, 2025
071eea9
ref: cleanup
OliverTrautvetter Dec 16, 2025
9de5965
chore(docs): Auto-update docs and licenses
OliverTrautvetter Dec 16, 2025
01d6750
Update internal/installer/node/node.go
OliverTrautvetter Dec 16, 2025
b19ac3b
ref: enhance shell command safety
OliverTrautvetter Dec 16, 2025
41e61da
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Dec 16, 2025
d4d1b5f
test: add tests for NodeManager and Node methods
OliverTrautvetter Dec 16, 2025
97bb3b8
fix: improve passphrase handling in getAuthMethods
OliverTrautvetter Dec 16, 2025
b07c0a8
fix: enforce required flags for remote installation and clean up test…
OliverTrautvetter Dec 16, 2025
8f56476
fix: update EnsureDirectoryExists to accept jumpbox IP
OliverTrautvetter Dec 16, 2025
f674352
test: add tests for InstallK0sCmd
OliverTrautvetter Dec 16, 2025
4e61092
fix: correct sed command syntax for enabling root login
OliverTrautvetter Dec 16, 2025
7a407f0
test: add mock expectations for SSH key file reading in InstallK0sCmd…
OliverTrautvetter Dec 16, 2025
52e8667
test: add tests for K0s configuration filtering
OliverTrautvetter Dec 16, 2025
ef0f96c
test: add tests for Reset functionality in K0s
OliverTrautvetter Dec 16, 2025
4b49bd6
test: add tests for SSH key file handling in InstallK0sRemote method
OliverTrautvetter Dec 16, 2025
e3a9e18
fix: fix k0s installation path and config handling
OliverTrautvetter Dec 17, 2025
e2192fe
fix: k0s config handling to support temporary paths in tests
OliverTrautvetter Dec 17, 2025
bb39c0e
feat: enhance remote k0s installation with user support and SSH instr…
OliverTrautvetter Dec 17, 2025
fdcb214
ref: minor
OliverTrautvetter Dec 17, 2025
2f6fa29
fix: error message for missing install-config in RunE method
OliverTrautvetter Dec 18, 2025
2ad0251
fix: appease make lint
OliverTrautvetter Dec 18, 2025
54ae71c
Update internal/installer/node/node.go
OliverTrautvetter Dec 18, 2025
a5faa2c
fix: improve regex for enabling root login in SSH configuration
OliverTrautvetter Dec 18, 2025
d120484
Update internal/installer/node/node.go
OliverTrautvetter Dec 18, 2025
8e92d3a
fix: update SSH installation notes and remove insecure host key warning
OliverTrautvetter Dec 18, 2025
bb05e55
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Dec 18, 2025
6e80a78
refactor: standardize receiver names in NodeManager methods for consi…
OliverTrautvetter Dec 18, 2025
921e47c
fix: enhance k0s reset process by stopping service before reset and u…
OliverTrautvetter Dec 19, 2025
dfc9deb
ref: extract k0s ClusterConfig keys into constants for improved maint…
OliverTrautvetter Dec 19, 2025
a79cd1a
feat: enhance node Installation and testing
OliverTrautvetter Jan 8, 2026
82fbdbf
Merge branch 'main' into deploy_k0s_install-config
OliverTrautvetter Jan 8, 2026
590ad32
fix: merge errors
OliverTrautvetter Jan 8, 2026
88d365b
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 8, 2026
6a88ac1
fix: simplify root login check logic
OliverTrautvetter Jan 9, 2026
40b97d1
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Jan 9, 2026
f2be13a
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 9, 2026
aa4222e
ref: enhance k0s installation process and test configuration
OliverTrautvetter Jan 13, 2026
af7f8a1
Merge branch 'main' into deploy_k0s_install-config
OliverTrautvetter Jan 13, 2026
7f3d823
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 13, 2026
5da46ec
fix: enhance error handling in NodeManager client connection tests
OliverTrautvetter Jan 13, 2026
f5ba1e8
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Jan 13, 2026
d1c2417
Merge remote-tracking branch 'origin/main' into deploy_k0s_install-co…
OliverTrautvetter Jan 22, 2026
949bbed
fix: merge error
OliverTrautvetter Jan 22, 2026
8b47dfd
fix: node tests
OliverTrautvetter Jan 22, 2026
0086e60
ref: start to update k0s to k0sctl
OliverTrautvetter Jan 28, 2026
8cb0709
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 28, 2026
8da565b
Merge branch 'main' into deploy_k0s_install-config
OliverTrautvetter Jan 28, 2026
36febb9
Merge branch 'main' into deploy_k0s_install-config
OliverTrautvetter Jan 28, 2026
ffa3084
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 28, 2026
d30c117
ref: mock SSH client and enhance tests for SSH connection failures
OliverTrautvetter Jan 28, 2026
e8f73f8
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Jan 28, 2026
095c55d
chore(docs): Auto-update docs and licenses
OliverTrautvetter Jan 28, 2026
767a005
Update internal/installer/node/node.go
OliverTrautvetter Jan 28, 2026
d0d3adb
Update hack/lima-oms.yaml
OliverTrautvetter Jan 28, 2026
7c6466b
fix: update go mod
OliverTrautvetter Jan 28, 2026
205bca4
ref: simplify host address assignment in k0sctl config generation
OliverTrautvetter Jan 28, 2026
836abc7
ref: remove unused MockSSHClient and related functions
OliverTrautvetter Jan 28, 2026
41f5eac
ref: enhance host key verification to auto-accept new hosts during pr…
OliverTrautvetter Jan 28, 2026
344d3de
fix: k0s bugs
OliverTrautvetter Jan 30, 2026
4167882
ref: update k0sctl config path to use OmsWorkdir and improve error ha…
OliverTrautvetter Jan 30, 2026
456ec52
Update internal/installer/node/node.go
OliverTrautvetter Jan 30, 2026
9e5bd53
Merge remote-tracking branch 'origin/main' into deploy_k0s_install-co…
OliverTrautvetter Jan 30, 2026
8a7ffc1
ref: cleanup
OliverTrautvetter Jan 30, 2026
1d44afc
ref: enhance GetNodeIPAddress logic and simplify GenerateK0sConfig wi…
OliverTrautvetter Feb 2, 2026
c9316f7
ref: simplify k0s config
OliverTrautvetter Feb 2, 2026
a97522f
Update internal/installer/k0sctl_config.go
OliverTrautvetter Feb 2, 2026
ada6983
Update internal/installer/node/node.go
OliverTrautvetter Feb 2, 2026
9905716
ref: implement review suggestions
OliverTrautvetter Feb 2, 2026
fc90a08
fix: new tests
OliverTrautvetter Feb 2, 2026
ff7bfff
Update hack/lima-oms.yaml
OliverTrautvetter Feb 2, 2026
36f193e
ref: implement review suggestions
OliverTrautvetter Feb 2, 2026
a542892
Merge branch 'deploy_k0s_install-config' of https://github.com/codesp…
OliverTrautvetter Feb 2, 2026
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ all: build-cli build-service
build-cli:
cd cli && go build -v && mv cli ../oms-cli

build-cli-linux:
GOOS=linux GOARCH=amd64 go build -C cli -o ../oms-cli

build-service:
cd service && go build -v && mv service ../oms-service

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/bootstrap_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
return fmt.Errorf("failed to bootstrap GCP: %w, env: %s", err, envString)
}

log.Println("\n🎉🎉🎉 GCP infrastructure bootstrapped successfully!")
log.Println("\nGCP infrastructure bootstrapped successfully!")
log.Println(envString)
log.Printf("Start the Codesphere installation using OMS from the jumpbox host:\nssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s", bs.Env.Jumpbox.GetExternalIP())
log.Printf("When the installation is done, run the k0s configuration script generated at the k0s-1 host %s /root/configure-k0s.sh.", bs.Env.ControlPlaneNodes[0].GetInternalIP())
Expand Down
132 changes: 103 additions & 29 deletions cli/cmd/install_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package cmd

import (
"fmt"
"log"
"path/filepath"

packageio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/spf13/cobra"
Expand All @@ -25,24 +27,23 @@ type InstallK0sCmd struct {

type InstallK0sOpts struct {
*GlobalOptions
Version string
Package string
Config string
Force bool
Version string
K0sctlVersion string
Package string
InstallConfig string
SSHKeyPath string
Force bool
NoDownload bool
}

func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error {
hw := portal.NewHttpWrapper()
env := c.Env
pm := installer.NewPackage(env.GetOmsWorkdir(), c.Opts.Package)
k0s := installer.NewK0s(hw, env, c.FileWriter)
k0sctl := installer.NewK0sctl(hw, env, c.FileWriter)

err := c.InstallK0s(pm, k0s)
if err != nil {
return fmt.Errorf("failed to install k0s: %w", err)
}

return nil
return c.InstallK0s(pm, k0s, k0sctl)
}

func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) {
Expand All @@ -51,50 +52,123 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) {
Use: "k0s",
Short: "Install k0s Kubernetes distribution",
Long: packageio.Long(`Install k0s either from the package or by downloading it.
This will either download the k0s binary directly to the OMS workdir, if not already present, and install it
or load the k0s binary from the provided package file and install it.
If no version is specified, the latest version will be downloaded.
If no install config is provided, k0s will be installed with the '--single' flag.`),
This command uses k0sctl to deploy k0s clusters from a Codesphere install-config.

You must provide a Codesphere install-config file, which will:
- Generate a k0s configuration from the install-config
- Generate a k0sctl configuration for cluster deployment
- Deploy k0s to all nodes defined in the install-config using k0sctl`),
Example: formatExamplesWithBinary("install k0s", []packageio.Example{
{Cmd: "", Desc: "Install k0s using the Go-native implementation"},
{Cmd: "--version <version>", Desc: "Version of k0s to install"},
{Cmd: "--install-config <path>", Desc: "Path to Codesphere install-config file to generate k0s config from"},
{Cmd: "--version <version>", Desc: "Version of k0s to install (e.g., v1.30.0+k0s.0)"},
{Cmd: "--k0sctl-version <version>", Desc: "Version of k0sctl to use (e.g., v0.17.4)"},
{Cmd: "--package <file>", Desc: "Package file (e.g. codesphere-v1.2.3-installer.tar.gz) to load k0s from"},
{Cmd: "--k0s-config <path>", Desc: "Path to k0s configuration file, if not set k0s will be installed with the '--single' flag"},
{Cmd: "--force", Desc: "Force new download and installation even if k0s binary exists or is already installed"},
{Cmd: "--ssh-key-path <path>", Desc: "SSH private key path for remote installation"},
{Cmd: "--force", Desc: "Force new download and installation"},
{Cmd: "--no-download", Desc: "Skip downloading k0s binary (expects it to be on remote nodes)"},
}, "oms-cli"),
},
Opts: InstallK0sOpts{GlobalOptions: opts},
Env: env.NewEnv(),
FileWriter: util.NewFilesystemWriter(),
}
k0s.cmd.Flags().StringVarP(&k0s.Opts.Version, "version", "v", "", "Version of k0s to install")
k0s.cmd.Flags().StringVar(&k0s.Opts.K0sctlVersion, "k0sctl-version", "", "Version of k0sctl to use")
k0s.cmd.Flags().StringVarP(&k0s.Opts.Package, "package", "p", "", "Package file (e.g. codesphere-v1.2.3-installer.tar.gz) to load k0s from")
k0s.cmd.Flags().StringVar(&k0s.Opts.Config, "k0s-config", "", "Path to k0s configuration file")
k0s.cmd.Flags().StringVar(&k0s.Opts.InstallConfig, "install-config", "", "Path to Codesphere install-config file (required)")
k0s.cmd.Flags().StringVar(&k0s.Opts.SSHKeyPath, "ssh-key-path", "", "SSH private key path for remote installation")
k0s.cmd.Flags().BoolVarP(&k0s.Opts.Force, "force", "f", false, "Force new download and installation")
k0s.cmd.Flags().BoolVar(&k0s.Opts.NoDownload, "no-download", false, "Skip downloading k0s binary")

_ = k0s.cmd.MarkFlagRequired("install-config")

install.AddCommand(k0s.cmd)

k0s.cmd.RunE = k0s.RunE
}

const defaultK0sPath = "kubernetes/files/k0s"
const (
defaultK0sPath = "kubernetes/files/k0s"
k0sctlConfigFile = "k0sctl-config.yaml"
)

func (c *InstallK0sCmd) InstallK0s(pm installer.PackageManager, k0s installer.K0sManager) error {
// Default dependency path for k0s binary within package
k0sPath := pm.GetDependencyPath(defaultK0sPath)
func (c *InstallK0sCmd) InstallK0s(pm installer.PackageManager, k0s installer.K0sManager, k0sctl installer.K0sctlManager) error {
// Load install-config
icg := installer.NewInstallConfigManager()
if err := icg.LoadInstallConfigFromFile(c.Opts.InstallConfig); err != nil {
return fmt.Errorf("failed to load install-config: %w", err)
}

var err error
if c.Opts.Package == "" {
k0sPath, err = k0s.Download(c.Opts.Version, c.Opts.Force, false)
config := icg.GetInstallConfig()

if !config.Kubernetes.ManagedByCodesphere {
return fmt.Errorf("install-config specifies external Kubernetes, k0s installation is only supported for Codesphere-managed Kubernetes")
}

// Determine k0s version
k0sVersion := c.Opts.Version
if k0sVersion == "" {
var err error
k0sVersion, err = k0s.GetLatestVersion()
if err != nil {
return fmt.Errorf("failed to download k0s: %w", err)
return fmt.Errorf("failed to get latest k0s version: %w", err)
}
log.Printf("Using latest k0s version: %s", k0sVersion)
}

// Download or get k0s binary path
var k0sBinaryPath string
if !c.Opts.NoDownload {
if c.Opts.Package != "" {
// Extract the k0s binary from the package first
if err := pm.ExtractDependency(defaultK0sPath, c.Opts.Force); err != nil {
return fmt.Errorf("failed to extract k0s from package: %w", err)
}
k0sBinaryPath = pm.GetDependencyPath(defaultK0sPath)
} else {
var err error
k0sBinaryPath, err = k0s.Download(k0sVersion, c.Opts.Force, false)
if err != nil {
return fmt.Errorf("failed to download k0s: %w", err)
}
}
}

err = k0s.Install(c.Opts.Config, k0sPath, c.Opts.Force)
// Download k0sctl
log.Println("Downloading k0sctl...")
k0sctlPath, err := k0sctl.Download(c.Opts.K0sctlVersion, c.Opts.Force, false)
if err != nil {
return fmt.Errorf("failed to install k0s: %w", err)
return fmt.Errorf("failed to download k0sctl: %w", err)
}

// Generate k0sctl configuration
log.Println("Generating k0sctl configuration from install-config...")
k0sctlConfig, err := installer.GenerateK0sctlConfig(config, k0sVersion, c.Opts.SSHKeyPath, k0sBinaryPath)
if err != nil {
return fmt.Errorf("failed to generate k0sctl config: %w", err)
}

// Write k0sctl config to file
k0sctlConfigData, err := k0sctlConfig.Marshal()
if err != nil {
return fmt.Errorf("failed to marshal k0sctl config: %w", err)
}

k0sctlConfigPath := filepath.Join(c.Env.GetOmsWorkdir(), k0sctlConfigFile)
if err := c.FileWriter.WriteFile(k0sctlConfigPath, k0sctlConfigData, 0644); err != nil {
return fmt.Errorf("failed to write k0sctl config: %w", err)
}

log.Printf("Generated k0sctl configuration at %s", k0sctlConfigPath)

// Apply k0sctl configuration
log.Println("Applying k0sctl configuration to deploy k0s cluster...")
if err := k0sctl.Apply(k0sctlConfigPath, k0sctlPath, c.Opts.Force); err != nil {
return fmt.Errorf("failed to apply k0sctl config: %w", err)
}

log.Println("k0s cluster deployed successfully!")
log.Printf("To manage your cluster, use: %s kubeconfig --config %s", k0sctlPath, k0sctlConfigPath)

return nil
}
Loading