mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Make kubectl stop take -f flag (for filename|url|directory)
This commit is contained in:
parent
59541e94f2
commit
b786c116b6
@ -416,7 +416,7 @@ Additional help topics:
|
|||||||
kubectl rollingupdate Perform a rolling update of the given ReplicationController.
|
kubectl rollingupdate Perform a rolling update of the given ReplicationController.
|
||||||
kubectl resize Set a new size for a Replication Controller.
|
kubectl resize Set a new size for a Replication Controller.
|
||||||
kubectl run-container Run a particular image on the cluster.
|
kubectl run-container Run a particular image on the cluster.
|
||||||
kubectl stop Gracefully shut down a resource.
|
kubectl stop Gracefully shut down a resource by id or filename.
|
||||||
kubectl expose Take a replicated application and expose it as Kubernetes Service
|
kubectl expose Take a replicated application and expose it as Kubernetes Service
|
||||||
kubectl label Update the labels on a resource
|
kubectl label Update the labels on a resource
|
||||||
|
|
||||||
@ -986,7 +986,7 @@ Global Flags:
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### stop
|
#### stop
|
||||||
Gracefully shut down a resource.
|
Gracefully shut down a resource by id or filename.
|
||||||
|
|
||||||
Attempts to shut down and delete a resource that supports graceful termination.
|
Attempts to shut down and delete a resource that supports graceful termination.
|
||||||
If the resource is resizable it will be resized to 0 before deletion.
|
If the resource is resizable it will be resized to 0 before deletion.
|
||||||
@ -996,10 +996,18 @@ Examples:
|
|||||||
// Shut down foo.
|
// Shut down foo.
|
||||||
$ kubectl stop replicationcontroller foo
|
$ kubectl stop replicationcontroller foo
|
||||||
|
|
||||||
|
// Shut down the service defined in service.json
|
||||||
|
$ kubectl stop -f service.json
|
||||||
|
|
||||||
|
// Shut down all resources in the path/to/resources directory
|
||||||
|
$ kubectl stop -f path/to/resources
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
kubectl stop <resource> <id> [flags]
|
kubectl stop (<resource> <id>|-f filename) [flags]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
-f, --filename=[]: Filename, directory, or URL to file of resource(s) to be stopped
|
||||||
|
|
||||||
Global Flags:
|
Global Flags:
|
||||||
--alsologtostderr=false: log to standard error as well as files
|
--alsologtostderr=false: log to standard error as well as files
|
||||||
|
@ -20,15 +20,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Factory) NewCmdStop(out io.Writer) *cobra.Command {
|
func (f *Factory) NewCmdStop(out io.Writer) *cobra.Command {
|
||||||
|
flags := &struct {
|
||||||
|
Filenames util.StringList
|
||||||
|
}{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "stop <resource> <id>",
|
Use: "stop (<resource> <id>|-f filename)",
|
||||||
Short: "Gracefully shut down a resource.",
|
Short: "Gracefully shut down a resource by id or filename.",
|
||||||
Long: `Gracefully shut down a resource.
|
Long: `Gracefully shut down a resource by id or filename.
|
||||||
|
|
||||||
Attempts to shut down and delete a resource that supports graceful termination.
|
Attempts to shut down and delete a resource that supports graceful termination.
|
||||||
If the resource is resizable it will be resized to 0 before deletion.
|
If the resource is resizable it will be resized to 0 before deletion.
|
||||||
@ -36,22 +40,38 @@ If the resource is resizable it will be resized to 0 before deletion.
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
// Shut down foo.
|
// Shut down foo.
|
||||||
$ kubectl stop replicationcontroller foo`,
|
$ kubectl stop replicationcontroller foo
|
||||||
|
|
||||||
|
// Shut down the service defined in service.json
|
||||||
|
$ kubectl stop -f service.json
|
||||||
|
|
||||||
|
// Shut down all resources in the path/to/resources directory
|
||||||
|
$ kubectl stop -f path/to/resources`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) != 2 {
|
|
||||||
usageError(cmd, "<resource> <id>")
|
|
||||||
}
|
|
||||||
cmdNamespace, err := f.DefaultNamespace(cmd)
|
cmdNamespace, err := f.DefaultNamespace(cmd)
|
||||||
mapper, _ := f.Object(cmd)
|
|
||||||
mapping, namespace, name := util.ResourceFromArgs(cmd, args, mapper, cmdNamespace)
|
|
||||||
|
|
||||||
reaper, err := f.Reaper(cmd, mapping)
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
mapper, typer := f.Object(cmd)
|
||||||
|
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand(cmd)).
|
||||||
|
ContinueOnError().
|
||||||
|
NamespaceParam(cmdNamespace).RequireNamespace().
|
||||||
|
ResourceTypeOrNameArgs(false, args...).
|
||||||
|
FilenameParam(flags.Filenames...).
|
||||||
|
Flatten().
|
||||||
|
Do()
|
||||||
|
checkErr(r.Err())
|
||||||
|
|
||||||
s, err := reaper.Stop(namespace, name)
|
r.Visit(func(info *resource.Info) error {
|
||||||
|
reaper, err := f.Reaper(cmd, info.Mapping)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
s, err := reaper.Stop(info.Namespace, info.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
fmt.Fprintf(out, "%s\n", s)
|
fmt.Fprintf(out, "%s\n", s)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file of resource(s) to be stopped")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user