Skip to content

Commit

Permalink
k3s, rke2, rancherd supports semver w/ pre-release
Browse files Browse the repository at this point in the history
ref: #47
  • Loading branch information
innobead committed May 2, 2021
1 parent e4c8890 commit 9413383
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions internal/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ func RKEVersionsEnvVars(version string) EnvVars {
func RKE2VersionsEnvVars(version string, configContent string) EnvVars {
return []string{
fmt.Sprintf("RKE2_VERSION=%s", version),
fmt.Sprintf("INSTALL_RKE2_VERSION=%s", version),
fmt.Sprintf(`RKE2_CONFIG="%s"`, configContent),
}
}

func RancherdVersionsEnvVars(version string, configContent string) EnvVars {
return []string{
fmt.Sprintf("RANCHERD_VERSION=%s", version),
fmt.Sprintf("INSTALL_RANCHERD_VERSION=%s", version),
fmt.Sprintf(`RKE2_CONFIG="%s"`, configContent),
}
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/bootstrap/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ func (k *K3sBootstrapper) bootstrap(node *data.Node, isSingleNode bool, extraOpt
before utilssh.Callback
}{
{
cmdline: fmt.Sprintf(`INSTALL_K3S_EXEC="%s" %s k3s-install.sh `, strings.Join(deployCmdOpts, " "), strings.Join(extraOptions.ExtraOptions, " ")),
cmdline: fmt.Sprintf(
`%s INSTALL_K3S_EXEC="%s" %s k3s-install.sh `,
config.K3sVersionsEnvVars(node.Spec.Cluster.Version).String(),
strings.Join(deployCmdOpts, " "),
strings.Join(extraOptions.ExtraOptions, " "),
),
},
{
cmdline: "cat /var/lib/rancher/k3s/server/node-token",
Expand Down Expand Up @@ -183,7 +188,12 @@ func (k *K3sBootstrapper) join(node *data.Node, apiServerAddress string, joinTok
defer sshClient.Close()

var deployCmdOpts []string
cmd := fmt.Sprintf("K3S_URL=https://%s:6443 K3S_TOKEN=%s k3s-install.sh", apiServerAddress, joinToken)
cmd := fmt.Sprintf(
"%s K3S_URL=https://%s:6443 K3S_TOKEN=%s k3s-install.sh",
config.K3sVersionsEnvVars(node.Spec.Cluster.Version).String(),
apiServerAddress,
joinToken,
)

if node.IsMaster() {
deployCmdOpts = append(deployCmdOpts, "--server")
Expand Down
12 changes: 10 additions & 2 deletions pkg/bootstrap/rancherd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ func (r *RancherdBootstrapper) bootstrap(node *data.Node, isSingleNode bool, ext
),
},
{
cmdline: "rancherd-install.sh",
cmdline: fmt.Sprintf(
"%s rancherd-install.sh",
config.RancherdVersionsEnvVars(node.Spec.Cluster.Version, deployConfigValue).String(),
),
},
{
cmdline: "systemctl enable rancherd-server.service",
Expand Down Expand Up @@ -197,6 +200,7 @@ func (r *RancherdBootstrapper) join(node *data.Node, apiServerAddress string, jo
}
cmd := "INSTALL_RKE2_TYPE=server rancherd-install.sh"
systemdService := "rancherd-server.service"

if node.IsMaster() {
if len(extraOptions.ServerInstallOptions) > 0 {
deployCmdOpts = append(deployCmdOpts, extraOptions.ServerInstallOptions...)
Expand Down Expand Up @@ -226,7 +230,11 @@ func (r *RancherdBootstrapper) join(node *data.Node, apiServerAddress string, jo
),
},
{
cmdline: cmd,
cmdline: fmt.Sprintf(
"%s %s",
config.RancherdVersionsEnvVars(node.Spec.Cluster.Version, deployConfigValue).String(),
cmd,
),
},
{
cmdline: fmt.Sprintf("systemctl enable %s", systemdService),
Expand Down
12 changes: 10 additions & 2 deletions pkg/bootstrap/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ func (r *RKE2Bootstrapper) bootstrap(node *data.Node, isSingleNode bool, extraOp
),
},
{
cmdline: "rke2-install.sh",
cmdline: fmt.Sprintf(
"%s rke2-install.sh",
config.RKE2VersionsEnvVars(node.Spec.Cluster.Version, "").String(),
),
},
{
cmdline: "systemctl enable rke2-server.service",
Expand Down Expand Up @@ -197,6 +200,7 @@ func (r *RKE2Bootstrapper) join(node *data.Node, apiServerAddress string, joinTo
}
cmd := "INSTALL_RKE2_TYPE=server rke2-install.sh"
systemdService := "rke2-server.service"

if node.IsMaster() {
if len(extraOptions.ServerInstallOptions) > 0 {
deployCmdOpts = append(deployCmdOpts, extraOptions.ServerInstallOptions...)
Expand Down Expand Up @@ -226,7 +230,11 @@ func (r *RKE2Bootstrapper) join(node *data.Node, apiServerAddress string, joinTo
),
},
{
cmdline: cmd,
cmdline: fmt.Sprintf(
"%s %s",
config.RKE2VersionsEnvVars(node.Spec.Cluster.Version, "").String(),
cmd,
),
},
{
cmdline: fmt.Sprintf("systemctl enable %s", systemdService),
Expand Down

0 comments on commit 9413383

Please sign in to comment.