Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubeconfig flag to validate cluster command #8110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cmd/kops/validate_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,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 @@ -78,6 +79,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 @@ -119,8 +121,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