Skip to content

Commit

Permalink
Add version pinning
Browse files Browse the repository at this point in the history
This commit adds the --k3s-version flag to install/join and fixes
an issue reported by @GnaphronG in PR #35. Rather than adding a
user-facing "extra-envs" command, this has been wrapped up in a
flag for a more concise UX.

The default has also been pinned to v0.8.0 due to his report of
v0.9.0 not working on Raspberry Pi, which is a primary use-case
for k3sup.

Tested by creating cluster with v0.8.0 with 2x RPi4.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Sep 22, 2019
1 parent d1de835 commit 7d95441
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"

config "github.com/alexellis/k3sup/pkg/config"
kssh "github.com/alexellis/k3sup/pkg/ssh"

homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -40,6 +41,7 @@ func MakeInstall() *cobra.Command {
command.Flags().String("local-path", "kubeconfig", "Local path to save the kubeconfig file")
command.Flags().String("k3s-extra-args", "", "Optional extra arguments to pass to k3s installer, wrapped in quotes (e.g. --k3s-extra-args '--no-deploy servicelb')")
command.Flags().Bool("merge", false, "Merge the config with existing kubeconfig if it already exists.\nProvide the --local-path flag with --merge if a kubeconfig already exists in some other directory")
command.Flags().String("k3s-version", config.K3sVersion, "Optional version to install, pinned at a default")

command.RunE = func(command *cobra.Command, args []string) error {

Expand All @@ -57,6 +59,8 @@ func MakeInstall() *cobra.Command {
merge, _ := command.Flags().GetBool("merge")
k3sExtraArgs, _ := command.Flags().GetString("k3s-extra-args")

k3sVersion, _ := command.Flags().GetString("k3s-version")

sshKeyPath := expandPath(sshKey)
fmt.Printf("ssh -i %s %s@%s\n", sshKeyPath, user, ip.String())

Expand Down Expand Up @@ -85,7 +89,8 @@ func MakeInstall() *cobra.Command {
defer operator.Close()

if !skipInstall {
installK3scommand := fmt.Sprintf("curl -sLS https://get.k3s.io | INSTALL_K3S_EXEC='server --tls-san %s %s' sh -\n", ip, k3sExtraArgs)
installK3scommand := fmt.Sprintf("curl -sLS https://get.k3s.io | INSTALL_K3S_EXEC='server --tls-san %s %s' INSTALL_K3S_VERSION='%s' sh -\n", ip, strings.TrimSpace(k3sExtraArgs), k3sVersion)

fmt.Printf("ssh: %s\n", installK3scommand)
res, err := operator.Execute(installK3scommand)

Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"strings"

config "github.com/alexellis/k3sup/pkg/config"
kssh "github.com/alexellis/k3sup/pkg/ssh"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -29,6 +30,7 @@ func MakeJoin() *cobra.Command {
command.Flags().Int("ssh-port", 22, "The port on which to connect for ssh")
command.Flags().Bool("skip-install", false, "Skip the k3s installer")
command.Flags().String("k3s-extra-args", "", "Optional extra arguments to pass to k3s installer, wrapped in quotes (e.g. --k3s-extra-args '--node-taint key=value:NoExecute')")
command.Flags().String("k3s-version", config.K3sVersion, "Optional version to install, pinned at a default")

command.RunE = func(command *cobra.Command, args []string) error {

Expand All @@ -45,6 +47,8 @@ func MakeJoin() *cobra.Command {

k3sExtraArgs, _ := command.Flags().GetString("k3s-extra-args")

k3sVersion, _ := command.Flags().GetString("k3s-version")

sshKeyPath := expandPath(sshKey)
fmt.Printf("ssh -i %s %s@%s\n", sshKeyPath, user, serverIP.String())

Expand Down Expand Up @@ -87,7 +91,7 @@ func MakeJoin() *cobra.Command {

joinToken := string(res.StdOut)

setupAgent(serverIP, ip, port, user, sshKeyPath, joinToken, k3sExtraArgs)
setupAgent(serverIP, ip, port, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion)

return nil
}
Expand All @@ -113,7 +117,7 @@ func MakeJoin() *cobra.Command {
return command
}

func setupAgent(serverIP, ip net.IP, port int, user, sshKeyPath, joinToken string, k3sExtraArgs string) error {
func setupAgent(serverIP, ip net.IP, port int, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion string) error {

authMethod, closeSSHAgent, err := loadPublickey(sshKeyPath)
if err != nil {
Expand All @@ -139,7 +143,7 @@ func setupAgent(serverIP, ip net.IP, port int, user, sshKeyPath, joinToken strin

defer operator.Close()

getTokenCommand := fmt.Sprintf("curl -sfL https://get.k3s.io/ | K3S_URL='https://%s:6443' K3S_TOKEN='%s' sh -s - %s", serverIP.String(), strings.TrimSpace(joinToken), k3sExtraArgs)
getTokenCommand := fmt.Sprintf("curl -sfL https://get.k3s.io/ | K3S_URL='https://%s:6443' K3S_TOKEN='%s' INSTALL_K3S_VERSION='%s' sh -s - %s", serverIP.String(), strings.TrimSpace(joinToken), k3sVersion, k3sExtraArgs)
fmt.Printf("ssh: %s\n", getTokenCommand)

res, err := operator.Execute(getTokenCommand)
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config

// K3sVersion default version
const K3sVersion = "v0.8.1"

0 comments on commit 7d95441

Please sign in to comment.