Skip to content

Commit

Permalink
Merge pull request #7113 from rancher-sandbox/diagnostics-wsl-kubecon…
Browse files Browse the repository at this point in the history
…fig-wsl-helper

Introduces a new flag to support diagnostics.
  • Loading branch information
Nino-K authored Jun 28, 2024
2 parents fe9c1df + 664530d commit be542d6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/go/wsl-helper/cmd/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,21 @@ var kubeconfigCmd = &cobra.Command{
Long: `This command configures the Kubernetes configuration inside a WSL2 distribution.`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

configPath := kubeconfigViper.GetString("kubeconfig")
enable := kubeconfigViper.GetBool("enable")
verify := kubeconfigViper.GetBool("verify")

configDir := path.Join(homedir.HomeDir(), ".kube")
linkPath := path.Join(configDir, "config")
unsupportedConfig, symlinkErr := requireManualSymlink(linkPath)
if verify {
if unsupportedConfig {
os.Exit(1)
}
os.Exit(0)
}

if configPath == "" {
return errors.New("Windows kubeconfig not supplied")
Expand All @@ -57,11 +70,7 @@ var kubeconfigCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("could not open Windows kubeconfig: %w", err)
}
cmd.SilenceUsage = true

configDir := path.Join(homedir.HomeDir(), ".kube")
linkPath := path.Join(configDir, "config")
unsupportedConfig, symlinkErr := requireManualSymlink(linkPath)
if !unsupportedConfig && symlinkErr != nil {
return symlinkErr
}
Expand Down Expand Up @@ -149,6 +158,7 @@ func readKubeConfig(configPath string) (kubeConfig, error) {
}

func init() {
kubeconfigCmd.PersistentFlags().Bool("verify", true, "Checks whether the symlinked config contains non-Rancher Desktop configuration.")
kubeconfigCmd.PersistentFlags().Bool("enable", true, "Set up config file")
kubeconfigCmd.PersistentFlags().String("kubeconfig", "", "Path to Windows kubeconfig, in /mnt/... form.")
kubeconfigViper.AutomaticEnv()
Expand Down

0 comments on commit be542d6

Please sign in to comment.