Skip to content

Commit

Permalink
Merge pull request kosmos-io#88 from ONE7live/main
Browse files Browse the repository at this point in the history
feat: Kosmosctl supports knode join and unjoin
  • Loading branch information
kosmos-robot authored Oct 8, 2023
2 parents 32cb9c7 + 9ec1ffc commit 87fbd14
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 199 deletions.
8 changes: 8 additions & 0 deletions examples/knode-demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kosmos.io/v1alpha1
kind: Knode
metadata:
name: knode-worker1
spec:
nodeName: knode-worker1
type: k8s
kubeconfig: {{ .cluster-kubeconfig }}
27 changes: 18 additions & 9 deletions pkg/kosmosctl/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@ import (
ctlget "k8s.io/kubectl/pkg/cmd/get"
ctlutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"

"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
)

const (
ClustersGroupResource = "clusters.kosmos.io"
ClusterNodesGroupResource = "clusternodes.kosmos.io"
KnodesGroupResource = "knodes.kosmos.io"
)

type CommandGetOptions struct {
Cluster string
ClusterNode string

Namespace string

GetOptions *ctlget.GetOptions
}

// NewCmdGet Display resources from the Clusterlink control plane.
// NewCmdGet Display resources from the Kosmos control plane.
func NewCmdGet(f ctlutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewCommandGetOptions(streams)

cmd := &cobra.Command{
Use: fmt.Sprintf("get [(-o|--output=)%s] (TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags]", strings.Join(o.GetOptions.PrintFlags.AllowedFormats(), "|")),
Short: i18n.T("Display resources from the Clusterlink control plane"),
Short: i18n.T("Display resources from the Kosmos control plane"),
Long: "",
Example: "",
SilenceUsage: true,
Expand All @@ -43,6 +48,8 @@ func NewCmdGet(f ctlutil.Factory, streams genericclioptions.IOStreams) *cobra.Co
}

o.GetOptions.PrintFlags.AddFlags(cmd)
flags := cmd.Flags()
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "If present, the namespace scope for this CLI request.")

return cmd
}
Expand All @@ -61,6 +68,8 @@ func (o *CommandGetOptions) Complete(f ctlutil.Factory, cmd *cobra.Command, args
return fmt.Errorf("kosmosctl get complete error, options failed: %s", err)
}

o.GetOptions.Namespace = o.Namespace

return nil
}

Expand All @@ -74,13 +83,13 @@ func (o *CommandGetOptions) Validate() error {
}

func (o *CommandGetOptions) Run(f ctlutil.Factory, cmd *cobra.Command, args []string) error {
for i := range args {
switch args[i] {
case "cluster", "clusters":
args[i] = ClustersGroupResource
case "clusternode", "clusternodes":
args[i] = ClusterNodesGroupResource
}
switch args[0] {
case "cluster", "clusters":
args[0] = ClustersGroupResource
case "clusternode", "clusternodes":
args[0] = ClusterNodesGroupResource
case "knode", "knodes":
args[0] = KnodesGroupResource
}

err := o.GetOptions.Run(f, cmd, args)
Expand Down
Loading

0 comments on commit 87fbd14

Please sign in to comment.