Merge pull request #26761 from matchstick/dedent

Automatic merge from submit-queue

Dedent

Adding the dedent package and then applying it to the kubectl help commands. Also updating the documentation to reflect the use of dedent.
This commit is contained in:
k8s-merge-robot 2016-06-28 12:50:59 -07:00 committed by GitHub
commit 13bb931b60
51 changed files with 860 additions and 555 deletions

5
Godeps/Godeps.json generated
View File

@ -1773,6 +1773,11 @@
"Comment": "v1.0.0-920-g934dbf8",
"Rev": "934dbf81977c67c521c75492dc1f55ca74dc5b04"
},
{
"ImportPath": "github.com/renstrom/dedent",
"Comment": "v1.0.0-3-g020d11c",
"Rev": "020d11c3b9c0c7a3c2efcc8e5cf5b9ef7bcea21f"
},
{
"ImportPath": "github.com/robfig/cron",
"Comment": "v1-16-g0f39cf7",

29
Godeps/LICENSES generated
View File

@ -57322,6 +57322,35 @@ specific language governing permissions and limitations under the License.
================================================================================
================================================================================
= vendor/github.com/renstrom/dedent licensed under: =
The MIT License (MIT)
Copyright (c) 2015 Peter Renström
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
= vendor/github.com/renstrom/dedent/LICENSE 285693e07a6e1fd790cb3f3b8b5127db -
================================================================================
================================================================================
= vendor/github.com/robfig/cron licensed under: =

View File

@ -279,15 +279,17 @@ type MineConfig struct {
mineLatest bool
}
const (
mineLong = `Some long description
for my command.`
var (
mineLong = dedent.Dedent(`
mine which is described here
with lots of details.`)
mineExample = ` # Run my command's first action
$ %[1]s first
mineExample = dedent.Dedent(`
# Run my command's first action
kubectl mine first_action
# Run my command's second action on latest stuff
$ %[1]s second --latest`
# Run my command's second action on latest stuff
kubectl mine second_action --flag`)
)
// NewCmdMine implements the kubectl mine command.

View File

@ -25,6 +25,7 @@ import (
"strings"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -58,42 +59,43 @@ type AnnotateOptions struct {
recursive bool
}
const (
var (
annotate_resources = `
pod (po), service (svc), replicationcontroller (rc),
node (no), event (ev), componentstatuse (cs),
limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc),
horizontalpodautoscaler (hpa), resourcequota (quota), secret
`
horizontalpodautoscaler (hpa), resourcequota (quota), secret`
annotate_long = `Update the annotations on one or more resources.
annotate_long = dedent.Dedent(`
Update the annotations on one or more resources.
An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data.
It is intended to store non-identifying auxiliary data, especially data manipulated by tools and system extensions.
If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.
An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data.
It is intended to store non-identifying auxiliary data, especially data manipulated by tools and system extensions.
If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.
Possible resources include (case insensitive):` + annotate_resources
Possible resources include (case insensitive):`) + annotate_resources
annotate_example = `# Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
# If the same annotation is set multiple times, only the last value will be applied
kubectl annotate pods foo description='my frontend'
annotate_example = dedent.Dedent(`
# Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
# If the same annotation is set multiple times, only the last value will be applied
kubectl annotate pods foo description='my frontend'
# Update a pod identified by type and name in "pod.json"
kubectl annotate -f pod.json description='my frontend'
# Update a pod identified by type and name in "pod.json"
kubectl annotate -f pod.json description='my frontend'
# Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value.
kubectl annotate --overwrite pods foo description='my frontend running nginx'
# Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value.
kubectl annotate --overwrite pods foo description='my frontend running nginx'
# Update all pods in the namespace
kubectl annotate pods --all description='my frontend running nginx'
# Update all pods in the namespace
kubectl annotate pods --all description='my frontend running nginx'
# Update pod 'foo' only if the resource is unchanged from version 1.
kubectl annotate pods foo description='my frontend running nginx' --resource-version=1
# Update pod 'foo' only if the resource is unchanged from version 1.
kubectl annotate pods foo description='my frontend running nginx' --resource-version=1
# Update pod 'foo' by removing an annotation named 'description' if it exists.
# Does not require the --overwrite flag.
kubectl annotate pods foo description-`
# Update pod 'foo' by removing an annotation named 'description' if it exists.
# Does not require the --overwrite flag.
kubectl annotate pods foo description-`)
)
func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -22,6 +22,7 @@ import (
"time"
"github.com/jonboulle/clockwork"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -50,17 +51,20 @@ const (
triesBeforeBackOff = 1
)
const (
apply_long = `Apply a configuration to a resource by filename or stdin.
The resource will be created if it doesn't exist yet.
To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'.
var (
apply_long = dedent.Dedent(`
Apply a configuration to a resource by filename or stdin.
This resource will be created if it doesn't exist yet.
To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'.
JSON and YAML formats are accepted.`
apply_example = `# Apply the configuration in pod.json to a pod.
kubectl apply -f ./pod.json
JSON and YAML formats are accepted.`)
# Apply the JSON passed into stdin to a pod.
cat pod.json | kubectl apply -f -`
apply_example = dedent.Dedent(`
# Apply the configuration in pod.json to a pod.
kubectl apply -f ./pod.json
# Apply the JSON passed into stdin to a pod.
cat pod.json | kubectl apply -f -`)
)
func NewCmdApply(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -22,6 +22,7 @@ import (
"net/url"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -35,16 +36,17 @@ import (
"k8s.io/kubernetes/pkg/util/term"
)
const (
attach_example = `# Get output from running pod 123456-7890, using the first container by default
kubectl attach 123456-7890
var (
attach_example = dedent.Dedent(`
# Get output from running pod 123456-7890, using the first container by default
kubectl attach 123456-7890
# Get output from ruby-container from pod 123456-7890
kubectl attach 123456-7890 -c ruby-container
# Get output from ruby-container from pod 123456-7890
kubectl attach 123456-7890 -c ruby-container
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
kubectl attach 123456-7890 -c ruby-container -i -t`
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
kubectl attach 123456-7890 -c ruby-container -i -t`)
)
func NewCmdAttach(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {

View File

@ -20,6 +20,8 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
@ -35,17 +37,19 @@ type AutoscaleOptions struct {
Recursive bool
}
const (
autoscaleLong = `Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster.
var (
autoscaleLong = dedent.Dedent(`
Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster.
Looks up a Deployment, ReplicaSet, or ReplicationController by name and creates an autoscaler that uses the given resource as a reference.
An autoscaler can automatically increase or decrease number of pods deployed within the system as needed.`
Looks up a Deployment, ReplicaSet, or ReplicationController by name and creates an autoscaler that uses the given resource as a reference.
An autoscaler can automatically increase or decrease number of pods deployed within the system as needed.`)
autoscaleExample = `# Auto scale a deployment "foo", with the number of pods between 2 to 10, no target CPU utilization specfied so a default autoscaling policy will be used:
kubectl autoscale deployment foo --min=2 --max=10
autoscaleExample = dedent.Dedent(`
# Auto scale a deployment "foo", with the number of pods between 2 to 10, target CPU utilization specified so a default autoscaling policy will be used:
kubectl autoscale deployment foo --min=2 --max=10
# Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%:
kubectl autoscale rc foo --max=5 --cpu-percent=80`
# Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%:
kubectl autoscale rc foo --max=5 --cpu-percent=80`)
)
func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -24,6 +24,7 @@ import (
"path/filepath"
"strings"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -44,7 +45,9 @@ type createAuthInfoOptions struct {
embedCertData flag.Tristate
}
var create_authinfo_long = fmt.Sprintf(`Sets a user entry in kubeconfig
var (
create_authinfo_long = fmt.Sprintf(`
Sets a user entry in kubeconfig
Specifying a name that already exists will merge new fields on top of existing values.
Client-certificate flags:
@ -59,15 +62,17 @@ Specifying a name that already exists will merge new fields on top of existing v
Bearer token and basic auth are mutually exclusive.
`, clientcmd.FlagCertFile, clientcmd.FlagKeyFile, clientcmd.FlagBearerToken, clientcmd.FlagUsername, clientcmd.FlagPassword)
const create_authinfo_example = `# Set only the "client-key" field on the "cluster-admin"
# entry, without touching other values:
kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key
create_authinfo_example = dedent.Dedent(`
# Set only the "client-key" field on the "cluster-admin"
# entry, without touching other values:
kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key
# Set basic auth for the "cluster-admin" entry
kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
# Set basic auth for the "cluster-admin" entry
kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
# Embed client certificate data in the "cluster-admin" entry
kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true`
# Embed client certificate data in the "cluster-admin" entry
kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true`)
)
func NewCmdConfigSetAuthInfo(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {
options := &createAuthInfoOptions{configAccess: configAccess}

View File

@ -23,6 +23,7 @@ import (
"io/ioutil"
"path/filepath"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -41,17 +42,19 @@ type createClusterOptions struct {
embedCAData flag.Tristate
}
const (
create_cluster_long = `Sets a cluster entry in kubeconfig.
Specifying a name that already exists will merge new fields on top of existing values for those fields.`
create_cluster_example = `# Set only the server field on the e2e cluster entry without touching other values.
kubectl config set-cluster e2e --server=https://1.2.3.4
var (
create_cluster_long = dedent.Dedent(`
Sets a cluster entry in kubeconfig.
Specifying a name that already exists will merge new fields on top of existing values for those fields.`)
create_cluster_example = dedent.Dedent(`
# Set only the server field on the e2e cluster entry without touching other values.
kubectl config set-cluster e2e --server=https://1.2.3.4
# Embed certificate authority data for the e2e cluster entry
kubectl config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
# Embed certificate authority data for the e2e cluster entry
kubectl config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
# Disable cert checking for the dev cluster entry
kubectl config set-cluster e2e --insecure-skip-tls-verify=true`
# Disable cert checking for the dev cluster entry
kubectl config set-cluster e2e --insecure-skip-tls-verify=true`)
)
func NewCmdConfigSetCluster(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -36,11 +37,13 @@ type createContextOptions struct {
namespace util.StringFlag
}
const (
create_context_long = `Sets a context entry in kubeconfig
Specifying a name that already exists will merge new fields on top of existing values for those fields.`
create_context_example = `# Set the user field on the gce context entry without touching other values
kubectl config set-context gce --user=cluster-admin`
var (
create_context_long = dedent.Dedent(`
Sets a context entry in kubeconfig
Specifying a name that already exists will merge new fields on top of existing values for those fields.`)
create_context_example = dedent.Dedent(`
# Set the user field on the gce context entry without touching other values
kubectl config set-context gce --user=cluster-admin`)
)
func NewCmdConfigSetContext(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -30,10 +31,12 @@ type CurrentContextOptions struct {
ConfigAccess clientcmd.ConfigAccess
}
const (
current_context_long = `Displays the current-context`
current_context_example = `# Display the current-context
kubectl config current-context`
var (
current_context_long = dedent.Dedent(`
Displays the current-context`)
current_context_example = dedent.Dedent(`
# Display the current-context
kubectl config current-context`)
)
func NewCmdConfigCurrentContext(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {

View File

@ -24,6 +24,7 @@ import (
"reflect"
"strings"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -42,9 +43,10 @@ type setOptions struct {
setRawBytes flag.Tristate
}
const set_long = `Sets an individual value in a kubeconfig file
PROPERTY_NAME is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots.
PROPERTY_VALUE is the new value you wish to set. Binary fields such as 'certificate-authority-data' expect a base64 encoded string unless the --set-raw-bytes flag is used.`
var set_long = dedent.Dedent(`
Sets an individual value in a kubeconfig file
PROPERTY_NAME is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots.
PROPERTY_VALUE is the new value you wish to set. Binary fields such as 'certificate-authority-data' expect a base64 encoded string unless the --set-raw-bytes flag is used.`)
func NewCmdConfigSet(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {
options := &setOptions{configAccess: configAccess}

View File

@ -22,6 +22,7 @@ import (
"io"
"reflect"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -32,8 +33,9 @@ type unsetOptions struct {
propertyName string
}
const unset_long = `Unsets an individual value in a kubeconfig file
PROPERTY_NAME is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots.`
var unset_long = dedent.Dedent(`
Unsets an individual value in a kubeconfig file
PROPERTY_NAME is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots.`)
func NewCmdConfigUnset(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {
options := &unsetOptions{configAccess: configAccess}

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -39,15 +40,17 @@ type ViewOptions struct {
RawByteData bool
}
const (
view_long = `Displays merged kubeconfig settings or a specified kubeconfig file.
var (
view_long = dedent.Dedent(`
Displays merged kubeconfig settings or a specified kubeconfig file.
You can use --output jsonpath={...} to extract specific values using a jsonpath expression.`
view_example = `# Show Merged kubeconfig settings.
kubectl config view
You can use --output jsonpath={...} to extract specific values using a jsonpath expression.`)
view_example = dedent.Dedent(`
# Show Merged kubeconfig settings.
kubectl config view
# Get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'`
# Get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'`)
)
func NewCmdConfigView(out io.Writer, ConfigAccess clientcmd.ConfigAccess) *cobra.Command {

View File

@ -20,6 +20,8 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apimachinery/registered"
@ -31,27 +33,30 @@ import (
"github.com/spf13/cobra"
)
const (
convert_long = `Convert config files between different API versions. Both YAML
and JSON formats are accepted.
var (
convert_long = dedent.Dedent(`
Convert config files between different API versions. Both YAML
and JSON formats are accepted.
The command takes filename, directory, or URL as input, and convert it into format
of version specified by --output-version flag. If target version is not specified or
not supported, convert to latest version.
The command takes filename, directory, or URL as input, and convert it into format
of version specified by --output-version flag. If target version is not specified or
not supported, convert to latest version.
The default output will be printed to stdout in YAML format. One can use -o option
to change to output destination.
`
convert_example = `# Convert 'pod.yaml' to latest version and print to stdout.
kubectl convert -f pod.yaml
The default output will be printed to stdout in YAML format. One can use -o option
to change to output destination.
`)
# Convert the live state of the resource specified by 'pod.yaml' to the latest version
# and print to stdout in json format.
kubectl convert -f pod.yaml --local -o json
convert_example = dedent.Dedent(`
# Convert 'pod.yaml' to latest version and print to stdout.
kubectl convert -f pod.yaml
# Convert all files under current directory to latest version and create them all.
kubectl convert -f . | kubectl create -f -
`
# Convert the live state of the resource specified by 'pod.yaml' to the latest version
# and print to stdout in json format.
kubectl convert -f pod.yaml --local -o json
# Convert all files under current directory to latest version and create them all.
kubectl convert -f . | kubectl create -f -
`)
)
// NewCmdConvert creates a command object for the generic "convert" action, which

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/unversioned"
@ -35,15 +36,17 @@ type CreateOptions struct {
Recursive bool
}
const (
create_long = `Create a resource by filename or stdin.
var (
create_long = dedent.Dedent(`
Create a resource by filename or stdin.
JSON and YAML formats are accepted.`
create_example = `# Create a pod using the data in pod.json.
kubectl create -f ./pod.json
JSON and YAML formats are accepted.`)
create_example = dedent.Dedent(`
# Create a pod using the data in pod.json.
kubectl create -f ./pod.json
# Create a pod based on the JSON passed into stdin.
cat pod.json | kubectl create -f -`
# Create a pod based on the JSON passed into stdin.
cat pod.json | kubectl create -f -`)
)
func NewCmdCreate(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,33 +20,36 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
configMapLong = `Create a configmap based on a file, directory, or specified literal value.
var (
configMapLong = dedent.Dedent(`
Create a configmap based on a file, directory, or specified literal value.
A single configmap may package one or more key/value pairs.
A single configmap may package one or more key/value pairs.
When creating a configmap based on a file, the key will default to the basename of the file, and the value will
default to the file content. If the basename is an invalid key, you may specify an alternate key.
When creating a configmap based on a file, the key will default to the basename of the file, and the value will
default to the file content. If the basename is an invalid key, you may specify an alternate key.
When creating a configmap based on a directory, each file whose basename is a valid key in the directory will be
packaged into the configmap. Any directory entries except regular files are ignored (e.g. subdirectories,
symlinks, devices, pipes, etc).
`
When creating a configmap based on a directory, each file whose basename is a valid key in the directory will be
packaged into the configmap. Any directory entries except regular files are ignored (e.g. subdirectories,
symlinks, devices, pipes, etc).
`)
configMapExample = ` # Create a new configmap named my-config with keys for each file in folder bar
kubectl create configmap my-config --from-file=path/to/bar
configMapExample = dedent.Dedent(`
# Create a new configmap named my-config with keys for each file in folder bar
kubectl create configmap my-config --from-file=path/to/bar
# Create a new configmap named my-config with specified keys instead of names on disk
kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
# Create a new configmap named my-config with specified keys instead of names on disk
kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
# Create a new configMap named my-config with key1=config1 and key2=config2
kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2`
# Create a new configMap named my-config with key1=config1 and key2=config2
kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2`)
)
// ConfigMap is a command to ease creating ConfigMaps.

View File

@ -20,18 +20,20 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
namespaceLong = `
Create a namespace with the specified name.`
var (
namespaceLong = dedent.Dedent(`
Create a namespace with the specified name.`)
namespaceExample = ` # Create a new namespace named my-namespace
kubectl create namespace my-namespace`
namespaceExample = dedent.Dedent(`
# Create a new namespace named my-namespace
kubectl create namespace my-namespace`)
)
// NewCmdCreateNamespace is a macro command to create a new namespace

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
@ -43,28 +44,29 @@ func NewCmdCreateSecret(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Command {
return cmd
}
const (
secretLong = `
Create a secret based on a file, directory, or specified literal value.
var (
secretLong = dedent.Dedent(`
Create a secret based on a file, directory, or specified literal value.
A single secret may package one or more key/value pairs.
A single secret may package one or more key/value pairs.
When creating a secret based on a file, the key will default to the basename of the file, and the value will
default to the file content. If the basename is an invalid key, you may specify an alternate key.
When creating a secret based on a file, the key will default to the basename of the file, and the value will
default to the file content. If the basename is an invalid key, you may specify an alternate key.
When creating a secret based on a directory, each file whose basename is a valid key in the directory will be
packaged into the secret. Any directory entries except regular files are ignored (e.g. subdirectories,
symlinks, devices, pipes, etc).
`
When creating a secret based on a directory, each file whose basename is a valid key in the directory will be
packaged into the secret. Any directory entries except regular files are ignored (e.g. subdirectories,
symlinks, devices, pipes, etc).
`)
secretExample = ` # Create a new secret named my-secret with keys for each file in folder bar
kubectl create secret generic my-secret --from-file=path/to/bar
secretExample = dedent.Dedent(`
# Create a new secret named my-secret with keys for each file in folder bar
kubectl create secret generic my-secret --from-file=path/to/bar
# Create a new secret named my-secret with specified keys instead of names on disk
kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-file=ssh-publickey=~/.ssh/id_rsa.pub
# Create a new secret named my-secret with specified keys instead of names on disk
kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-file=ssh-publickey=~/.ssh/id_rsa.pub
# Create a new secret named my-secret with key1=supersecret and key2=topsecret
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret`
# Create a new secret named my-secret with key1=supersecret and key2=topsecret
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret`)
)
// NewCmdCreateSecretGeneric is a command to create generic secrets from files, directories, or literal values
@ -115,23 +117,24 @@ func CreateSecretGeneric(f *cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Comman
})
}
const (
secretForDockerRegistryLong = `
Create a new secret for use with Docker registries.
var (
secretForDockerRegistryLong = dedent.Dedent(`
Create a new secret for use with Docker registries.
Dockercfg secrets are used to authenticate against Docker registries.
Dockercfg secrets are used to authenticate against Docker registries.
When using the Docker command line to push images, you can authenticate to a given registry by running
'docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'.
That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to
authenticate to the registry.
When using the Docker command line to push images, you can authenticate to a given registry by running
'docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'.
That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to
authenticate to the registry.
When creating applications, you may have a Docker registry that requires authentication. In order for the
nodes to pull images on your behalf, they have to have the credentials. You can provide this information
by creating a dockercfg secret and attaching it to your service account.`
When creating applications, you may have a Docker registry that requires authentication. In order for the
nodes to pull images on your behalf, they have to have the credentials. You can provide this information
by creating a dockercfg secret and attaching it to your service account.`)
secretForDockerRegistryExample = ` # If you don't already have a .dockercfg file, you can create a dockercfg secret directly by using:
kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL`
secretForDockerRegistryExample = dedent.Dedent(`
# If you don't already have a .dockercfg file, you can create a dockercfg secret directly by using:
kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL`)
)
// NewCmdCreateSecretDockerRegistry is a macro command for creating secrets to work with Docker registries
@ -194,14 +197,15 @@ func CreateSecretDockerRegistry(f *cmdutil.Factory, cmdOut io.Writer, cmd *cobra
})
}
const (
secretForTLSLong = `
Create a TLS secret from the given public/private key pair.
var (
secretForTLSLong = dedent.Dedent(`
Create a TLS secret from the given public/private key pair.
The public/private key pair must exist before hand. The public key certificate must be .PEM encoded and match the given private key.`
The public/private key pair must exist before hand. The public key certificate must be .PEM encoded and match the given private key.`)
secretForTLSExample = ` # Create a new TLS secret named tls-secret with the given key pair:
kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key`
secretForTLSExample = dedent.Dedent(`
# Create a new TLS secret named tls-secret with the given key pair:
kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key`)
)
// NewCmdCreateSecretTLS is a macro command for creating secrets to work with Docker registries

View File

@ -20,18 +20,20 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
serviceAccountLong = `
Create a service account with the specified name.`
var (
serviceAccountLong = dedent.Dedent(`
Create a service account with the specified name.`)
serviceAccountExample = ` # Create a new service account named my-service-account
$ kubectl create serviceaccount my-service-account`
serviceAccountExample = dedent.Dedent(`
# Create a new service account named my-service-account
$ kubectl create serviceaccount my-service-account`)
)
// NewCmdCreateServiceAccount is a macro command to create a new service account

View File

@ -21,6 +21,7 @@ import (
"io"
"time"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -38,36 +39,38 @@ type DeleteOptions struct {
Recursive bool
}
const (
delete_long = `Delete resources by filenames, stdin, resources and names, or by resources and label selector.
var (
delete_long = dedent.Dedent(`
Delete resources by filenames, stdin, resources and names, or by resources and label selector.
JSON and YAML formats are accepted.
JSON and YAML formats are accepted.
Only one type of the arguments may be specified: filenames, resources and names, or resources and label selector
Only one type of the arguments may be specified: filenames, resources and names, or resources and label selector
Note that the delete command does NOT do resource version checks, so if someone
submits an update to a resource right when you submit a delete, their update
will be lost along with the rest of the resource.`
delete_example = `# Delete a pod using the type and name specified in pod.json.
kubectl delete -f ./pod.json
Note that the delete command does NOT do resource version checks, so if someone
submits an update to a resource right when you submit a delete, their update
will be lost along with the rest of the resource.`)
delete_example = dedent.Dedent(`
# Delete a pod using the type and name specified in pod.json.
kubectl delete -f ./pod.json
# Delete a pod based on the type and name in the JSON passed into stdin.
cat pod.json | kubectl delete -f -
# Delete a pod based on the type and name in the JSON passed into stdin.
cat pod.json | kubectl delete -f -
# Delete pods and services with same names "baz" and "foo"
kubectl delete pod,service baz foo
# Delete pods and services with same names "baz" and "foo"
kubectl delete pod,service baz foo
# Delete pods and services with label name=myLabel.
kubectl delete pods,services -l name=myLabel
# Delete pods and services with label name=myLabel.
kubectl delete pods,services -l name=myLabel
# Delete a pod immediately (no graceful shutdown)
kubectl delete pod foo --now
# Delete a pod immediately (no graceful shutdown)
kubectl delete pod foo --now
# Delete a pod with UID 1234-56-7890-234234-456456.
kubectl delete pod 1234-56-7890-234234-456456
# Delete a pod with UID 1234-56-7890-234234-456456.
kubectl delete pod 1234-56-7890-234234-456456
# Delete all pods
kubectl delete pods --all`
# Delete all pods
kubectl delete pods --all`)
)
func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -21,6 +21,7 @@ import (
"io"
"strings"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
apierrors "k8s.io/kubernetes/pkg/api/errors"
@ -39,36 +40,39 @@ type DescribeOptions struct {
Recursive bool
}
const (
describe_long = `Show details of a specific resource or group of resources.
var (
describe_long = dedent.Dedent(`
Show details of a specific resource or group of resources.
This command joins many API calls together to form a detailed description of a
given resource or group of resources.
This command joins many API calls together to form a detailed description of a
given resource or group of resources.
$ kubectl describe TYPE NAME_PREFIX
$ kubectl describe TYPE NAME_PREFIX
will first check for an exact match on TYPE and NAME_PREFIX. If no such resource
exists, it will output details for every resource that has a name prefixed with NAME_PREFIX.
will first check for an exact match on TYPE and NAME_PREFIX. If no such resource
exists, it will output details for every resource that has a name prefixed with NAME_PREFIX
`) +
kubectl.PossibleResourceTypes
` + kubectl.PossibleResourceTypes
describe_example = `# Describe a node
kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal
describe_example = dedent.Dedent(`
# Describe a node
kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal
# Describe a pod
kubectl describe pods/nginx
# Describe a pod
kubectl describe pods/nginx
# Describe a pod identified by type and name in "pod.json"
kubectl describe -f pod.json
# Describe a pod identified by type and name in "pod.json"
kubectl describe -f pod.json
# Describe all pods
kubectl describe pods
# Describe all pods
kubectl describe pods
# Describe pods by label name=myLabel
kubectl describe po -l name=myLabel
# Describe pods by label name=myLabel
kubectl describe po -l name=myLabel
# Describe all pods managed by the 'frontend' replication controller (rc-created pods
# get the name of the rc as a prefix in the pod the name).
kubectl describe pods frontend`
# Describe all pods managed by the 'frontend' replication controller (rc-created pods
# get the name of the rc as a prefix in the pod the name).
kubectl describe pods frontend`)
)
func NewCmdDescribe(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -23,6 +23,7 @@ import (
"reflect"
"strings"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -66,11 +67,16 @@ const (
kLocalStorageWarning = "Deleting pods with local storage"
kUnmanagedFatal = "pods not managed by ReplicationController, ReplicaSet, Job, or DaemonSet (use --force to override)"
kUnmanagedWarning = "Deleting pods not managed by ReplicationController, ReplicaSet, Job, or DaemonSet"
cordon_long = `Mark node as unschedulable.
`
cordon_example = `# Mark node "foo" as unschedulable.
kubectl cordon foo
`
)
var (
cordon_long = dedent.Dedent(`
Mark node as unschedulable.
`)
cordon_example = dedent.Dedent(`
# Mark node "foo" as unschedulable.
kubectl cordon foo
`)
)
func NewCmdCordon(f *cmdutil.Factory, out io.Writer) *cobra.Command {
@ -89,12 +95,14 @@ func NewCmdCordon(f *cmdutil.Factory, out io.Writer) *cobra.Command {
return cmd
}
const (
uncordon_long = `Mark node as schedulable.
`
uncordon_example = `# Mark node "foo" as schedulable.
$ kubectl uncordon foo
`
var (
uncordon_long = dedent.Dedent(`
Mark node as schedulable.
`)
uncordon_example = dedent.Dedent(`
# Mark node "foo" as schedulable.
$ kubectl uncordon foo
`)
)
func NewCmdUncordon(f *cmdutil.Factory, out io.Writer) *cobra.Command {
@ -113,28 +121,31 @@ func NewCmdUncordon(f *cmdutil.Factory, out io.Writer) *cobra.Command {
return cmd
}
const (
drain_long = `Drain node in preparation for maintenance.
var (
drain_long = dedent.Dedent(`
Drain node in preparation for maintenance.
The given node will be marked unschedulable to prevent new pods from arriving.
Then drain deletes all pods except mirror pods (which cannot be deleted through
the API server). If there are DaemonSet-managed pods, drain will not proceed
without --ignore-daemonsets, and regardless it will not delete any
DaemonSet-managed pods, because those pods would be immediately replaced by the
DaemonSet controller, which ignores unschedulable markings. If there are any
pods that are neither mirror pods nor managed--by ReplicationController,
ReplicaSet, DaemonSet or Job--, then drain will not delete any pods unless you
use --force.
The given node will be marked unschedulable to prevent new pods from arriving.
Then drain deletes all pods except mirror pods (which cannot be deleted through
the API server). If there are DaemonSet-managed pods, drain will not proceed
without --ignore-daemonsets, and regardless it will not delete any
DaemonSet-managed pods, because those pods would be immediately replaced by the
DaemonSet controller, which ignores unschedulable markings. If there are any
pods that are neither mirror pods nor managed--by ReplicationController,
ReplicaSet, DaemonSet or Job--, then drain will not delete any pods unless you
use --force.
When you are ready to put the node back into service, use kubectl uncordon, which
will make the node schedulable again.
`
drain_example = `# Drain node "foo", even if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet on it.
$ kubectl drain foo --force
When you are ready to put the node back into service, use kubectl uncordon, which
will make the node schedulable again.
`)
# As above, but abort if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet, and use a grace period of 15 minutes.
$ kubectl drain foo --grace-period=900
`
drain_example = dedent.Dedent(`
# Drain node "foo", even if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet on it.
$ kubectl drain foo --force
# As above, but abort if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet, and use a grace period of 15 minutes.
$ kubectl drain foo --grace-period=900
`)
)
func NewCmdDrain(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -27,6 +27,7 @@ import (
gruntime "runtime"
"strings"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
@ -45,35 +46,37 @@ import (
"github.com/spf13/cobra"
)
const (
editLong = `Edit a resource from the default editor.
var (
editLong = dedent.Dedent(`
Edit a resource from the default editor.
The edit command allows you to directly edit any API resource you can retrieve via the
command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR
environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
You can edit multiple objects, although changes are applied one at a time. The command
accepts filenames as well as command line arguments, although the files you point to must
be previously saved versions of resources.
The edit command allows you to directly edit any API resource you can retrieve via the
command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR
environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
You can edit multiple objects, although changes are applied one at a time. The command
accepts filenames as well as command line arguments, although the files you point to must
be previously saved versions of resources.
The files to edit will be output in the default API version, or a version specified
by --output-version. The default format is YAML - if you would like to edit in JSON
pass -o json. The flag --windows-line-endings can be used to force Windows line endings,
otherwise the default for your operating system will be used.
The files to edit will be output in the default API version, or a version specified
by --output-version. The default format is YAML - if you would like to edit in JSON
pass -o json. The flag --windows-line-endings can be used to force Windows line endings,
otherwise the default for your operating system will be used.
In the event an error occurs while updating, a temporary file will be created on disk
that contains your unapplied changes. The most common error when updating a resource
is another editor changing the resource on the server. When this occurs, you will have
to apply your changes to the newer version of the resource, or update your temporary
saved copy to include the latest resource version.`
In the event an error occurs while updating, a temporary file will be created on disk
that contains your unapplied changes. The most common error when updating a resource
is another editor changing the resource on the server. When this occurs, you will have
to apply your changes to the newer version of the resource, or update your temporary
saved copy to include the latest resource version.`)
editExample = ` # Edit the service named 'docker-registry':
kubectl edit svc/docker-registry
editExample = dedent.Dedent(`
# Edit the service named 'docker-registry':
kubectl edit svc/docker-registry
# Use an alternative editor
KUBE_EDITOR="nano" kubectl edit svc/docker-registry
# Use an alternative editor
KUBE_EDITOR="nano" kubectl edit svc/docker-registry
# Edit the service 'docker-registry' in JSON using the v1 API format:
kubectl edit svc/docker-registry --output-version=v1 -o json`
# Edit the service 'docker-registry' in JSON using the v1 API format:
kubectl edit svc/docker-registry --output-version=v1 -o json`)
)
// EditOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of

View File

@ -26,6 +26,7 @@ import (
"github.com/docker/docker/pkg/term"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/restclient"
@ -35,16 +36,17 @@ import (
remotecommandserver "k8s.io/kubernetes/pkg/kubelet/server/remotecommand"
)
const (
exec_example = `# Get output from running 'date' from pod 123456-7890, using the first container by default
kubectl exec 123456-7890 date
var (
exec_example = dedent.Dedent(`
# Get output from running 'date' from pod 123456-7890, using the first container by default
kubectl exec 123456-7890 date
# Get output from running 'date' in ruby-container from pod 123456-7890
kubectl exec 123456-7890 -c ruby-container date
# Get output from running 'date' in ruby-container from pod 123456-7890
kubectl exec 123456-7890 -c ruby-container date
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il`
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il`)
)
func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {

View File

@ -19,6 +19,7 @@ package cmd
import (
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/unversioned"
@ -27,16 +28,18 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
explainExamples = `# Get the documentation of the resource and its fields
kubectl explain pods
var (
explainExamples = dedent.Dedent(`
# Get the documentation of the resource and its fields
kubectl explain pods
# Get the documentation of a specific field of a resource
kubectl explain pods.spec.containers`
# Get the documentation of a specific field of a resource
kubectl explain pods.spec.containers`)
explainLong = `Documentation of resources.
explainLong = dedent.Dedent(`
Documentation of resources.
` + kubectl.PossibleResourceTypes
`) + kubectl.PossibleResourceTypes
)
// NewCmdExplain returns a cobra command for swagger docs

View File

@ -22,6 +22,7 @@ import (
"regexp"
"strings"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
@ -38,43 +39,45 @@ type ExposeOptions struct {
Recursive bool
}
const (
expose_resources = `
pod (po), service (svc), replicationcontroller (rc),
deployment, replicaset (rs)
`
var (
expose_resources = dedent.Dedent(`
pod (po), service (svc), replicationcontroller (rc),
deployment, replicaset (rs)
`)
expose_long = `Expose a resource as a new Kubernetes service.
expose_long = dedent.Dedent(`
Expose a resource as a new Kubernetes service.
Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector
for that resource as the selector for a new service on the specified port. A deployment or replica set
will be exposed as a service only if its selector is convertible to a selector that service supports,
i.e. when the selector contains only the matchLabels component. Note that if no port is specified via
--port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no
labels are specified, the new service will re-use the labels from the resource it exposes.
Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector
for that resource as the selector for a new service on the specified port. A deployment or replica set
will be exposed as a service only if its selector is convertible to a selector that service supports,
i.e. when the selector contains only the matchLabels component. Note that if no port is specified via
--port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no
labels are specified, the new service will re-use the labels from the resource it exposes.
Possible resources include (case insensitive):` + expose_resources
Possible resources include (case insensitive): `) + expose_resources
expose_example = `# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
kubectl expose rc nginx --port=80 --target-port=8000
expose_example = dedent.Dedent(`
# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
kubectl expose rc nginx --port=80 --target-port=8000
# Create a service for a replication controller identified by type and name specified in "nginx-controller.yaml", which serves on port 80 and connects to the containers on port 8000.
kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
# Create a service for a replication controller identified by type and name specified in "nginx-controller.yaml", which serves on port 80 and connects to the containers on port 8000.
kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
# Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
kubectl expose pod valid-pod --port=444 --name=frontend
# Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
kubectl expose pod valid-pod --port=444 --name=frontend
# Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
# Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
# Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
# Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
# Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
kubectl expose rs nginx --port=80 --target-port=8000
# Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
kubectl expose rs nginx --port=80 --target-port=8000
# Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
kubectl expose deployment nginx --port=80 --target-port=8000`
# Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
kubectl expose deployment nginx --port=80 --target-port=8000`)
)
func NewCmdExposeService(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/kubectl"
@ -37,36 +38,38 @@ type GetOptions struct {
Recursive bool
}
const (
get_long = `Display one or many resources.
var (
get_long = dedent.Dedent(`
Display one or many resources.
` + kubectl.PossibleResourceTypes + `
`) + kubectl.PossibleResourceTypes + dedent.Dedent(`
By specifying the output as 'template' and providing a Go template as the value
of the --template flag, you can filter the attributes of the fetched resource(s).`
get_example = `# List all pods in ps output format.
kubectl get pods
By specifying the output as 'template' and providing a Go template as the value
of the --template flag, you can filter the attributes of the fetched resource(s).`)
get_example = dedent.Dedent(`
# List all pods in ps output format.
kubectl get pods
# List all pods in ps output format with more information (such as node name).
kubectl get pods -o wide
# List all pods in ps output format with more information (such as node name).
kubectl get pods -o wide
# List a single replication controller with specified NAME in ps output format.
kubectl get replicationcontroller web
# List a single replication controller with specified NAME in ps output format.
kubectl get replicationcontroller web
# List a single pod in JSON output format.
kubectl get -o json pod web-pod-13je7
# List a single pod in JSON output format.
kubectl get -o json pod web-pod-13je7
# List a pod identified by type and name specified in "pod.yaml" in JSON output format.
kubectl get -f pod.yaml -o json
# List a pod identified by type and name specified in "pod.yaml" in JSON output format.
kubectl get -f pod.yaml -o json
# Return only the phase value of the specified pod.
kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
# Return only the phase value of the specified pod.
kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
# List all replication controllers and services together in ps output format.
kubectl get rc,services
# List all replication controllers and services together in ps output format.
kubectl get rc,services
# List one or more resources by their type and names.
kubectl get rc/web service/frontend pods/web-pod-13je7`
# List one or more resources by their type and names.
kubectl get rc/web service/frontend pods/web-pod-13je7`)
)
// NewCmdGet creates a command object for the generic "get" action, which

View File

@ -24,6 +24,7 @@ import (
"strings"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -43,30 +44,32 @@ type LabelOptions struct {
Recursive bool
}
const (
label_long = `Update the labels on a resource.
var (
label_long = dedent.Dedent(`
Update the labels on a resource.
A label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
If --overwrite is true, then existing labels can be overwritten, otherwise attempting to overwrite a label will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.`
label_example = `# Update pod 'foo' with the label 'unhealthy' and the value 'true'.
kubectl label pods foo unhealthy=true
A label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
If --overwrite is true, then existing labels can be overwritten, otherwise attempting to overwrite a label will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.`)
label_example = dedent.Dedent(`
# Update pod 'foo' with the label 'unhealthy' and the value 'true'.
kubectl label pods foo unhealthy=true
# Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.
kubectl label --overwrite pods foo status=unhealthy
# Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.
kubectl label --overwrite pods foo status=unhealthy
# Update all pods in the namespace
kubectl label pods --all status=unhealthy
# Update all pods in the namespace
kubectl label pods --all status=unhealthy
# Update a pod identified by the type and name in "pod.json"
kubectl label -f pod.json status=unhealthy
# Update a pod identified by the type and name in "pod.json"
kubectl label -f pod.json status=unhealthy
# Update pod 'foo' only if the resource is unchanged from version 1.
kubectl label pods foo status=unhealthy --resource-version=1
# Update pod 'foo' only if the resource is unchanged from version 1.
kubectl label pods foo status=unhealthy --resource-version=1
# Update pod 'foo' by removing a label named 'bar' if it exists.
# Does not require the --overwrite flag.
kubectl label pods foo bar-`
# Update pod 'foo' by removing a label named 'bar' if it exists.
# Does not require the --overwrite flag.
kubectl label pods foo bar-`)
)
func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -23,6 +23,7 @@ import (
"os"
"time"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -34,21 +35,22 @@ import (
"k8s.io/kubernetes/pkg/runtime"
)
const (
logs_example = `# Return snapshot logs from pod nginx with only one container
kubectl logs nginx
var (
logs_example = dedent.Dedent(`
# Return snapshot logs from pod nginx with only one container
kubectl logs nginx
# Return snapshot of previous terminated ruby container logs from pod web-1
kubectl logs -p -c ruby web-1
# Return snapshot of previous terminated ruby container logs from pod web-1
kubectl logs -p -c ruby web-1
# Begin streaming the logs of the ruby container in pod web-1
kubectl logs -f -c ruby web-1
# Begin streaming the logs of the ruby container in pod web-1
kubectl logs -f -c ruby web-1
# Display only the most recent 20 lines of output in pod nginx
kubectl logs --tail=20 nginx
# Display only the most recent 20 lines of output in pod nginx
kubectl logs --tail=20 nginx
# Show all logs from pod nginx written in the last hour
kubectl logs --since=1h nginx`
# Show all logs from pod nginx written in the last hour
kubectl logs --since=1h nginx`)
)
type LogsOptions struct {

View File

@ -22,6 +22,7 @@ import (
"strings"
"github.com/evanphx/json-patch"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -46,24 +47,26 @@ type PatchOptions struct {
OutputFormat string
}
const (
patch_long = `Update field(s) of a resource using strategic merge patch
var (
patch_long = dedent.Dedent(`
Update field(s) of a resource using strategic merge patch
JSON and YAML formats are accepted.
JSON and YAML formats are accepted.
Please refer to the models in https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html to find if a field is mutable.`
patch_example = `
# Partially update a node using strategic merge patch
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
Please refer to the models in https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html to find if a field is mutable.`)
patch_example = dedent.Dedent(`
# Partially update a node identified by the type and name specified in "node.json" using strategic merge patch
kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}'
# Partially update a node using strategic merge patch
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
# Update a container's image; spec.containers[*].name is required because it's a merge key
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
# Partially update a node identified by the type and name specified in "node.json" using strategic merge patch
kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}'
# Update a container's image using a json patch with positional arrays
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'`
# Update a container's image; spec.containers[*].name is required because it's a merge key
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
# Update a container's image using a json patch with positional arrays
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'`)
)
func NewCmdPatch(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -23,6 +23,7 @@ import (
"os/signal"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/restclient"
@ -31,19 +32,19 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
portforward_example = `
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward mypod 5000 6000
var (
portforward_example = dedent.Dedent(`
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward mypod 5000 6000
# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward mypod 8888:5000
# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward mypod 8888:5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod :5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod :5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod 0:5000`
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod 0:5000`)
)
func NewCmdPortForward(f *cmdutil.Factory, cmdOut, cmdErr io.Writer) *cobra.Command {

View File

@ -24,45 +24,48 @@ import (
"strings"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
var (
default_port = 8001
proxy_example = `# Run a proxy to kubernetes apiserver on port 8011, serving static content from ./local/www/
kubectl proxy --port=8011 --www=./local/www/
proxy_example = dedent.Dedent(`
# Run a proxy to kubernetes apiserver on port 8011, serving static content from ./local/www/
kubectl proxy --port=8011 --www=./local/www/
# Run a proxy to kubernetes apiserver on an arbitrary local port.
# The chosen port for the server will be output to stdout.
kubectl proxy --port=0
# Run a proxy to kubernetes apiserver on an arbitrary local port.
# The chosen port for the server will be output to stdout.
kubectl proxy --port=0
# Run a proxy to kubernetes apiserver, changing the api prefix to k8s-api
# This makes e.g. the pods api available at localhost:8011/k8s-api/v1/pods/
kubectl proxy --api-prefix=/k8s-api`
# Run a proxy to kubernetes apiserver, changing the api prefix to k8s-api
# This makes e.g. the pods api available at localhost:8011/k8s-api/v1/pods/
kubectl proxy --api-prefix=/k8s-api`)
)
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 Kubernetes API server",
Long: `To proxy all of the kubernetes api and nothing else, use:
Long: dedent.Dedent(`
To proxy all of the kubernetes api and nothing else, use:
kubectl proxy --api-prefix=/
kubectl proxy --api-prefix=/
To proxy only part of the kubernetes api and also some static files:
To proxy only part of the kubernetes api and also some static files:
kubectl proxy --www=/my/files --www-prefix=/static/ --api-prefix=/api/
kubectl proxy --www=/my/files --www-prefix=/static/ --api-prefix=/api/
The above lets you 'curl localhost:8001/api/v1/pods'.
The above lets you 'curl localhost:8001/api/v1/pods'.
To proxy the entire kubernetes api at a different root, use:
To proxy the entire kubernetes api at a different root, use:
kubectl proxy --api-prefix=/custom/
kubectl proxy --api-prefix=/custom/
The above lets you 'curl localhost:8001/custom/api/v1/pods'
`,
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)

View File

@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"github.com/golang/glog"
@ -38,25 +39,27 @@ type ReplaceOptions struct {
Recursive bool
}
const (
replace_long = `Replace a resource by filename or stdin.
var (
replace_long = dedent.Dedent(`
Replace a resource by filename or stdin.
JSON and YAML formats are accepted. If replacing an existing resource, the
complete resource spec must be provided. This can be obtained by
$ kubectl get TYPE NAME -o yaml
JSON and YAML formats are accepted. If replacing an existing resource, the
complete resource spec must be provided. This can be obtained by
$ kubectl get TYPE NAME -o yaml
Please refer to the models in https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html to find if a field is mutable.`
replace_example = `# Replace a pod using the data in pod.json.
kubectl replace -f ./pod.json
Please refer to the models in https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html to find if a field is mutable.`)
replace_example = dedent.Dedent(`
# Replace a pod using the data in pod.json.
kubectl replace -f ./pod.json
# Replace a pod based on the JSON passed into stdin.
cat pod.json | kubectl replace -f -
# Replace a pod based on the JSON passed into stdin.
cat pod.json | kubectl replace -f -
# Update a single-container pod's image version (tag) to v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
# Update a single-container pod's image version (tag) to v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
# Force replace, delete and then re-create the resource
kubectl replace --force -f ./pod.json`
# Force replace, delete and then re-create the resource
kubectl replace --force -f ./pod.json`)
)
func NewCmdReplace(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -25,6 +25,7 @@ import (
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
@ -42,28 +43,30 @@ type RollingUpdateOptions struct {
Filenames []string
}
const (
rollingUpdate_long = `Perform a rolling update of the given ReplicationController.
var (
rollingUpdate_long = dedent.Dedent(`
Perform a rolling update of the given ReplicationController.
Replaces the specified replication controller with a new replication controller by updating one pod at a time to use the
new PodTemplate. The new-controller.json must specify the same namespace as the
existing replication controller and overwrite at least one (common) label in its replicaSelector.`
rollingUpdate_example = `# Update pods of frontend-v1 using new replication controller data in frontend-v2.json.
kubectl rolling-update frontend-v1 -f frontend-v2.json
Replaces the specified replication controller with a new replication controller by updating one pod at a time to use the
new PodTemplate. The new-controller.json must specify the same namespace as the
existing replication controller and overwrite at least one (common) label in its replicaSelector.`)
rollingUpdate_example = dedent.Dedent(`
# Update pods of frontend-v1 using new replication controller data in frontend-v2.json.
kubectl rolling-update frontend-v1 -f frontend-v2.json
# Update pods of frontend-v1 using JSON data passed into stdin.
cat frontend-v2.json | kubectl rolling-update frontend-v1 -f -
# Update pods of frontend-v1 using JSON data passed into stdin.
cat frontend-v2.json | kubectl rolling-update frontend-v1 -f -
# Update the pods of frontend-v1 to frontend-v2 by just changing the image, and switching the
# name of the replication controller.
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2
# Update the pods of frontend-v1 to frontend-v2 by just changing the image, and switching the
# name of the replication controller.
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2
# Update the pods of frontend by just changing the image, and keeping the old name.
kubectl rolling-update frontend --image=image:v2
# Update the pods of frontend by just changing the image, and keeping the old name.
kubectl rolling-update frontend --image=image:v2
# Abort and reverse an existing rollout in progress (from frontend-v1 to frontend-v2).
kubectl rolling-update frontend-v1 frontend-v2 --rollback
`
# Abort and reverse an existing rollout in progress (from frontend-v1 to frontend-v2).
kubectl rolling-update frontend-v1 frontend-v2 --rollback
`)
)
var (

View File

@ -19,17 +19,21 @@ package rollout
import (
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
rollout_long = `Manages a deployment using subcommands like "kubectl rollout undo deployment/abc"`
rollout_example = `# Rollback to the previous deployment
kubectl rollout undo deployment/abc`
rollout_valid_resources = `Valid resource types include:
* deployments
`
var (
rollout_long = dedent.Dedent(`
Manages a deployment using subcommands like "kubectl rollout undo deployment/abc"`)
rollout_example = dedent.Dedent(`
# Rollback to the previous deployment
kubectl rollout undo deployment/abc`)
rollout_valid_resources = dedent.Dedent(`
Valid resource types include:
* deployments
`)
)
func NewCmdRollout(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
@ -34,13 +35,15 @@ type HistoryOptions struct {
Recursive bool
}
const (
history_long = `View previous rollout revisions and configurations.`
history_example = `# View the rollout history of a deployment
kubectl rollout history deployment/abc
var (
history_long = dedent.Dedent(`
View previous rollout revisions and configurations.`)
history_example = dedent.Dedent(`
# View the rollout history of a deployment
kubectl rollout history deployment/abc
# View the details of deployment revision 3
kubectl rollout history deployment/abc --revision=3`
# View the details of deployment revision 3
kubectl rollout history deployment/abc --revision=3`)
)
func NewCmdRolloutHistory(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -19,6 +19,7 @@ package rollout
import (
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/meta"
@ -42,17 +43,19 @@ type PauseConfig struct {
Recursive bool
}
const (
pause_long = `Mark the provided resource as paused
var (
pause_long = dedent.Dedent(`
Mark the provided resource as paused
Paused resources will not be reconciled by a controller.
Use \"kubectl rollout resume\" to resume a paused resource.
Currently only deployments support being paused.`
Paused resources will not be reconciled by a controller.
Use \"kubectl rollout resume\" to resume a paused resource.
Currently only deployments support being paused.`)
pause_example = `# Mark the nginx deployment as paused. Any current state of
# the deployment will continue its function, new updates to the deployment will not
# have an effect as long as the deployment is paused.
kubectl rollout pause deployment/nginx`
pause_example = dedent.Dedent(`
# Mark the nginx deployment as paused. Any current state of
# the deployment will continue its function, new updates to the deployment will not
# have an effect as long as the deployment is paused.
kubectl rollout pause deployment/nginx`)
)
func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -19,6 +19,7 @@ package rollout
import (
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/meta"
@ -42,15 +43,17 @@ type ResumeConfig struct {
Recursive bool
}
const (
resume_long = `Resume a paused resource
var (
resume_long = dedent.Dedent(`
Resume a paused resource
Paused resources will not be reconciled by a controller. By resuming a
resource, we allow it to be reconciled again.
Currently only deployments support being resumed.`
Paused resources will not be reconciled by a controller. By resuming a
resource, we allow it to be reconciled again.
Currently only deployments support being resumed.`)
resume_example = `# Resume an already paused deployment
kubectl rollout resume deployment/nginx`
resume_example = dedent.Dedent(`
# Resume an already paused deployment
kubectl rollout resume deployment/nginx`)
)
func NewCmdRolloutResume(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
@ -35,10 +36,12 @@ type StatusOptions struct {
Recursive bool
}
const (
status_long = `Watch the status of current rollout, until it's done.`
status_example = `# Watch the rollout status of a deployment
kubectl rollout status deployment/nginx`
var (
status_long = dedent.Dedent(`
Watch the status of current rollout, until it's done.`)
status_example = dedent.Dedent(`
# Watch the rollout status of a deployment
kubectl rollout status deployment/nginx`)
)
func NewCmdRolloutStatus(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -19,6 +19,7 @@ package rollout
import (
"io"
"github.com/renstrom/dedent"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@ -43,13 +44,15 @@ type UndoOptions struct {
Recursive bool
}
const (
undo_long = `Rollback to a previous rollout.`
undo_example = `# Rollback to the previous deployment
kubectl rollout undo deployment/abc
var (
undo_long = dedent.Dedent(`
Rollback to a previous rollout.`)
undo_example = dedent.Dedent(`
# Rollback to the previous deployment
kubectl rollout undo deployment/abc
# Rollback to deployment revision 3
kubectl rollout undo deployment/abc --to-revision=3`
# Rollback to deployment revision 3
kubectl rollout undo deployment/abc --to-revision=3`)
)
func NewCmdRolloutUndo(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -22,6 +22,7 @@ import (
"os"
"time"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -35,38 +36,40 @@ import (
"k8s.io/kubernetes/pkg/runtime"
)
const (
run_long = `Create and run a particular image, possibly replicated.
Creates a deployment or job to manage the created container(s).`
run_example = `# Start a single instance of nginx.
kubectl run nginx --image=nginx
var (
run_long = dedent.Dedent(`
Create and run a particular image, possibly replicated.
Creates a deployment or job to manage the created container(s).`)
run_example = dedent.Dedent(`
# Start a single instance of nginx.
kubectl run nginx --image=nginx
# Start a single instance of hazelcast and let the container expose port 5701 .
kubectl run hazelcast --image=hazelcast --port=5701
# Start a single instance of hazelcast and let the container expose port 5701 .
kubectl run hazelcast --image=hazelcast --port=5701
# Start a single instance of hazelcast and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
kubectl run hazelcast --image=hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
# Start a single instance of hazelcast and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
kubectl run hazelcast --image=hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
# Start a replicated instance of nginx.
kubectl run nginx --image=nginx --replicas=5
# Start a replicated instance of nginx.
kubectl run nginx --image=nginx --replicas=5
# Dry run. Print the corresponding API objects without creating them.
kubectl run nginx --image=nginx --dry-run
# Dry run. Print the corresponding API objects without creating them.
kubectl run nginx --image=nginx --dry-run
# Start a single instance of nginx, but overload the spec of the deployment with a partial set of values parsed from JSON.
kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
# Start a single instance of nginx, but overload the spec of the deployment with a partial set of values parsed from JSON.
kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
# Start a pod of busybox and keep it in the foreground, don't restart it if it exits.
kubectl run -i -t busybox --image=busybox --restart=Never
# Start a pod of busybox and keep it in the foreground, don't restart it if it exits.
kubectl run -i -t busybox --image=busybox --restart=Never
# Start the nginx container using the default command, but use custom arguments (arg1 .. argN) for that command.
kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
# Start the nginx container using the default command, but use custom arguments (arg1 .. argN) for that command.
kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
# Start the nginx container using a different command and custom arguments.
kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>
# Start the nginx container using a different command and custom arguments.
kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>
# Start the perl container to compute π to 2000 places and print it out.
kubectl run pi --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)'`
# Start the perl container to compute π to 2000 places and print it out.
kubectl run pi --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)'`)
)
func NewCmdRun(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {

View File

@ -21,6 +21,7 @@ import (
"io"
"os"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
@ -36,27 +37,29 @@ type ScaleOptions struct {
Recursive bool
}
const (
scale_long = `Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job.
var (
scale_long = dedent.Dedent(`
Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job.
Scale also allows users to specify one or more preconditions for the scale action.
If --current-replicas or --resource-version is specified, it is validated before the
scale is attempted, and it is guaranteed that the precondition holds true when the
scale is sent to the server.`
scale_example = `# Scale a replicaset named 'foo' to 3.
kubectl scale --replicas=3 rs/foo
Scale also allows users to specify one or more preconditions for the scale action.
If --current-replicas or --resource-version is specified, it is validated before the
scale is attempted, and it is guaranteed that the precondition holds true when the
scale is sent to the server.`)
scale_example = dedent.Dedent(`
# Scale a replicaset named 'foo' to 3.
kubectl scale --replicas=3 rs/foo
# Scale a resource identified by type and name specified in "foo.yaml" to 3.
kubectl scale --replicas=3 -f foo.yaml
# Scale a resource identified by type and name specified in "foo.yaml" to 3.
kubectl scale --replicas=3 -f foo.yaml
# If the deployment named mysql's current size is 2, scale mysql to 3.
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
# If the deployment named mysql's current size is 2, scale mysql to 3.
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
# Scale multiple replication controllers.
kubectl scale --replicas=5 rc/foo rc/bar rc/baz
# Scale multiple replication controllers.
kubectl scale --replicas=5 rc/foo rc/bar rc/baz
# Scale job named 'cron' to 3.
kubectl scale --replicas=3 job/cron`
# Scale job named 'cron' to 3.
kubectl scale --replicas=3 job/cron`)
)
// NewCmdScale returns a cobra command with the appropriate configuration and flags to run scale

View File

@ -19,15 +19,17 @@ package set
import (
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
const (
set_long = `Configure application resources
var (
set_long = dedent.Dedent(`
Configure application resources
These commands help you make changes to existing application resources.`
set_example = ``
These commands help you make changes to existing application resources.`)
set_example = dedent.Dedent(``)
)
func NewCmdSet(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -55,25 +56,27 @@ type ImageOptions struct {
ContainerImages map[string]string
}
const (
var (
image_resources = `
pod (po), replicationcontroller (rc), deployment, daemonset (ds), job, replicaset (rs)`
image_long = `Update existing container image(s) of resources.
image_long = dedent.Dedent(`
Update existing container image(s) of resources.
Possible resources include (case insensitive):` + image_resources
Possible resources include (case insensitive):`) + image_resources
image_example = `# Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
image_example = dedent.Dedent(`
# Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
# Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
kubectl set image deployments,rc nginx=nginx:1.9.1 --all
# Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
kubectl set image deployments,rc nginx=nginx:1.9.1 --all
# Update image of all containers of daemonset abc to 'nginx:1.9.1'
kubectl set image daemonset abc *=nginx:1.9.1
# Update image of all containers of daemonset abc to 'nginx:1.9.1'
kubectl set image daemonset abc *=nginx:1.9.1
# Print result (in yaml format) of updating nginx container image from local file, without hitting the server
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`
# Print result (in yaml format) of updating nginx container image from local file, without hitting the server
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`)
)
func NewCmdImage(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@ -33,25 +34,27 @@ type StopOptions struct {
Recursive bool
}
const (
stop_long = `Deprecated: Gracefully shut down a resource by name or filename.
var (
stop_long = dedent.Dedent(`
Deprecated: Gracefully shut down a resource by name or filename.
The stop command is deprecated, all its functionalities are covered by delete command.
See 'kubectl delete --help' for more details.
The stop command is deprecated, all its functionalities are covered by delete command.
See 'kubectl delete --help' for more details.
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 = `# Shut down foo.
kubectl stop replicationcontroller foo
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
# Stop pods and services with label name=myLabel.
kubectl stop pods,services -l name=myLabel
# Stop pods and services with label name=myLabel.
kubectl stop pods,services -l name=myLabel
# Shut down the service defined in service.json
kubectl stop -f service.json
# 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`
# Shut down all resources in the path/to/resources directory
kubectl stop -f path/to/resources`)
)
func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command {

View File

@ -23,6 +23,7 @@ import (
"encoding/json"
"github.com/golang/glog"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
@ -49,19 +50,21 @@ type TaintOptions struct {
cmd *cobra.Command
}
const (
taint_long = `Update the taints on one or more nodes.
var (
taint_long = dedent.Dedent(`
Update the taints on one or more nodes.
A taint consists of a key, value, and effect. As an argument here, it is expressed as key=value:effect.
The key must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
The value must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
The effect must be NoSchedule or PreferNoSchedule.
Currently taint can only apply to node.`
taint_example = `# Update node 'foo' with a taint with key 'dedicated' and value 'special-user' and effect 'NoSchedule'.
# If a taint with that key already exists, its value and effect are replaced as specified.
kubectl taint nodes foo dedicated=special-user:NoSchedule
# Remove from node 'foo' the taint with key 'dedicated' if one exists.
kubectl taint nodes foo dedicated-`
A taint consists of a key, value, and effect. As an argument here, it is expressed as key=value:effect.
The key must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
The value must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters.
The effect must be NoSchedule or PreferNoSchedule.
Currently taint can only apply to node.`)
taint_example = dedent.Dedent(`
# Update node 'foo' with a taint with key 'dedicated' and value 'special-user' and effect 'NoSchedule'.
# If a taint with that key already exists, its value and effect are replaced as specified.
kubectl taint nodes foo dedicated=special-user:NoSchedule
# Remove from node 'foo' the taint with key 'dedicated' if one exists.
kubectl taint nodes foo dedicated-`)
)
func NewCmdTaint(f *cmdutil.Factory, out io.Writer) *cobra.Command {

11
vendor/github.com/renstrom/dedent/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,11 @@
language: go
go:
- 1.0
- 1.1
- 1.2
- 1.3
- 1.4
- 1.5
sudo: false

21
vendor/github.com/renstrom/dedent/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Peter Renström
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

50
vendor/github.com/renstrom/dedent/README.md generated vendored Normal file
View File

@ -0,0 +1,50 @@
# Dedent
[![Build Status](https://travis-ci.org/renstrom/dedent.svg?branch=master)](https://travis-ci.org/renstrom/dedent)
[![Godoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/renstrom/dedent)
Removes common leading whitespace from multiline strings. Inspired by [`textwrap.dedent`](https://docs.python.org/3/library/textwrap.html#textwrap.dedent) in Python.
## Usage / example
Imagine the following snippet that prints a multiline string. You want the indentation to both look nice in the code as well as in the actual output.
```go
package main
import (
"fmt"
"github.com/renstrom/dedent"
)
func main() {
s := `Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Curabitur justo tellus, facilisis nec efficitur dictum,
fermentum vitae ligula. Sed eu convallis sapien.`
fmt.Println(dedent.Dedent(s))
fmt.Println("-------------")
fmt.Println(s)
}
```
To illustrate the difference, here's the output:
```bash
$ go run main.go
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Curabitur justo tellus, facilisis nec efficitur dictum,
fermentum vitae ligula. Sed eu convallis sapien.
-------------
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Curabitur justo tellus, facilisis nec efficitur dictum,
fermentum vitae ligula. Sed eu convallis sapien.
```
## License
MIT

49
vendor/github.com/renstrom/dedent/dedent.go generated vendored Normal file
View File

@ -0,0 +1,49 @@
package dedent
import (
"regexp"
"strings"
)
var (
whitespaceOnly = regexp.MustCompile("(?m)^[ \t]+$")
leadingWhitespace = regexp.MustCompile("(?m)(^[ \t]*)(?:[^ \t\n])")
)
// Dedent removes any common leading whitespace from every line in text.
//
// This can be used to make multiline strings to line up with the left edge of
// the display, while still presenting them in the source code in indented
// form.
func Dedent(text string) string {
var margin string
text = whitespaceOnly.ReplaceAllString(text, "")
indents := leadingWhitespace.FindAllStringSubmatch(text, -1)
// Look for the longest leading string of spaces and tabs common to all
// lines.
for i, indent := range indents {
if i == 0 {
margin = indent[1]
} else if strings.HasPrefix(indent[1], margin) {
// Current line more deeply indented than previous winner:
// no change (previous winner is still on top).
continue
} else if strings.HasPrefix(margin, indent[1]) {
// Current line consistent with and no deeper than previous winner:
// it's the new winner.
margin = indent[1]
} else {
// Current line and previous winner have no common whitespace:
// there is no margin.
margin = ""
break
}
}
if margin != "" {
text = regexp.MustCompile("(?m)^"+margin).ReplaceAllString(text, "")
}
return text
}