2015-01-22 17:46:38 +00:00
/ *
2015-05-01 16:19:44 +00:00
Copyright 2014 The Kubernetes Authors All rights reserved .
2015-01-22 17:46:38 +00:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
package cmd
import (
"io"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/util"
2015-01-22 17:46:38 +00:00
"github.com/spf13/cobra"
)
2015-02-20 21:28:43 +00:00
const (
2015-07-29 09:19:18 +00:00
stop_long = ` Deprecated : Gracefully shut down a resource by name or filename .
2015-07-06 11:31:27 +00:00
The stop command is deprecated , all its functionalities are covered by delete command .
2015-07-29 09:19:18 +00:00
See ' kubectl delete -- help ' for more details .
2015-01-22 17:46:38 +00:00
2015-02-03 17:59:21 +00:00
Attempts to shut down and delete a resource that supports graceful termination .
2015-05-21 21:10:25 +00:00
If the resource is scalable it will be scaled to 0 before deletion . `
2015-02-20 21:28:43 +00:00
stop_example = ` // Shut down foo.
$ kubectl stop replicationcontroller foo
2015-02-03 17:59:21 +00:00
2015-03-10 12:21:49 +00:00
// Stop pods and services with label name=myLabel.
$ kubectl stop pods , services - l name = myLabel
2015-02-20 21:28:43 +00:00
// Shut down the service defined in service.json
$ kubectl stop - f service . json
2015-02-14 00:28:39 +00:00
2015-02-20 21:28:43 +00:00
// Shut down all resources in the path/to/resources directory
$ kubectl stop - f path / to / resources `
)
2015-02-14 00:28:39 +00:00
2015-04-07 18:21:25 +00:00
func NewCmdStop ( f * cmdutil . Factory , out io . Writer ) * cobra . Command {
2015-02-20 21:28:43 +00:00
flags := & struct {
Filenames util . StringList
} { }
cmd := & cobra . Command {
2015-07-06 11:31:27 +00:00
Use : "stop (-f FILENAME | TYPE (NAME | -l label | --all))" ,
2015-07-29 09:19:18 +00:00
Short : "Deprecated: Gracefully shut down a resource by name or filename." ,
2015-02-20 21:28:43 +00:00
Long : stop_long ,
Example : stop_example ,
2015-01-22 17:46:38 +00:00
Run : func ( cmd * cobra . Command , args [ ] string ) {
2015-07-01 22:47:43 +00:00
cmdutil . CheckErr ( cmdutil . ValidateOutputArgs ( cmd ) )
shortOutput := cmdutil . GetFlagString ( cmd , "output" ) == "name"
cmdutil . CheckErr ( RunStop ( f , cmd , args , flags . Filenames , out , shortOutput ) )
2015-01-22 17:46:38 +00:00
} ,
}
2015-05-21 17:01:34 +00:00
usage := "Filename, directory, or URL to file of resource(s) to be stopped."
2015-03-29 03:38:46 +00:00
kubectl . AddJsonFilenameFlag ( cmd , & flags . Filenames , usage )
2015-05-21 17:01:34 +00:00
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." )
2015-04-28 12:21:57 +00:00
cmd . Flags ( ) . Int ( "grace-period" , - 1 , "Period of time in seconds given to the resource to terminate gracefully. Ignored if negative." )
2015-05-29 23:16:30 +00:00
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" )
2015-07-01 22:47:43 +00:00
cmdutil . AddOutputFlagsForMutation ( cmd )
2015-01-22 17:46:38 +00:00
return cmd
}
2015-04-23 04:15:15 +00:00
2015-07-01 22:47:43 +00:00
func RunStop ( f * cmdutil . Factory , cmd * cobra . Command , args [ ] string , filenames util . StringList , out io . Writer , shortOutput bool ) error {
2015-06-26 20:49:34 +00:00
cmdNamespace , enforceNamespace , err := f . DefaultNamespace ( )
2015-04-23 04:15:15 +00:00
if err != nil {
return err
}
mapper , typer := f . Object ( )
r := resource . NewBuilder ( mapper , typer , f . ClientMapperForCommand ( ) ) .
ContinueOnError ( ) .
2015-06-26 20:49:34 +00:00
NamespaceParam ( cmdNamespace ) . DefaultNamespace ( ) .
2015-04-23 04:15:15 +00:00
ResourceTypeOrNameArgs ( false , args ... ) .
2015-06-26 20:49:34 +00:00
FilenameParam ( enforceNamespace , filenames ... ) .
2015-04-23 04:15:15 +00:00
SelectorParam ( cmdutil . GetFlagString ( cmd , "selector" ) ) .
SelectAllParam ( cmdutil . GetFlagBool ( cmd , "all" ) ) .
Flatten ( ) .
Do ( )
if r . Err ( ) != nil {
return r . Err ( )
}
2015-07-01 22:47:43 +00:00
return ReapResult ( r , f , out , false , cmdutil . GetFlagBool ( cmd , "ignore-not-found" ) , cmdutil . GetFlagDuration ( cmd , "timeout" ) , cmdutil . GetFlagInt ( cmd , "grace-period" ) , shortOutput , mapper )
2015-04-23 04:15:15 +00:00
}