Skip to content

Commit

Permalink
Add k3s support for ks (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Mar 7, 2021
1 parent 82821d3 commit 8a0cc13
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ All features below work with [KubeSphere](https://github.com/kubsphere/kubespher
* Update a component manually or automatically
* Output the logs of a KubeSphere component
* Edit a KubeSphere component
* Working with [k3s](https://github.com/k3s-io/k3s) via setting environment `kubernetes_type=k3s`

## Pipeline

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/linuxsuren/cobra-extension v0.0.10
github.com/linuxsuren/go-cli-alias v0.0.4
github.com/linuxsuren/go-cli-alias v0.0.5
github.com/mitchellh/copystructure v1.1.1 // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
k8s.io/api v0.19.4
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ github.com/linuxsuren/cobra-extension v0.0.6 h1:JlSmHjE/KCdJBZYGTjQbgvXSpziFwzpI
github.com/linuxsuren/cobra-extension v0.0.6/go.mod h1:qcEJv7BbL0UpK6MbrTESP/nKf1+z1wQdMAnE1NBl3QQ=
github.com/linuxsuren/cobra-extension v0.0.10 h1:ciZDb2Bp/aAFqr4YoeVuH2uyBaBFfO6pwz1WBih7R4A=
github.com/linuxsuren/cobra-extension v0.0.10/go.mod h1:nDsXgvm0lSWVV+byAEfwhIGFDoIp0Sq9wkfNUDBp5do=
github.com/linuxsuren/go-cli-alias v0.0.4 h1:+otarDOeSZzzbTCr9CllAOQCQNpaf/HI41iDvWWUo/w=
github.com/linuxsuren/go-cli-alias v0.0.4/go.mod h1:dfwOx8H0iVpdS9gtLC80GCC4cvDvzWejxjxXn7sFWUs=
github.com/linuxsuren/go-cli-plugin v0.0.1/go.mod h1:uyO09KK8otYfDV5LVTfcWX2UbAi3kEz3PrkdfIxnDlg=
github.com/linuxsuren/go-cli-alias v0.0.5 h1:8FuE+z9Gvp6UIxV5ojl+RQ+UazoxGR92OWwrs9z0+RM=
github.com/linuxsuren/go-cli-alias v0.0.5/go.mod h1:Sa7xNUI72BgHTcywDU8MXVSH1q72SLdMALZSSANwuUM=
github.com/linuxsuren/http-downloader v0.0.2-0.20201207132639-19888a6beaec h1:N6xw+W4IvgOV0cmhE7iUWKHNZqMUXlT3in+1ORmqIGo=
github.com/linuxsuren/http-downloader v0.0.2-0.20201207132639-19888a6beaec/go.mod h1:zRZY9FCDBuYNDxbI2Ny5suasZsMk7J6q9ecQ3V3PIqI=
github.com/linuxsuren/http-downloader v0.0.6 h1:JuCgWVT4/pw8MAhYe+ngE7BwcO575L1aPDc9Fgx+2ig=
Expand Down
37 changes: 27 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"fmt"
ext "github.com/linuxsuren/cobra-extension"
extver "github.com/linuxsuren/cobra-extension/version"
aliasCmd "github.com/linuxsuren/go-cli-alias/pkg/cmd"
"github.com/linuxsuren/ks/kubectl-plugin/entrypoint"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"os"
)
Expand All @@ -14,24 +16,39 @@ const (
TargetCLI = "kubectl"
// AliasCLI represents the alias CLI which is ks
AliasCLI = "ks"
// KubernetesType is the env name for Kubernetes type
KubernetesType = "kubernetes_type"
)

func main() {
cmd := aliasCmd.CreateDefaultCmd(TargetCLI, AliasCLI)
kType := os.Getenv(KubernetesType)
var cmd *cobra.Command
var targetCommand string

switch kType {
case "k3s":
targetCommand = fmt.Sprintf("k3s %s", TargetCLI)
default:
targetCommand = TargetCLI
}

cmd = aliasCmd.CreateDefaultCmd(TargetCLI, AliasCLI)
cmd.AddCommand(extver.NewVersionCmd("linuxsuren", AliasCLI, AliasCLI, nil))

aliasCmd.AddAliasCmd(cmd, getDefault())
cmd.AddCommand(ext.NewCompletionCmd(cmd))

// add all the sub-commands from kubectl-ks
kubectlPluginCmdRoot := entrypoint.NewCmdKS(genericclioptions.IOStreams{
In: os.Stdin,
Out: os.Stdout,
ErrOut: os.Stderr,
})
kubectlPluginCmds := kubectlPluginCmdRoot.Commands()
cmd.AddCommand(kubectlPluginCmds...)
// need to figure out how to connect with k3s before enable below features
if kType != "k3s" {
// add all the sub-commands from kubectl-ks
kubectlPluginCmdRoot := entrypoint.NewCmdKS(genericclioptions.IOStreams{
In: os.Stdin,
Out: os.Stdout,
ErrOut: os.Stderr,
})
kubectlPluginCmds := kubectlPluginCmdRoot.Commands()
cmd.AddCommand(kubectlPluginCmds...)
}

aliasCmd.Execute(cmd, TargetCLI, getDefault(), nil)
aliasCmd.Execute(cmd, targetCommand, getDefault(), nil)
}

0 comments on commit 8a0cc13

Please sign in to comment.