func NewCmdRun(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "run NAME --image=image [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json]", // run-container is deprecated Aliases: []string{"run-container"}, Short: "Run a particular image on the cluster.", Long: run_long, Example: run_example, Run: func(cmd *cobra.Command, args []string) { err := Run(f, out, cmd, args) cmdutil.CheckErr(err) }, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().String("generator", "run/v1", "The name of the API generator to use. Default is 'run-controller/v1'.") cmd.Flags().String("image", "", "The image for the container to run.") cmd.MarkFlagRequired("image") cmd.Flags().IntP("replicas", "r", 1, "Number of replicas to create for this container. Default is 1.") cmd.Flags().Bool("dry-run", false, "If true, only print the object that would be sent, without sending it.") cmd.Flags().String("overrides", "", "An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.") cmd.Flags().Int("port", -1, "The port that this container exposes.") cmd.Flags().Int("hostport", -1, "The host port mapping for the container port. To demonstrate a single-machine container.") cmd.Flags().StringP("labels", "l", "", "Labels to apply to the pod(s).") return cmd }
func NewCmdDescribe(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "describe (RESOURCE NAME | RESOURCE/NAME)", Short: "Show details of a specific resource", Long: `Show details of a specific resource. This command joins many API calls together to form a detailed description of a given resource.`, Example: `// Describe a node $ qingctl describe nodes qingyuan-minion-emt8.c.myproject.internal // Describe a pod $ qingctl describe pods/nginx // Describe pods by label name=myLabel $ qingctl describe po -l name=myLabel`, Run: func(cmd *cobra.Command, args []string) { err := RunDescribe(f, out, cmd, args) cmdutil.CheckErr(err) }, ValidArgs: qingctl.DescribableResources(), } cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on") return cmd }
func NewCmdExposeService(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "expose RESOURCE NAME --port=port [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--public-ip=ip] [--type=type]", Short: "Take a replicated application and expose it as QingYuan Service", Long: expose_long, Example: expose_example, Run: func(cmd *cobra.Command, args []string) { err := RunExpose(f, out, cmd, args) cmdutil.CheckErr(err) }, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().String("generator", "service/v1", "The name of the API generator to use. Default is 'service/v1'.") cmd.Flags().String("protocol", "TCP", "The network protocol for the service to be created. Default is 'tcp'.") cmd.Flags().Int("port", -1, "The port that the service should serve on. Required.") cmd.MarkFlagRequired("port") cmd.Flags().String("type", "", "Type for this service: ClusterIP, NodePort, or LoadBalancer. Default is 'ClusterIP' unless --create-external-load-balancer is specified.") cmd.Flags().Bool("create-external-load-balancer", false, "If true, create an external load balancer for this service (trumped by --type). Implementation is cloud provider dependent. Default is 'false'.") cmd.Flags().String("selector", "", "A label selector to use for this service. If empty (the default) infer the selector from the replication controller.") cmd.Flags().StringP("labels", "l", "", "Labels to apply to the service created by this call.") cmd.Flags().Bool("dry-run", false, "If true, only print the object that would be sent, without creating it.") cmd.Flags().String("container-port", "", "Synonym for --target-port") cmd.Flags().String("target-port", "", "Name or number for the port on the container that the service should direct traffic to. Optional.") cmd.Flags().String("public-ip", "", "Name of a public IP address to set for the service. The service will be assigned this IP in addition to its generated service IP.") cmd.Flags().String("overrides", "", "An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.") cmd.Flags().String("name", "", "The name for the newly created object.") return cmd }
func NewCmdCreate(f *cmdutil.Factory, out io.Writer) *cobra.Command { var filenames util.StringList cmd := &cobra.Command{ Use: "create -f FILENAME", Short: "Create a resource by filename or stdin", Long: create_long, Example: create_example, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(ValidateArgs(cmd, args)) cmdutil.CheckErr(RunCreate(f, out, filenames)) }, } usage := "Filename, directory, or URL to file to use to create the resource" qingctl.AddJsonFilenameFlag(cmd, &filenames, usage) cmd.MarkFlagRequired("filename") return cmd }
func NewCmdVersion(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "version", Short: "Print the client and server version information.", Run: func(cmd *cobra.Command, args []string) { err := RunVersion(f, out, cmd) cmdutil.CheckErr(err) }, } cmd.Flags().BoolP("client", "c", false, "Client version only (no server required).") return cmd }
func NewCmdApiVersions(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "api-versions", // apiversions is deprecated. Aliases: []string{"apiversions"}, Short: "Print available API versions.", Run: func(cmd *cobra.Command, args []string) { err := RunApiVersions(f, out) cmdutil.CheckErr(err) }, } return cmd }
// TODO remove once people have been given enough time to notice func NewCmdNamespace(out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "namespace [namespace]", Short: "SUPERCEDED: Set and view the current QingYuan namespace", Long: `SUPERCEDED: Set and view the current QingYuan namespace scope for command line requests. namespace has been superceded by the context.namespace field of .qingconfig files. See 'qingctl config set-context --help' for more details. `, Run: func(cmd *cobra.Command, args []string) { util.CheckErr(fmt.Errorf("namespace has been superceded by the context.namespace field of .qingconfig files. See 'qingctl config set-context --help' for more details.")) }, } return cmd }
func NewCmdPortForward(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "port-forward -p POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]", Short: "Forward one or more local ports to a pod.", Long: "Forward one or more local ports to a pod.", Example: portforward_example, Run: func(cmd *cobra.Command, args []string) { err := RunPortForward(f, cmd, args, &defaultPortForwarder{}) cmdutil.CheckErr(err) }, } cmd.Flags().StringP("pod", "p", "", "Pod name") cmd.MarkFlagRequired("pod") // TODO support UID return cmd }
// NewCmdLog creates a new pod log command func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "logs [-f] [-p] POD [CONTAINER]", Short: "Print the logs for a container in a pod.", Long: "Print the logs for a container in a pod. If the pod has only one container, the container name is optional.", Example: log_example, Run: func(cmd *cobra.Command, args []string) { err := RunLog(f, out, cmd, args) cmdutil.CheckErr(err) }, Aliases: []string{"log"}, } cmd.Flags().BoolP("follow", "f", false, "Specify if the logs should be streamed.") cmd.Flags().Bool("interactive", true, "If true, prompt the user for input when required. Default true.") cmd.Flags().BoolP("previous", "p", false, "If true, print the logs for the previous instance of the container in a pod if it exists.") return cmd }
func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "label [--overwrite] RESOURCE NAME KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Short: "Update the labels on a resource", Long: fmt.Sprintf(label_long, util.LabelValueMaxLength), Example: label_example, Run: func(cmd *cobra.Command, args []string) { err := RunLabel(f, out, cmd, args) cmdutil.CheckErr(err) }, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().Bool("overwrite", false, "If true, allow labels to be overwritten, otherwise reject label updates that overwrite existing labels.") cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on") cmd.Flags().Bool("all", false, "select all resources in the namespace of the specified resource types") cmd.Flags().String("resource-version", "", "If non-empty, the labels update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource.") return cmd }
func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command { params := &execParams{} cmd := &cobra.Command{ Use: "exec POD -c CONTAINER -- COMMAND [args...]", Short: "Execute a command in a container.", Long: "Execute a command in a container.", Example: exec_example, Run: func(cmd *cobra.Command, args []string) { err := RunExec(f, cmd, cmdIn, cmdOut, cmdErr, params, args, &defaultRemoteExecutor{}) cmdutil.CheckErr(err) }, } cmd.Flags().StringVarP(¶ms.podName, "pod", "p", "", "Pod name") // TODO support UID cmd.Flags().StringVarP(¶ms.containerName, "container", "c", "", "Container name") cmd.Flags().BoolVarP(¶ms.stdin, "stdin", "i", false, "Pass stdin to the container") cmd.Flags().BoolVarP(¶ms.tty, "tty", "t", false, "Stdin is a TTY") return cmd }
func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command { var filenames util.StringList cmd := &cobra.Command{ Use: "delete ([-f FILENAME] | (RESOURCE [(ID | -l label | --all)]", Short: "Delete a resource by filename, stdin, resource and ID, or by resources and label selector.", Long: delete_long, Example: delete_example, Run: func(cmd *cobra.Command, args []string) { err := RunDelete(f, out, cmd, args, filenames) cmdutil.CheckErr(err) }, } usage := "Filename, directory, or URL to a file containing the resource to delete." qingctl.AddJsonFilenameFlag(cmd, &filenames, usage) cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on.") cmd.Flags().Bool("all", false, "[-all] to select all the specified resources.") cmd.Flags().Bool("ignore-not-found", false, "Treat \"resource not found\" as a successful delete.") cmd.Flags().Bool("cascade", true, "If true, cascade the delete resources managed by this resource (e.g. Pods created by a ReplicationController). Default true.") cmd.Flags().Int("grace-period", -1, "Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.") cmd.Flags().Duration("timeout", 0, "The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object") return cmd }
func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command { flags := &struct { Filenames util.StringList }{} cmd := &cobra.Command{ Use: "stop (-f FILENAME | RESOURCE (ID | -l label | --all))", Short: "Gracefully shut down a resource by id or filename.", Long: stop_long, Example: stop_example, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(RunStop(f, cmd, args, flags.Filenames, out)) }, } usage := "Filename, directory, or URL to file of resource(s) to be stopped." qingctl.AddJsonFilenameFlag(cmd, &flags.Filenames, usage) cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on.") cmd.Flags().Bool("all", false, "[-all] to select all the specified resources.") cmd.Flags().Bool("ignore-not-found", false, "Treat \"resource not found\" as a successful stop.") cmd.Flags().Int("grace-period", -1, "Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.") cmd.Flags().Duration("timeout", 0, "The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object") return cmd }
// NewCmdGet creates a command object for the generic "get" action, which // retrieves one or more resources from a server. func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command { p := qingctl.NewHumanReadablePrinter(false, false, []string{}) validArgs := p.HandledResources() cmd := &cobra.Command{ Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)", Short: "Display one or many resources", Long: get_long, Example: get_example, Run: func(cmd *cobra.Command, args []string) { err := RunGet(f, out, cmd, args) cmdutil.CheckErr(err) }, ValidArgs: validArgs, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on") cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes.") cmd.Flags().Bool("watch-only", false, "Watch for changes to the requested object(s), without listing/getting first.") cmd.Flags().Bool("all-namespaces", false, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.") qingctl.AddLabelsToColumnsFlag(cmd, &util.StringList{}, "Accepts a comma separated list of labels that are going to be presented as columns. Names are case-sensitive. You can also use multiple flag statements like -L label1 -L label2...") return cmd }
func NewCmdProxy(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix]", Short: "Run a proxy to the QingYuan API server", Long: `To proxy all of the qingyuan api and nothing else, use: qingctl proxy --api-prefix=/ To proxy only part of the qingyuan api and also some static files: qingctl proxy --www=/my/files --www-prefix=/static/ --api-prefix=/api/ The above lets you 'curl localhost:8001/api/v1/pods'. To proxy the entire qingyuan api at a different root, use: qingctl proxy --api-prefix=/custom/ The above lets you 'curl localhost:8001/custom/api/v1/pods' `, Example: proxy_example, Run: func(cmd *cobra.Command, args []string) { err := RunProxy(f, out, cmd) cmdutil.CheckErr(err) }, } cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the specified prefix.") cmd.Flags().StringP("www-prefix", "P", "/static/", "Prefix to serve static files under, if static file directory is specified.") cmd.Flags().StringP("api-prefix", "", "/api/", "Prefix to serve the proxied API under.") cmd.Flags().String("accept-paths", qingctl.DefaultPathAcceptRE, "Regular expression for paths that the proxy should accept.") cmd.Flags().String("reject-paths", qingctl.DefaultPathRejectRE, "Regular expression for paths that the proxy should reject.") cmd.Flags().String("accept-hosts", qingctl.DefaultHostAcceptRE, "Regular expression for hosts that the proxy should accept.") cmd.Flags().String("reject-methods", qingctl.DefaultMethodRejectRE, "Regular expression for HTTP methods that the proxy should reject.") cmd.Flags().IntP("port", "p", 8001, "The port on which to run the proxy.") cmd.Flags().Bool("disable-filter", false, "If true, disable request filtering in the proxy. This is dangerous, and can leave you vulnerable to XSRF attacks. Use with caution.") return cmd }
func NewCmdRollingUpdate(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE | -f NEW_CONTROLLER_SPEC)", // rollingupdate is deprecated. Aliases: []string{"rollingupdate"}, Short: "Perform a rolling update of the given ReplicationController.", Long: rollingUpdate_long, Example: rollingUpdate_example, Run: func(cmd *cobra.Command, args []string) { err := RunRollingUpdate(f, out, cmd, args) cmdutil.CheckErr(err) }, } cmd.Flags().String("update-period", updatePeriod, `Time to wait between updating pods. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`) cmd.Flags().String("poll-interval", pollInterval, `Time delay between polling for replication controller status after the update. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`) cmd.Flags().String("timeout", timeout, `Max time to wait for a replication controller to update before giving up. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`) cmd.Flags().StringP("filename", "f", "", "Filename or URL to file to use to create the new replication controller.") cmd.Flags().String("image", "", "Image to use for upgrading the replication controller. Can not be used with --filename/-f") cmd.Flags().String("deployment-label-key", "deployment", "The key to use to differentiate between two different controllers, default 'deployment'. Only relevant when --image is specified, ignored otherwise") cmd.Flags().Bool("dry-run", false, "If true, print out the changes that would be made, but don't actually make them.") cmd.Flags().Bool("rollback", false, "If true, this is a request to abort an existing rollout that is partially rolled out. It effectively reverses current and next and runs a rollout") cmdutil.AddPrinterFlags(cmd) return cmd }