Skip to content

Commit

Permalink
Merge pull request #8110 from vvbogdanov87/validate-cluster-kubeconfig
Browse files Browse the repository at this point in the history
Add kubeconfig flag to validate cluster command
  • Loading branch information
k8s-ci-robot committed Dec 17, 2019
2 parents fc4b21d + 9befa17 commit db11481
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions cmd/kops/validate_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions docs/cli/kops_validate_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db11481

Please sign in to comment.