Skip to content

Commit c502b0a

Browse files
feat: block individual node upgrades when using centralized config (#53)
feat: individual node upgrades when centralized config users shouldn't be able to run `helmvm node upgrade` when they are using a centralized config. on a centralized config all nodes are upgraded with a single `helmvm apply` or `helmvm install` command. this commit blocks users from attempting to upgrade nodes individually until they have added other nodes to the cluster using `join` commands.
1 parent 29491cb commit c502b0a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cmd/helmvm/upgrade.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ func stopHelmVM() error {
3030
return nil
3131
}
3232

33-
// canRunUpgrade checks if we can run the upgrade command. Checks if we are running on linux
34-
// and if we are root.
33+
// canRunUpgrade checks if we can run the upgrade command. Checks if we are running on
34+
// linux and if we are root. This function also ensures that upgrades can't be run on
35+
// a cluster that has been deployed using a centralized configuration.
3536
func canRunUpgrade(c *cli.Context) error {
3637
if runtime.GOOS != "linux" {
3738
return fmt.Errorf("upgrade command is only supported on linux")
3839
}
3940
if os.Getuid() != 0 {
4041
return fmt.Errorf("upgrade command must be run as root")
4142
}
42-
return nil
43+
if _, err := os.Stat(defaults.PathToConfig("k0sctl.yaml")); err != nil {
44+
if os.IsNotExist(err) {
45+
return nil
46+
}
47+
return fmt.Errorf("unable to read configuration: %w", err)
48+
}
49+
if defaults.DecentralizedInstall() {
50+
return nil
51+
}
52+
logrus.Errorf("Attempting to upgrade a single node in a cluster with centralized")
53+
logrus.Errorf("configuration is not supported. Execute the following command for")
54+
logrus.Errorf("a proper upgrade:")
55+
logrus.Errorf("\t%s apply", defaults.BinaryName())
56+
return fmt.Errorf("command not available")
4357
}
4458

4559
var upgradeCommand = &cli.Command{

0 commit comments

Comments
 (0)