Merge pull request #8110 from vvbogdanov87/validate-cluster-kubeconfig

Add kubeconfig flag to validate cluster command
This commit is contained in:
Kubernetes Prow Robot 2019-12-17 06:41:59 -08:00 committed by GitHub
commit db11481e37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -48,8 +48,9 @@ func init() {
}
type ValidateClusterOptions struct {
output string
wait time.Duration
output string
wait time.Duration
kubeconfig string
}
func (o *ValidateClusterOptions) InitDefaults() {
@ -80,6 +81,7 @@ func NewCmdValidateCluster(f *util.Factory, out io.Writer) *cobra.Command {
cmd.Flags().StringVarP(&options.output, "output", "o", options.output, "Output format. One of json|yaml|table.")
cmd.Flags().DurationVar(&options.wait, "wait", options.wait, "If set, will wait for cluster to be ready")
cmd.Flags().StringVar(&options.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file")
return cmd
}
@ -126,8 +128,12 @@ func RunValidateCluster(f *util.Factory, cmd *cobra.Command, args []string, out
// TODO: Refactor into util.Factory
contextName := cluster.ObjectMeta.Name
configLoadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
if options.kubeconfig != "" {
configLoadingRules.ExplicitPath = options.kubeconfig
}
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
configLoadingRules,
&clientcmd.ConfigOverrides{CurrentContext: contextName}).ClientConfig()
if err != nil {
return nil, fmt.Errorf("Cannot load kubecfg settings for %q: %v", contextName, err)

View File

@ -30,9 +30,10 @@ kops validate cluster [flags]
### Options
```
-h, --help help for cluster
-o, --output string Output format. One of json|yaml|table. (default "table")
--wait duration If set, will wait for cluster to be ready
-h, --help help for cluster
--kubeconfig string Path to the kubeconfig file
-o, --output string Output format. One of json|yaml|table. (default "table")
--wait duration If set, will wait for cluster to be ready
```
### Options inherited from parent commands