Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
84 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
0cfbbd8
ref: cleanup
OliverTrautvetter Feb 11, 2026
593fff9
Merge remote-tracking branch 'origin/main' into deploy_k0s_install-co…
OliverTrautvetter Feb 11, 2026
3270731
chore(docs): Auto-update docs and licenses
OliverTrautvetter Feb 11, 2026
e22a299
Merge remote-tracking branch 'origin/main' into deploy_k0s_install-co…
OliverTrautvetter Feb 16, 2026
59f5b84
chore(docs): Auto-update docs and licenses
OliverTrautvetter Feb 16, 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
40 changes: 32 additions & 8 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ License URL: https://github.com/clipperhouse/uax29/blob/v2.3.0/LICENSE

----------
Module: github.com/codesphere-cloud/cs-go/pkg/io
Version: v0.14.1
Version: v0.15.0
License: Apache-2.0
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.14.1/LICENSE
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.15.0/LICENSE

----------
Module: github.com/codesphere-cloud/oms/internal/tmpl
Expand Down Expand Up @@ -77,16 +77,28 @@ License URL: https://github.com/inconshreveable/go-update/blob/8152e7eb6ccf/inte

----------
Module: github.com/jedib0t/go-pretty/v6
Version: v6.7.5
Version: v6.7.7
License: MIT
License URL: https://github.com/jedib0t/go-pretty/blob/v6.7.5/LICENSE
License URL: https://github.com/jedib0t/go-pretty/blob/v6.7.7/LICENSE

----------
Module: github.com/kr/fs
Version: v0.1.0
License: BSD-3-Clause
License URL: https://github.com/kr/fs/blob/v0.1.0/LICENSE

----------
Module: github.com/mattn/go-runewidth
Version: v0.0.19
License: MIT
License URL: https://github.com/mattn/go-runewidth/blob/v0.0.19/LICENSE

----------
Module: github.com/pkg/sftp
Version: v1.13.10
License: BSD-2-Clause
License URL: https://github.com/pkg/sftp/blob/v1.13.10/LICENSE

----------
Module: github.com/pmezard/go-difflib/difflib
Version: v1.0.1-0.20181226105442-5d4384ee4fb2
Expand Down Expand Up @@ -155,21 +167,33 @@ License URL: https://github.com/yaml/go-yaml/blob/v3.0.4/LICENSE

----------
Module: golang.org/x/crypto
Version: v0.45.0
Version: v0.46.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/crypto/+/v0.45.0:LICENSE
License URL: https://cs.opensource.google/go/x/crypto/+/v0.46.0:LICENSE

----------
Module: golang.org/x/oauth2
Version: v0.33.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/oauth2/+/v0.33.0:LICENSE

----------
Module: golang.org/x/sys/unix
Version: v0.39.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/sys/+/v0.39.0:LICENSE

----------
Module: golang.org/x/term
Version: v0.38.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/term/+/v0.38.0:LICENSE

----------
Module: golang.org/x/text
Version: v0.31.0
Version: v0.32.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/text/+/v0.31.0:LICENSE
License URL: https://cs.opensource.google/go/x/text/+/v0.32.0:LICENSE

----------
Module: gopkg.in/yaml.v3
Expand Down
112 changes: 107 additions & 5 deletions cli/cmd/install_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ package cmd

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

packageio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/spf13/cobra"

