Skip to content

Commit

Permalink
Fix the command cannot use due to the k8s client missing (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Mar 9, 2021
1 parent 3c49c2c commit 9868ad5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
13 changes: 8 additions & 5 deletions kubectl-plugin/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ KubeSphere supports multiple types Pipeline. Currently, this CLI only support th
_ = cmd.RegisterFlagCompletionFunc("type", common.ArrayCompletion("pipeline", "multi-branch-pipeline"))
_ = cmd.RegisterFlagCompletionFunc("scm-type", common.ArrayCompletion("gitlab", "github"))

if wsList, err := opt.getWorkspaceNameList(); err == nil {
_ = cmd.RegisterFlagCompletionFunc("ws", common.ArrayCompletion(wsList...))
}
if projectList, err := opt.getDevOpsProjectGenerateNameList(); err == nil {
_ = cmd.RegisterFlagCompletionFunc("project", common.ArrayCompletion(projectList...))
if client != nil {
// these features rely on the k8s client, ignore it if the client is nil
if wsList, err := opt.getWorkspaceNameList(); err == nil {
_ = cmd.RegisterFlagCompletionFunc("ws", common.ArrayCompletion(wsList...))
}
if projectList, err := opt.getDevOpsProjectGenerateNameList(); err == nil {
_ = cmd.RegisterFlagCompletionFunc("project", common.ArrayCompletion(projectList...))
}
}
return
}
Expand Down
16 changes: 13 additions & 3 deletions kubectl-plugin/token/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package token

import (
"errors"
"fmt"
"github.com/spf13/cobra"
"k8s.io/client-go/dynamic"
Expand All @@ -13,9 +14,11 @@ import (
func NewTokenCmd(client dynamic.Interface, clientset *kubernetes.Clientset) (cmd *cobra.Command) {
opt := &option{}
cmd = &cobra.Command{
Use: "token",
Short: "Print the kubectl token of KubeSphere",
RunE: opt.runE,
Use: "token",
Short: "Print the kubectl token of KubeSphere",
Example: "ks token --host yourServer",
PreRunE: opt.preRunE,
RunE: opt.runE,
}

flags := cmd.Flags()
Expand All @@ -35,6 +38,13 @@ type option struct {
Port int
}

func (o *option) preRunE(cmd *cobra.Command, args []string) (err error) {
if o.Host == "" {
err = errors.New("cannot print the token due to --host is empty")
}
return
}

func (o *option) runE(cmd *cobra.Command, args []string) (err error) {
var name string
if name, err = o.getSecretName(); err != nil {
Expand Down

0 comments on commit 9868ad5

Please sign in to comment.