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

chore: switch our own addons to use the native helm installer #88

Merged
merged 39 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2b53813
switch our own addons to use the native helm installer
danj-replicated Sep 29, 2023
94e330a
re-enable custom charts
danj-replicated Oct 3, 2023
1b92a08
clean up helm deps in addon packages
danj-replicated Oct 3, 2023
9e990c3
use provided values for custom charts
danj-replicated Oct 4, 2023
4a21614
defer close
danj-replicated Oct 4, 2023
6ba7990
Merge branch 'main' into danj/k0sctl-helm-installer
danj-replicated Oct 4, 2023
ce01dd8
check if custom charts are disabled
danj-replicated Oct 4, 2023
e8b7599
fix 'apply' upgrades
danj-replicated Oct 4, 2023
3f5054b
don't ask for password if admin panel already has one
danj-replicated Oct 4, 2023
61f772d
don't ask for password if admin panel already has one
danj-replicated Oct 4, 2023
d525cd2
println
danj-replicated Oct 4, 2023
ed5db82
re-order e2e script
danj-replicated Oct 4, 2023
e71c6c0
re-enable terraform stuff
danj-replicated Oct 4, 2023
c461281
ask for new kots password if we can't get it
danj-replicated Oct 5, 2023
77b578e
warn on password fetch failure
danj-replicated Oct 5, 2023
63c98d7
address some comments and refactor config generation
danj-replicated Oct 5, 2023
605f27a
Merge branch 'main' into danj/k0sctl-helm-installer
danj-replicated Oct 5, 2023
c667ae9
fix wonky merge
danj-replicated Oct 5, 2023
d07d819
fix k0sctl helm config generation
danj-replicated Oct 5, 2023
d6db879
Add checks for config and password verification
danj-replicated Oct 6, 2023
4289f2c
update e2e for password confirm
danj-replicated Oct 6, 2023
7d74013
Don't marshall cluster config object
danj-replicated Oct 6, 2023
00d9d16
use os.WriteFile for chart archives
danj-replicated Oct 6, 2023
6a8fcdd
wrong type
danj-replicated Oct 6, 2023
06d6893
type check config and fix custom chart writer
danj-replicated Oct 6, 2023
478237e
password is now after node inputs
danj-replicated Oct 6, 2023
45f0284
remove commented lines
danj-replicated Oct 6, 2023
e887ca4
fail after trying to set admin password 3 times
danj-replicated Oct 6, 2023
1a231a7
address PR comments
danj-replicated Oct 10, 2023
b160c3c
check for nil items in config
danj-replicated Oct 13, 2023
488f012
Merge branch 'main' into danj/k0sctl-helm-installer
danj-replicated Oct 13, 2023
4310add
readability
danj-replicated Oct 13, 2023
8141130
fix current config password check
danj-replicated Oct 13, 2023
afd984c
remove addonsOnly test
danj-replicated Oct 13, 2023
0bbbeda
Merge remote-tracking branch 'origin/main' into danj/k0sctl-helm-inst…
laverya Oct 16, 2023
15b80ee
go mod tidy
laverya Oct 16, 2023
a18009c
fix lint issues
laverya Oct 16, 2023
8e7a4b6
Merge remote-tracking branch 'origin/main' into danj/k0sctl-helm-inst…
laverya Oct 16, 2023
daed2d3
Merge remote-tracking branch 'origin/main' into danj/k0sctl-helm-inst…
laverya Oct 16, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- TestVersion
- TestMultiNodeInteractiveInstallation
- TestInstallWithDisabledAddons
- TestEmbedAddonsOnly
- TestHostPreflight
steps:
- name: Move Docker aside
Expand Down
108 changes: 58 additions & 50 deletions cmd/helmvm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ func createK0sctlConfigBackup(ctx context.Context) error {
return nil
}

