From 69ad3dbeb71ae986ce01c9ed6c1ab47700515651 Mon Sep 17 00:00:00 2001 From: Ahmad Nurus S Date: Sat, 5 Jan 2019 03:50:20 +0700 Subject: [PATCH] Add kubectl config set example --- pkg/kubectl/cmd/config/set.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/cmd/config/set.go b/pkg/kubectl/cmd/config/set.go index 2b5a37a27f..55c994136f 100644 --- a/pkg/kubectl/cmd/config/set.go +++ b/pkg/kubectl/cmd/config/set.go @@ -40,12 +40,29 @@ type setOptions struct { setRawBytes flag.Tristate } -var setLong = templates.LongDesc(` +var ( + setLong = templates.LongDesc(` Sets an individual value in a kubeconfig file PROPERTY_NAME is a dot delimited name where each token represents either an 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.`) + 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. + + Specifying a attribute name that already exists will merge new fields on top of existing values.`) + + setExample = templates.Examples(` + # Set server field on the my-cluster cluster to https://1.2.3.4 + kubectl config set clusters.my-cluster.server https://1.2.3.4 + + # Set certificate-authority-data field on the my-cluster cluster. + kubectl config set clusters.my-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) + + # Set cluster field in the my-context context to my-cluster. + kubectl config set contexts.my-context.cluster my-cluster + + # Set client-key-data field in the cluster-admin user using --set-raw-bytes option. + kubectl config set users.cluster-admin.client-key-data cert_data_here --set-raw-bytes=true`) +) // NewCmdConfigSet returns a Command instance for 'config set' sub command func NewCmdConfigSet(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { @@ -56,6 +73,7 @@ func NewCmdConfigSet(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra. DisableFlagsInUseLine: true, Short: i18n.T("Sets an individual value in a kubeconfig file"), Long: setLong, + Example: setExample, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(options.complete(cmd)) cmdutil.CheckErr(options.run())