2015-01-22 17:46:38 +00:00
/ *
2016-06-03 00:25:58 +00:00
Copyright 2014 The Kubernetes Authors .
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 (
2015-11-11 23:09:37 +00:00
"fmt"
2015-01-22 17:46:38 +00:00
"io"
2016-05-20 17:49:56 +00:00
"github.com/renstrom/dedent"
2015-08-05 22:05:17 +00:00
"github.com/spf13/cobra"
2015-08-05 22:03:47 +00:00
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
2015-01-22 17:46:38 +00:00
)
2016-05-20 17:49:56 +00:00
var (
stop_long = dedent . Dedent ( `
Deprecated : Gracefully shut down a resource by name or filename .
2015-07-29 09:19:18 +00:00
2016-05-20 17:49:56 +00:00
The stop command is deprecated , all its functionalities are covered by delete command .
See ' kubectl delete -- help ' for more details .
2015-01-22 17:46:38 +00:00
2016-05-20 17:49:56 +00:00
Attempts to shut down and delete a resource that supports graceful termination .
If the resource is scalable it will be scaled to 0 before deletion . ` )
stop_example = dedent . Dedent ( `
# Shut down foo .
kubectl stop replicationcontroller foo
2015-02-03 17:59:21 +00:00
2016-05-20 17:49:56 +00:00
# Stop pods and services with label name = myLabel .
kubectl stop pods , services - l name = myLabel
2015-03-10 12:21:49 +00:00
2016-05-20 17:49:56 +00:00
# Shut down the service defined in service . json
kubectl stop - f service . json
2015-02-14 00:28:39 +00:00
2016-05-20 17:49:56 +00:00
# Shut down all resources in the path / to / resources directory
kubectl stop - f path / to / resources ` )
2015-02-20 21:28:43 +00:00
)
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 {
2016-08-17 18:28:07 +00:00
options := & resource . FilenameOptions { }
2015-08-14 18:46:43 +00:00
2015-02-20 21:28:43 +00:00
cmd := & cobra . Command {
2015-11-11 23:09:37 +00:00
Use : "stop (-f FILENAME | TYPE (NAME | -l label | --all))" ,
2016-06-07 17:38:04 +00:00
Short : "Deprecated: Gracefully shut down a resource by name or filename" ,
2015-11-11 23:09:37 +00:00
Long : stop_long ,
Example : stop_example ,
Deprecated : fmt . Sprintf ( "use %q instead." , "delete" ) ,
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 ) )
2015-08-14 18:46:43 +00:00
cmdutil . CheckErr ( RunStop ( f , cmd , args , out , options ) )
2015-01-22 17:46:38 +00:00
} ,
}
2016-08-17 18:28:07 +00:00
usage := "of resource(s) to be stopped."
cmdutil . AddFilenameOptionFlags ( cmd , options , 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 )
2016-03-10 01:27:19 +00:00
cmdutil . AddInclude3rdPartyFlags ( cmd )
2015-01-22 17:46:38 +00:00
return cmd
}
2015-04-23 04:15:15 +00:00
2016-08-17 18:28:07 +00:00
func RunStop ( f * cmdutil . Factory , cmd * cobra . Command , args [ ] string , out io . Writer , options * resource . FilenameOptions ) 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
}
2015-08-05 14:21:47 +00:00
2016-09-16 19:50:34 +00:00
mapper , typer := f . Object ( )
2015-12-21 05:37:49 +00:00
r := resource . NewBuilder ( mapper , typer , resource . ClientMapperFunc ( f . ClientForMapping ) , f . Decoder ( true ) ) .
2015-04-23 04:15:15 +00:00
ContinueOnError ( ) .
2015-06-26 20:49:34 +00:00
NamespaceParam ( cmdNamespace ) . DefaultNamespace ( ) .
2015-04-23 04:15:15 +00:00
ResourceTypeOrNameArgs ( false , args ... ) .
2016-08-17 18:28:07 +00:00
FilenameParam ( enforceNamespace , options ) .
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-08-05 14:21:47 +00:00
shortOutput := cmdutil . GetFlagString ( cmd , "output" ) == "name"
2016-08-08 21:24:44 +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 , false )
2015-04-23 04:15:15 +00:00
}