Unify usage example template of karmadactl
Signed-off-by: lonelyCZ <531187475@qq.com>
This commit is contained in:
parent
7b7ae06392
commit
4908b313b7
|
|
@ -23,7 +23,7 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
|
|||
Use: "init",
|
||||
Short: initShort,
|
||||
Long: initLong,
|
||||
Example: getInitExample(parentCommand),
|
||||
Example: initExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Validate(parentCommand); err != nil {
|
||||
|
|
@ -83,35 +83,34 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func getInitExample(parentCommand string) string {
|
||||
initExample := `
|
||||
# Install Karmada in Kubernetes cluster.
|
||||
# The karmada-apiserver binds the master node's IP by default.
|
||||
` + parentCommand + ` init
|
||||
func initExample(parentCommand string) string {
|
||||
example := `
|
||||
# Install Karmada in Kubernetes cluster
|
||||
# The karmada-apiserver binds the master node's IP by default` + "\n" +
|
||||
fmt.Sprintf("%s init", parentCommand) + `
|
||||
|
||||
# Specify the URL to download CRD tarball.
|
||||
` + parentCommand + ` init --crds https://github.com/karmada-io/karmada/releases/download/v0.10.1/crds.tar.gz
|
||||
# Specify the URL to download CRD tarball` + "\n" +
|
||||
fmt.Sprintf("%s init --crds https://github.com/karmada-io/karmada/releases/download/v1.1.0/crds.tar.gz", parentCommand) + `
|
||||
|
||||
# Specify the local CRD tarball.
|
||||
` + parentCommand + ` init --crds /root/crds.tar.gz
|
||||
# Specify the local CRD tarball` + "\n" +
|
||||
fmt.Sprintf("%s init --crds /root/crds.tar.gz", parentCommand) + `
|
||||
|
||||
# Use PVC to persistent storage etcd data.
|
||||
` + parentCommand + ` init --etcd-storage-mode PVC --storage-classes-name {StorageClassesName}
|
||||
# Use PVC to persistent storage etcd data` + "\n" +
|
||||
fmt.Sprintf("%s init --etcd-storage-mode PVC --storage-classes-name {StorageClassesName}", parentCommand) + `
|
||||
|
||||
# Use hostPath to persistent storage etcd data. For data security, only 1 etcd pod can run in hostPath mode.
|
||||
` + parentCommand + ` init --etcd-storage-mode hostPath --etcd-replicas 1
|
||||
# Use hostPath to persistent storage etcd data. For data security, only 1 etcd pod can run in hostPath mode` + "\n" +
|
||||
fmt.Sprintf("%s init --etcd-storage-mode hostPath --etcd-replicas 1", parentCommand) + `
|
||||
|
||||
# Use hostPath to persistent storage etcd data but select nodes by labels.
|
||||
` + parentCommand + ` init --etcd-storage-mode hostPath --etcd-node-selector-labels karmada.io/etcd=true
|
||||
# Use hostPath to persistent storage etcd data but select nodes by labels` + "\n" +
|
||||
fmt.Sprintf("%s init --etcd-storage-mode hostPath --etcd-node-selector-labels karmada.io/etcd=true", parentCommand) + `
|
||||
|
||||
# Private registry can be specified for all images.
|
||||
` + parentCommand + ` init --etcd-image local.registry.com/library/etcd:3.5.1-0
|
||||
# Private registry can be specified for all images` + "\n" +
|
||||
fmt.Sprintf("%s init --etcd-image local.registry.com/library/etcd:3.5.1-0", parentCommand) + `
|
||||
|
||||
# Deploy highly available(HA) karmada.
|
||||
` + parentCommand + ` init --karmada-apiserver-replicas 3 --etcd-replicas 3 --storage-classes-name PVC --storage-classes-name {StorageClassesName}
|
||||
|
||||
# Specify external IPs(load balancer or HA IP) which used to sign the certificate.
|
||||
` + parentCommand + ` init --cert-external-ip 10.235.1.2 --cert-external-dns www.karmada.io
|
||||
`
|
||||
return initExample
|
||||
# Deploy highly available(HA) karmada` + "\n" +
|
||||
fmt.Sprintf("%s init --karmada-apiserver-replicas 3 --etcd-replicas 3 --storage-classes-name PVC --storage-classes-name {StorageClassesName}", parentCommand) + `
|
||||
|
||||
# Specify external IPs(load balancer or HA IP) which used to sign the certificate` + "\n" +
|
||||
fmt.Sprintf("%s init --cert-external-ip 10.235.1.2 --cert-external-dns www.karmada.io", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,19 +19,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
cordonShort = `Mark cluster as unschedulable`
|
||||
cordonLong = `Mark cluster as unschedulable.`
|
||||
cordonExample = `
|
||||
# Mark cluster "foo" as unschedulable.
|
||||
%s cordon foo
|
||||
`
|
||||
cordonShort = `Mark cluster as unschedulable`
|
||||
cordonLong = `Mark cluster as unschedulable.`
|
||||
|
||||
uncordonShort = `Mark cluster as schedulable`
|
||||
uncordonLong = `Mark cluster as schedulable.`
|
||||
uncordonExample = `
|
||||
# Mark cluster "foo" as schedulable.
|
||||
%s uncordon foo
|
||||
`
|
||||
uncordonShort = `Mark cluster as schedulable`
|
||||
uncordonLong = `Mark cluster as schedulable.`
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -40,13 +32,13 @@ const (
|
|||
)
|
||||
|
||||
// NewCmdCordon defines the `cordon` command that mark cluster as unschedulable.
|
||||
func NewCmdCordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string) *cobra.Command {
|
||||
func NewCmdCordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
||||
opts := CommandCordonOption{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "cordon CLUSTER",
|
||||
Short: cordonShort,
|
||||
Long: cordonLong,
|
||||
Example: fmt.Sprintf(cordonExample, cmdStr),
|
||||
Example: cordonExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -65,14 +57,21 @@ func NewCmdCordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string)
|
|||
return cmd
|
||||
}
|
||||
|
||||
func cordonExample(parentCommand string) string {
|
||||
example := `
|
||||
# Mark cluster "foo" as unschedulable` + "\n" +
|
||||
fmt.Sprintf("%s cordon foo", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// NewCmdUncordon defines the `uncordon` command that mark cluster as schedulable.
|
||||
func NewCmdUncordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string) *cobra.Command {
|
||||
func NewCmdUncordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
||||
opts := CommandCordonOption{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "uncordon CLUSTER",
|
||||
Short: uncordonShort,
|
||||
Long: uncordonLong,
|
||||
Example: fmt.Sprintf(uncordonExample, cmdStr),
|
||||
Example: uncordonExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -91,6 +90,13 @@ func NewCmdUncordon(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string
|
|||
return cmd
|
||||
}
|
||||
|
||||
func uncordonExample(parentCommand string) string {
|
||||
example := `
|
||||
# Mark cluster "foo" as schedulable.` + "\n" +
|
||||
fmt.Sprintf("%s uncordon foo", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// CommandCordonOption holds all command options for cordon and uncordon
|
||||
type CommandCordonOption struct {
|
||||
// global flags
|
||||
|
|
|
|||
|
|
@ -1027,7 +1027,6 @@ func Exists(path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// getExample get examples by cmd type
|
||||
func getExample(parentCommand string) string {
|
||||
example := `
|
||||
# List all pods in ps output format` + "\n" +
|
||||
|
|
|
|||
|
|
@ -25,12 +25,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
joinShort = `Register a cluster to control plane`
|
||||
joinLong = `Join registers a cluster to control plane.`
|
||||
joinExample = `
|
||||
# Join cluster into karamada control plane
|
||||
%s join CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>
|
||||
`
|
||||
joinShort = `Register a cluster to control plane`
|
||||
joinLong = `Join registers a cluster to control plane.`
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -54,14 +50,14 @@ var (
|
|||
var clusterResourceKind = clusterv1alpha1.SchemeGroupVersion.WithKind("Cluster")
|
||||
|
||||
// NewCmdJoin defines the `join` command that registers a cluster.
|
||||
func NewCmdJoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string) *cobra.Command {
|
||||
func NewCmdJoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
||||
opts := CommandJoinOption{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "join CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>",
|
||||
Short: joinShort,
|
||||
Long: joinLong,
|
||||
Example: fmt.Sprintf(joinExample, cmdStr),
|
||||
Example: joinExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -83,6 +79,13 @@ func NewCmdJoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string) *c
|
|||
return cmd
|
||||
}
|
||||
|
||||
func joinExample(parentCommand string) string {
|
||||
example := `
|
||||
# Join cluster into karamada control plane, if '--cluster-context' not specified, take the cluster name as the context` + "\n" +
|
||||
fmt.Sprintf("%s join CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// CommandJoinOption holds all command options.
|
||||
type CommandJoinOption struct {
|
||||
options.GlobalCommandOptions
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func NewCmdLogs(out io.Writer, karmadaConfig KarmadaConfig, parentCommand string
|
|||
Use: logsUsageStr,
|
||||
Short: "Print the logs for a container in a pod in a cluster",
|
||||
SilenceUsage: true,
|
||||
Example: getLogsExample(parentCommand),
|
||||
Example: logsExample(parentCommand),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := o.Complete(karmadaConfig, cmd, args); err != nil {
|
||||
return err
|
||||
|
|
@ -64,8 +64,7 @@ func NewCmdLogs(out io.Writer, karmadaConfig KarmadaConfig, parentCommand string
|
|||
return cmd
|
||||
}
|
||||
|
||||
// getLogsExample logs examples by cmd type
|
||||
func getLogsExample(parentCommand string) string {
|
||||
func logsExample(parentCommand string) string {
|
||||
example := `
|
||||
# Return snapshot logs from pod nginx with only one container in cluster(member1)` + "\n" +
|
||||
fmt.Sprintf("%s logs nginx -C=member1", parentCommand) + `
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func NewCmdPromote(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand
|
|||
Use: "promote <RESOURCE_TYPE> <RESOURCE_NAME> -n <NAME_SPACE> -c <CLUSTER_NAME>",
|
||||
Short: promoteShort,
|
||||
Long: promoteLong,
|
||||
Example: getPromoteExample(parentCommand),
|
||||
Example: promoteExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -68,27 +68,26 @@ func NewCmdPromote(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand
|
|||
return cmd
|
||||
}
|
||||
|
||||
func getPromoteExample(parentCommand string) string {
|
||||
promoteExample := `
|
||||
# Promote deployment(default/nginx) from cluster1 to Karmada.
|
||||
` + parentCommand + ` promote deployment nginx -n default -c cluster1
|
||||
func promoteExample(parentCommand string) string {
|
||||
example := `
|
||||
# Promote deployment(default/nginx) from cluster1 to Karmada` + "\n" +
|
||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1", parentCommand) + `
|
||||
|
||||
# Promote deployment((default/nginx) with gvk from cluster1 to Karmada.
|
||||
` + parentCommand + ` promote deployment.v1.apps nginx -n default -c cluster1
|
||||
# Promote deployment((default/nginx) with gvk from cluster1 to Karmada` + "\n" +
|
||||
fmt.Sprintf("%s promote deployment.v1.apps nginx -n default -c cluster1", parentCommand) + `
|
||||
|
||||
# Dumps the artifacts but does not deploy them to Karmada, same as 'dry run'.
|
||||
` + parentCommand + ` promote deployment nginx -n default -c cluster1 -o yaml|json
|
||||
# Dumps the artifacts but does not deploy them to Karmada, same as 'dry run'` + "\n" +
|
||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 -o yaml|json", parentCommand) + `
|
||||
|
||||
# Promote secret(default/default-token) from cluster1 to Karmada.
|
||||
` + parentCommand + ` promote secret default-token -n default -c cluster1
|
||||
|
||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' to specify the configuration.
|
||||
` + parentCommand + ` promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH>
|
||||
|
||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' and '--cluster-context' to specify the configuration.
|
||||
` + parentCommand + ` promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --cluster-context=<CLUSTER_CONTEXT>
|
||||
`
|
||||
return promoteExample
|
||||
# Promote secret(default/default-token) from cluster1 to Karmada` + "\n" +
|
||||
fmt.Sprintf("%s promote secret default-token -n default -c cluster1", parentCommand) + `
|
||||
|
||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' to specify the configuration` + "\n" +
|
||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH>", parentCommand) + `
|
||||
|
||||
# For clusters with 'Pull' mode, use '--cluster-kubeconfig' and '--cluster-context' to specify the configuration` + "\n" +
|
||||
fmt.Sprintf("%s promote deployment nginx -n default -c cluster1 --cluster-kubeconfig=<CLUSTER_KUBECONFIG_PATH> --cluster-context=<CLUSTER_CONTEXT>", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// CommandPromoteOption holds all command options for promote
|
||||
|
|
|
|||
|
|
@ -34,22 +34,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
taintShort = `Update the taints on one or more clusters.`
|
||||
taintLong = `Update the taints on one or more clusters.`
|
||||
taintExample = `
|
||||
# Update cluster 'foo' with a taint with key 'dedicated' and value 'special-user' and effect 'NoSchedule'
|
||||
# If a taint with that key and effect already exists, its value is replaced as specified
|
||||
%s taint clusters foo dedicated=special-user:NoSchedule
|
||||
|
||||
# Remove from cluster 'foo' the taint with key 'dedicated' and effect 'NoSchedule' if one exists
|
||||
%s taint clusters foo dedicated:NoSchedule-
|
||||
|
||||
# Remove from cluster 'foo' all the taints with key 'dedicated'
|
||||
%s taint clusters foo dedicated-
|
||||
|
||||
# Add to cluster 'foo' a taint with key 'bar' and no value
|
||||
%s taint clusters foo bar:NoSchedule
|
||||
`
|
||||
taintShort = `Update the taints on one or more clusters.`
|
||||
taintLong = `Update the taints on one or more clusters.`
|
||||
)
|
||||
|
||||
// NewCmdTaint defines the `taint` command that mark cluster with taints
|
||||
|
|
@ -60,7 +46,7 @@ func NewCmdTaint(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand st
|
|||
Use: "taint CLUSTER NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N",
|
||||
Short: taintShort,
|
||||
Long: taintLong,
|
||||
Example: getTaintExample(parentCommand),
|
||||
Example: taintExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -82,8 +68,21 @@ func NewCmdTaint(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand st
|
|||
return cmd
|
||||
}
|
||||
|
||||
func getTaintExample(cmdStr string) string {
|
||||
return fmt.Sprintf(taintExample, cmdStr, cmdStr, cmdStr, cmdStr)
|
||||
func taintExample(parentCommand string) string {
|
||||
example := `
|
||||
# Update cluster 'foo' with a taint with key 'dedicated' and value 'special-user' and effect 'NoSchedule'
|
||||
# If a taint with that key and effect already exists, its value is replaced as specified` + "\n" +
|
||||
fmt.Sprintf("%s taint clusters foo dedicated=special-user:NoSchedule", parentCommand) + `
|
||||
|
||||
# Remove from cluster 'foo' the taint with key 'dedicated' and effect 'NoSchedule' if one exists` + "\n" +
|
||||
fmt.Sprintf("%s taint clusters foo dedicated:NoSchedule-", parentCommand) + `
|
||||
|
||||
# Remove from cluster 'foo' all the taints with key 'dedicated'` + "\n" +
|
||||
fmt.Sprintf("%s taint clusters foo dedicated-", parentCommand) + `
|
||||
|
||||
# Add to cluster 'foo' a taint with key 'bar' and no value` + "\n" +
|
||||
fmt.Sprintf("%s taint clusters foo bar:NoSchedule", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// CommandTaintOption holds all command options for taint
|
||||
|
|
|
|||
|
|
@ -23,26 +23,19 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
unjoinShort = `Remove the registration of a cluster from control plane`
|
||||
unjoinLong = `Unjoin removes the registration of a cluster from control plane.`
|
||||
unjoinExample = `
|
||||
# Unjoin cluster from karamada control plane
|
||||
%s unjoin CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>
|
||||
|
||||
# Unjoin cluster from karamada control plane with timeout
|
||||
%s unjoin CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG> --wait 2m
|
||||
`
|
||||
unjoinShort = `Remove the registration of a cluster from control plane`
|
||||
unjoinLong = `Unjoin removes the registration of a cluster from control plane.`
|
||||
)
|
||||
|
||||
// NewCmdUnjoin defines the `unjoin` command that removes registration of a cluster from control plane.
|
||||
func NewCmdUnjoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string) *cobra.Command {
|
||||
func NewCmdUnjoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
||||
opts := CommandUnjoinOption{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "unjoin CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>",
|
||||
Short: unjoinShort,
|
||||
Long: unjoinLong,
|
||||
Example: getUnjoinExample(cmdStr),
|
||||
Example: unjoinExample(parentCommand),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := opts.Complete(args); err != nil {
|
||||
|
|
@ -64,8 +57,17 @@ func NewCmdUnjoin(cmdOut io.Writer, karmadaConfig KarmadaConfig, cmdStr string)
|
|||
return cmd
|
||||
}
|
||||
|
||||
func getUnjoinExample(cmdStr string) string {
|
||||
return fmt.Sprintf(unjoinExample, cmdStr, cmdStr)
|
||||
func unjoinExample(parentCommand string) string {
|
||||
example := `
|
||||
# Unjoin cluster from karamada control plane, but not to remove resources created by karmada in the unjoining cluster` + "\n" +
|
||||
fmt.Sprintf("%s unjoin CLUSTER_NAME", parentCommand) + `
|
||||
|
||||
# Unjoin cluster from karamada control plane and attempt to remove resources created by karmada in the unjoining cluster` + "\n" +
|
||||
fmt.Sprintf("%s unjoin CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG>", parentCommand) + `
|
||||
|
||||
# Unjoin cluster from karamada control plane with timeout` + "\n" +
|
||||
fmt.Sprintf("%s unjoin CLUSTER_NAME --cluster-kubeconfig=<KUBECONFIG> --wait 2m", parentCommand)
|
||||
return example
|
||||
}
|
||||
|
||||
// CommandUnjoinOption holds all command options.
|
||||
|
|
|
|||
Loading…
Reference in New Issue