// updateConfigBundle updates the k0sctl.yaml file in the configuration directory
// to use the bundle in the specified directory (reads the bundle directory and
// updates the files that need to be uploaded to the nodes). This function also
// makes sure that the k0s version used in the configuration matches the version
// we are planning to install.
func updateConfigBundle(ctx context.Context, bundledir string) error {
if err := createK0sctlConfigBackup(ctx); err != nil {
// updateConfig updates the k0sctl.yaml file with the latest configuration
// options.
func updateConfig(c *cli.Context) error {

bundledir := c.String("bundle")

if err := createK0sctlConfigBackup(c.Context); err != nil {
return fmt.Errorf("unable to create config backup: %w", err)
}

cfgpath := defaults.PathToConfig("k0sctl.yaml")
cfg, err := config.ReadConfigFile(cfgpath)
if err != nil {
Expand All @@ -158,6 +159,20 @@ func updateConfigBundle(ctx context.Context, bundledir string) error {
return fmt.Errorf("unable to update hosts files: %w", err)
}
cfg.Spec.K0s.Version = defaults.K0sVersion

opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
}

for _, addon := range c.StringSlice("disable-addon") {
opts = append(opts, addons.WithoutAddon(addon))
}

if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
return fmt.Errorf("unable to update helm configs: %w", err)
}

fp, err := os.OpenFile(cfgpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("unable to create config file: %w", err)
Expand Down Expand Up @@ -224,10 +239,10 @@ func ensureK0sctlConfig(c *cli.Context, nodes []infra.Node, useprompt bool) erro
if _, err := os.Stat(cfgpath); err == nil {
if len(nodes) == 0 {
if !useprompt {
return updateConfigBundle(c.Context, bundledir)
return updateConfig(c)
}
if !overwriteExistingConfig() {
return updateConfigBundle(c.Context, bundledir)
return updateConfig(c)
}
}
if err := createK0sctlConfigBackup(c.Context); err != nil {
Expand All @@ -236,10 +251,25 @@ func ensureK0sctlConfig(c *cli.Context, nodes []infra.Node, useprompt bool) erro
} else if !os.IsNotExist(err) {
return fmt.Errorf("unable to open config: %w", err)
}

cfg, err := config.RenderClusterConfig(c.Context, nodes, multi)
if err != nil {
return fmt.Errorf("unable to render config: %w", err)
}

opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
}

for _, addon := range c.StringSlice("disable-addon") {
opts = append(opts, addons.WithoutAddon(addon))
}

if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
return fmt.Errorf("unable to update helm configs: %w", err)
}

if bundledir != "" {
config.SetUploadBinary(cfg)
}
Expand Down Expand Up @@ -330,7 +360,8 @@ func dumpApplyLogs() {

// applyK0sctl runs the k0sctl apply command and waits for it to finish. If
// no configuration is found one is generated.
func applyK0sctl(c *cli.Context, useprompt bool, nodes []infra.Node) error {
func applyK0sctl(c *cli.Context, nodes []infra.Node) error {
useprompt := !c.Bool("no-prompt")
fmt.Println("Processing cluster configuration")
if err := ensureK0sctlConfig(c, nodes, useprompt); err != nil {
return fmt.Errorf("unable to create config file: %w", err)
Expand All @@ -356,9 +387,8 @@ func applyK0sctl(c *cli.Context, useprompt bool, nodes []infra.Node) error {

// installCommands executes the "install" command. This will ensure that a
// k0sctl.yaml file exists and then run `k0sctl apply` to apply the cluster.
// Once this is finished then a "kubeconfig" file is created and the addons
// are applied. Resulting k0sctl.yaml and kubeconfig are stored in the
// configuration dir.
// Once this is finished then a "kubeconfig" file is created.
// Resulting k0sctl.yaml and kubeconfig are stored in the configuration dir.
var installCommand = &cli.Command{
Name: "install",
Aliases: []string{"apply"},
Expand All @@ -381,11 +411,6 @@ var installCommand = &cli.Command{
Usage: "Installs or upgrades a multi node deployment",
Value: false,
},
&cli.BoolFlag{
Name: "addons-only",
Usage: "Only apply addons. Skips cluster install",
Value: false,
},
&cli.BoolFlag{
Name: "no-prompt",
Usage: "Do not prompt user when it is not necessary",
Expand All @@ -412,50 +437,33 @@ var installCommand = &cli.Command{
metrics.ReportApplyFinished(c, err)
ricardomaraschini marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if !c.Bool("addons-only") {
ricardomaraschini marked this conversation as resolved.
Show resolved Hide resolved
var err error
var nodes []infra.Node
if dir := c.String("infra"); dir != "" {
logrus.Infof("Processing infrastructure manifests")
if nodes, err = infra.Apply(c.Context, dir, useprompt); err != nil {
err := fmt.Errorf("unable to create infra: %w", err)
metrics.ReportApplyFinished(c, err)
return err
}
}
if err := applyK0sctl(c, useprompt, nodes); err != nil {
err := fmt.Errorf("unable update cluster: %w", err)

var err error
var nodes []infra.Node
if dir := c.String("infra"); dir != "" {
logrus.Infof("Processing infrastructure manifests")
if nodes, err = infra.Apply(c.Context, dir, useprompt); err != nil {
err := fmt.Errorf("unable to create infra: %w", err)
metrics.ReportApplyFinished(c, err)
return err
}
}
if err := applyK0sctl(c, nodes); err != nil {
err := fmt.Errorf("unable update cluster: %w", err)
metrics.ReportApplyFinished(c, err)
return err

}

logrus.Infof("Reading cluster access configuration")
if err := runK0sctlKubeconfig(c.Context); err != nil {
err := fmt.Errorf("unable to get kubeconfig: %w", err)
metrics.ReportApplyFinished(c, err)
return err
}
logrus.Infof("Applying add-ons")
ccfg := defaults.PathToConfig("k0sctl.yaml")
kcfg := defaults.PathToConfig("kubeconfig")
os.Setenv("KUBECONFIG", kcfg)
opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
}
for _, addon := range c.StringSlice("disable-addon") {
opts = append(opts, addons.WithoutAddon(addon))
}
if err := addons.NewApplier(opts...).Apply(c.Context); err != nil {
err := fmt.Errorf("unable to apply addons: %w", err)
metrics.ReportApplyFinished(c, err)
return err
}
if err := runPostApply(c.Context); err != nil {
err := fmt.Errorf("unable to run post apply: %w", err)
metrics.ReportApplyFinished(c, err)
return err
}

fmt.Println("Cluster configuration has been applied")
fmt.Printf("Kubeconfig file has been placed at at %s\n", kcfg)
fmt.Printf("Cluster configuration file has been placed at %s\n", ccfg)
Expand Down
16 changes: 2 additions & 14 deletions cmd/helmvm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,9 @@ var upgradeCommand = &cli.Command{
metrics.ReportNodeUpgradeFailed(c.Context, err)
return err
}
os.Setenv("KUBECONFIG", kcfg)
logrus.Infof("Upgrading addons")
opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
}
for _, addon := range c.StringSlice("disable-addon") {
opts = append(opts, addons.WithoutAddon(addon))
}
if err := addons.NewApplier(opts...).Apply(c.Context); err != nil {
err := fmt.Errorf("unable to apply addons: %w", err)
metrics.ReportNodeUpgradeFailed(c.Context, err)
return err
}

ricardomaraschini marked this conversation as resolved.
Show resolved Hide resolved
metrics.ReportNodeUpgradeSucceeded(c.Context)

logrus.Infof("Upgrade complete")
return nil
},
Expand Down
33 changes: 1 addition & 32 deletions e2e/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/replicatedhq/helmvm/e2e/cluster"
)

func TestEmbedAndInstall(t *testing.T) {
func AndInstall(t *testing.T) {
t.Parallel()
tc := cluster.NewTestCluster(&cluster.Input{
T: t,
Expand All @@ -31,34 +31,3 @@ func TestEmbedAndInstall(t *testing.T) {
t.Fatalf("fail to install embedded ssh in node 0: %v", err)
}
}

func TestEmbedAddonsOnly(t *testing.T) {
t.Parallel()
tc := cluster.NewTestCluster(&cluster.Input{
T: t,
Nodes: 1,
Image: "ubuntu/jammy",
SSHPublicKey: "../output/tmp/id_rsa.pub",
SSHPrivateKey: "../output/tmp/id_rsa",
HelmVMPath: "../output/bin/helmvm",
})
defer tc.Destroy()
t.Log("installing ssh in node 0")
commands := [][]string{
{"apt-get", "update", "-y"},
{"apt-get", "install", "openssh-server", "-y"},
}
if err := RunCommandsOnNode(t, tc, 0, commands); err != nil {
t.Fatalf("fail to install ssh on node %s: %v", tc.Nodes[0], err)
}
t.Log("installing helmvm on node 0")
line := []string{"single-node-install.sh"}
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
}
t.Log("testing --addons-only on node 0")
line = []string{"addons-only.sh"}
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
t.Fatalf("fail to install embedded ssh in node 0: %v", err)
}
}
1 change: 1 addition & 0 deletions e2e/scripts/interactive-multi-node-install.exp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ expect -re "Add another node?.*:" { send "n\r" }
set timeout 600
expect "Load balancer address:" { send "\r" }
expect "Enter a new Admin Console password:" { send "password\r" }
expect "Confirm password:" { send "password\r" }
expect "You can now access your cluster with kubectl"
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand All @@ -61,6 +62,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/docker/cli v24.0.6+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
Expand Down Expand Up @@ -127,6 +129,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/webbrowser v1.0.0 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/k0sproject/k0s v0.13.1
github.com/k0sproject/version v0.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
Expand Down Expand Up @@ -212,7 +215,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/macaroon.v2 v2.1.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/yaml.v3 v3.0.1
k8s.io/apiextensions-apiserver v0.28.2 // indirect
k8s.io/apiserver v0.28.2 // indirect
k8s.io/cli-runtime v0.28.2 // indirect
Expand Down
Loading
Loading