"github.com/codesphere-cloud/oms/internal/env"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/installer/files"
"github.com/codesphere-cloud/oms/internal/installer/node"
"github.com/codesphere-cloud/oms/internal/portal"
"github.com/codesphere-cloud/oms/internal/util"
)
Expand All @@ -25,10 +30,14 @@ type InstallK0sCmd struct {

type InstallK0sOpts struct {
*GlobalOptions
Version string
Package string
Config string
Force bool
Version string
Package string
Config string
InstallConfig string
SSHKeyPath string
RemoteHost string
RemoteUser string
Force bool
}

func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error {
Expand All @@ -37,6 +46,10 @@ func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error {
pm := installer.NewPackage(env.GetOmsWorkdir(), c.Opts.Package)
k0s := installer.NewK0s(hw, env, c.FileWriter)

if c.Opts.InstallConfig != "" {
return c.InstallK0sFromInstallConfig(pm, k0s)
}

err := c.InstallK0s(pm, k0s)
if err != nil {
return fmt.Errorf("failed to install k0s: %w", err)
Expand All @@ -54,12 +67,19 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) {
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.`),
If no install config is provided, k0s will be installed with the '--single' flag.

You can also install k0s from a Codesphere install-config file, which will:
- Generate a k0s configuration from the install-config
- Optionally install k0s on remote nodes via SSH`),
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: "--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: "--install-config <path>", Desc: "Path to Codesphere install-config file to generate k0s config from"},
{Cmd: "--remote-host <ip>", Desc: "Remote host IP to install k0s on (requires --ssh-key-path)"},
{Cmd: "--ssh-key-path <path>", Desc: "SSH private key path for remote installation"},
{Cmd: "--force", Desc: "Force new download and installation even if k0s binary exists or is already installed"},
}, "oms-cli"),
},
Expand All @@ -70,6 +90,10 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) {
k0s.cmd.Flags().StringVarP(&k0s.Opts.Version, "version", "v", "", "Version of k0s to install")
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")
k0s.cmd.Flags().StringVar(&k0s.Opts.SSHKeyPath, "ssh-key-path", "", "SSH private key path for remote installation")
k0s.cmd.Flags().StringVar(&k0s.Opts.RemoteHost, "remote-host", "", "Remote host IP to install k0s on")
k0s.cmd.Flags().StringVar(&k0s.Opts.RemoteUser, "remote-user", "root", "Remote user for SSH connection")
k0s.cmd.Flags().BoolVarP(&k0s.Opts.Force, "force", "f", false, "Force new download and installation")

install.AddCommand(k0s.cmd)
Expand Down Expand Up @@ -98,3 +122,81 @@ func (c *InstallK0sCmd) InstallK0s(pm installer.PackageManager, k0s installer.K0

return nil
}

func (c *InstallK0sCmd) InstallK0sFromInstallConfig(pm installer.PackageManager, k0s installer.K0sManager) error {
icg := installer.NewInstallConfigManager()
if err := icg.LoadInstallConfigFromFile(c.Opts.InstallConfig); err != nil {
return fmt.Errorf("failed to load install-config: %w", err)
}

config := icg.GetInstallConfig()

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

log.Println("Generating k0s configuration from install-config...")
k0sConfig, err := installer.GenerateK0sConfig(config)
if err != nil {
return fmt.Errorf("failed to generate k0s config: %w", err)
}

k0sConfigData, err := k0sConfig.Marshal()
if err != nil {
return fmt.Errorf("failed to marshal k0s config: %w", err)
}

tmpK0sConfigPath := filepath.Join(os.TempDir(), "k0s-config.yaml")
if err := os.WriteFile(tmpK0sConfigPath, k0sConfigData, 0644); err != nil {
return fmt.Errorf("failed to write k0s config: %w", err)
}
defer func() { _ = os.Remove(tmpK0sConfigPath) }()

log.Printf("Generated k0s configuration at %s", tmpK0sConfigPath)

k0sPath := pm.GetDependencyPath(defaultK0sPath)
if c.Opts.Package == "" {
k0sPath, err = k0s.Download(c.Opts.Version, c.Opts.Force, false)
if err != nil {
return fmt.Errorf("failed to download k0s: %w", err)
}
}

if c.Opts.RemoteHost != "" {
return c.InstallK0sRemote(config, k0sPath, tmpK0sConfigPath)
}

err = k0s.Install(tmpK0sConfigPath, k0sPath, c.Opts.Force)
if err != nil {
return fmt.Errorf("failed to install k0s: %w", err)
}

log.Println("k0s installed successfully using configuration from install-config")
return nil
}

func (c *InstallK0sCmd) InstallK0sRemote(config *files.RootConfig, k0sBinaryPath string, k0sConfigPath string) error {
if c.Opts.SSHKeyPath == "" {
return fmt.Errorf("--ssh-key-path is required for remote installation")
}

log.Printf("Installing k0s on remote host %s", c.Opts.RemoteHost)

nm := &node.NodeManager{
FileIO: c.FileWriter,
KeyPath: c.Opts.SSHKeyPath,
}

remoteNode := &node.Node{
ExternalIP: c.Opts.RemoteHost,
InternalIP: c.Opts.RemoteHost,
Name: "k0s-node",
}

if err := remoteNode.InstallK0s(nm, k0sBinaryPath, k0sConfigPath, c.Opts.Force); err != nil {
return fmt.Errorf("failed to install k0s on remote host: %w", err)
}

log.Printf("k0s successfully installed on remote host %s", c.Opts.RemoteHost)
return nil
}
Loading