File kubectl-switch-2.3.0.obscpio of Package kubectl-switch

07070100000000000081A400000000000000000000000168EC2913000000DF000000000000000000000000000000000000002800000000kubectl-switch-2.3.0/.commitlintrc.json{
  "rules": {
    "subject-case": [
      2,
      "never",
      [
        "start-case",
        "pascal-case",
        "upper-case"
      ]
    ],
    "header-max-length": [
      2,
      "always",
      150
    ]
  }
}07070100000001000081A400000000000000000000000168EC29130000007B000000000000000000000000000000000000001C00000000kubectl-switch-2.3.0/.envrcexport KUBECONFIG_DIR="./test/configs/"
export KUBECONFIG="./test/config"
export LOG_LEVEL="error"
export LOG_FORMAT="text"07070100000002000081A400000000000000000000000168EC29130000018B000000000000000000000000000000000000002400000000kubectl-switch-2.3.0/.golangci.yaml---
version: "2"

linters:
  exclusions:
    generated: lax
    presets:
      - comments
      - common-false-positives
      - legacy
      - std-error-handling
    paths:
      - third_party$
      - builtin$
      - examples$

formatters:
  enable:
    - gofmt
    - gofumpt
    - goimports
  exclusions:
    generated: lax
    paths:
      - third_party$
      - builtin$
      - examples$
07070100000003000081A400000000000000000000000168EC291300000F60000000000000000000000000000000000000002600000000kubectl-switch-2.3.0/.goreleaser.yaml---
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2
project_name: kubectl-switch

before:
  hooks:
    - go mod tidy
    - go mod download

builds:
  - env:
      - CGO_ENABLED=0
    binary: "{{.ProjectName}}"
    goos:
      - linux
      - darwin
    ldflags:
      - -s -w -X github.com/mirceanton/{{.ProjectName}}/cmd.version={{.Version}}

archives:
  - format: tar.gz
    name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}"

checksum:
  disable: false
  name_template: "checksums.txt"

changelog:
  disable: false
  use: github
  sort: asc
  groups:
    - title: Features
      regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
      order: 0
    - title: "Patches"
      regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
      order: 1
    - title: "CI"
      regexp: ".*ci.*"
      order: 998
    - title: Others
      order: 999

nfpms:
  - homepage: https://github.com/mirceanton/{{.ProjectName}}
    maintainer: Mircea-Pavel Anton <contact@mirceanton.com>
    description: A simple tool to switch between Kubernetes contexts.
    file_name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}"
    license: MIT
    formats: [deb, apk, rpm]

brews:
  - name: kubectl-switch
    description: A simple tool to switch between Kubernetes contexts.
    license: MIT
    homepage: https://github.com/mirceanton/{{.ProjectName}}
    directory: Formula
    repository:
      owner: mirceanton
      name: homebrew-taps
      token: "{{ .Env.TAP_GITHUB_TOKEN }}"
    test: system "#{bin}/kubectl-switch", "--help"
    commit_author:
      name: mr-borboto[bot]
      email: 170036086+mr-borboto[bot]@users.noreply.github.com

dockers:
  - image_templates:
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-amd64"
    use: buildx
    dockerfile: Dockerfile
    build_flag_templates:
      - "--platform=linux/amd64"
      - "--label=org.opencontainers.image.created={{.Date}}"
      - "--label=org.opencontainers.image.title={{.ProjectName}}"
      - "--label=org.opencontainers.image.revision={{.FullCommit}}"
      - "--label=org.opencontainers.image.version={{.Version}}"
      - "--label=org.opencontainers.image.url=https://github.com/mirceanton/{{.ProjectName}}"
      - "--label=org.opencontainers.image.source=https://github.com/mirceanton/{{.ProjectName}}"
      - "--label=org.opencontainers.image.licenses=MIT"
      - "--label=org.opencontainers.image.authors=Mircea-Pavel Anton <contact@mirceanton.com>"
      - "--label=org.opencontainers.image.description=A simple tool to switch between Kubernetes contexts."
  - image_templates:
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-arm64v8"
    use: buildx
    goarch: arm64
    dockerfile: Dockerfile
    build_flag_templates:
      - "--platform=linux/arm64/v8"
      - "--label=org.opencontainers.image.created={{.Date}}"
      - "--label=org.opencontainers.image.title={{.ProjectName}}"
      - "--label=org.opencontainers.image.revision={{.FullCommit}}"
      - "--label=org.opencontainers.image.version={{.Version}}"
      - "--label=org.opencontainers.image.url=https://github.com/mirceanton/{{.ProjectName}}"
      - "--label=org.opencontainers.image.source=https://github.com/mirceanton/{{.ProjectName}}"
      - "--label=org.opencontainers.image.licenses=MIT"
      - "--label=org.opencontainers.image.authors=Mircea-Pavel Anton <contact@mirceanton.com>"
      - "--label=org.opencontainers.image.description=A simple tool to switch between Kubernetes contexts."

docker_manifests:
  - name_template: "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}"
    image_templates:
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-amd64"
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-arm64v8"

  - name_template: "ghcr.io/mirceanton/{{.ProjectName}}:latest"
    image_templates:
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-amd64"
      - "ghcr.io/mirceanton/{{.ProjectName}}:v{{.Version}}-arm64v8"
07070100000004000081A400000000000000000000000168EC2913000005D9000000000000000000000000000000000000002000000000kubectl-switch-2.3.0/.mise.toml[tools]
# =================================================================================================
# Project Tools -> pinned versions
# =================================================================================================
go = "1.25.2"
"aqua:golangci/golangci-lint" = "2.5.0"
"aqua:goreleaser/goreleaser" = "2.12.5"
"aqua:kubernetes/kubectl" = "1.33.1"


# =================================================================================================
# Misc Tools
# =================================================================================================
"aqua:kubernetes/minikube" = "latest"
"aqua:helm/helm" = "latest"
"aqua:derailed/k9s" = "latest"
direnv = "latest"


# =================================================================================================
# CI Tools
# =================================================================================================
"npm:@commitlint/cli" = "20"
"aqua:rhysd/actionlint" = "1"
"shellcheck" = "0.11"

# =================================================================================================
# TASKS -> GO
# =================================================================================================
[tasks."release"]
description = "Run goreleaser in snapshot mode."
run = "goreleaser release --snapshot --clean"

[tasks."lint"]
description = "Run golangci-lint in fix mode."
run = "golangci-lint run --fix"

[tasks."test"]
description = "Run e2e tests."
run = "bash scripts/test.sh"
07070100000005000081A400000000000000000000000168EC29130000008D000000000000000000000000000000000000002600000000kubectl-switch-2.3.0/.renovaterc.json{
    "$schema": "https://docs.renovatebot.com/renovate-schema.json",
    "extends": [ "github>mirceanton/renovate-config//default.json5" ]
}07070100000006000081A400000000000000000000000168EC291300000072000000000000000000000000000000000000002000000000kubectl-switch-2.3.0/DockerfileFROM gcr.io/distroless/static-debian12:nonroot
USER 8675:8675
COPY kubectl-switch /
ENTRYPOINT ["/kubectl-switch"]07070100000007000081A400000000000000000000000168EC291300000433000000000000000000000000000000000000001D00000000kubectl-switch-2.3.0/LICENSEMIT License

Copyright (c) 2023 Mircea-Pavel Anton

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
07070100000008000081A400000000000000000000000168EC291300001946000000000000000000000000000000000000001F00000000kubectl-switch-2.3.0/README.md# kubectl-switch

`kubectl-switch` is a command-line tool for managing and switching between multiple Kubernetes configuration files located in the same directory. It simplifies the process of selecting a Kubernetes context from multiple kubeconfig files and updating the active configuration or namespace.

Just dump all your `kubeconfigs` into a single dir and let `kubectl-switch` manage them for you!

## Features

- **Multiple kubeconfig files**: Manage multiple kubeconfig files in a single directory without merging them
- **Context & namespace switching**: Switch between contexts and namespaces from multiple config files
- **Interactive & non-interactive modes**: Select from a list or specify directly as an argument (with tab completion support!)

## Why `kubectl-switch`?

`kubectl-switch` is an alternative to tools like `kubectx`, `kubens` and `kubie`. It has been created because I feel all of those fall short in certain regards:

- `kubectx` and `kubens` assume all your contexts are defined in a single config file. Yes, there is some hackery you can do to your `KUBECONFIG` environment variable to make it work with multiple files, but it is (in my opinion) a sub-par workflow and I never really liked it
- `kubie` spawns a new shell when you use it to change contexts, making it practically impossible to integrate into scripts or taskfile automation. Also I consider it to be too complicated of a solution for what is fundamentally a really simple problem

What I wanted was something very simple conceptually: I just want to dump all my `kubeconfig` files in a single directory and then have my tool parse them and "physically" move over the config file to `.kube/config` (or whatever is configured in my `KUBECONFIG` env var) such that it is also persistent between different shells. Here is where `kubectl-switch` comes in!

## Installation

### Install via go install

Install the latest stable version directly using Go:

```bash
# Install the latest version
go install github.com/mirceanton/kubectl-switch/v2@latest

# Or install a specific version
go install github.com/mirceanton/kubectl-switch/v2@v2.2.6
```

> **Note**: Versions prior to v2.2.6 cannot be installed via `go install` due to module path issues. If you need an older version, please use one of the alternative installation methods below.

### Download Precompiled Binaries

Precompiled binaries are available for various platforms. You can download the latest release from the [GitHub Releases page](https://github.com/mirceanton/kubectl-switch/releases/latest).

1. Download the appropriate binary for your system and extract the archive.
2. Make the extracted binary executable:

   ```bash
   chmod +x kubectl-switch
   ```

3. Move the binary to a directory in your PATH:

   ```bash
   mv kubectl-switch /usr/local/bin/kubectl-switch
   ```

### Install via Homebrew

1. Add the tap

   ```bash
   brew tap mirceanton/taps
   ```

2. Install `kubectl-switch`

   ```bash
   brew install kubectl-switch
   ```

### Running via Docker

`kubectl-switch` is also available as a Docker container:

```bash
docker pull ghcr.io/mirceanton/kubectl-switch
```

To use it with your local kubeconfig files:

```bash
docker run -v ~/.kube:/root/.kube -v /path/to/kubeconfigs:/kubeconfigs \
    -e KUBECONFIG_DIR=/kubeconfigs \
    ghcr.io/mirceanton/kubectl-switch context
```

### Build from Source

1. Clone the repository:

   ```bash
   git clone https://github.com/mirceanton/kubectl-switch
   cd kubectl-switch
   ```

2. Build the tool:

   ```bash
   go build -o kubectl-switch
   ```

3. Move the binary to your PATH:

   ```bash
   mv kubectl-switch /usr/local/bin/kubectl-switch
   ```

## Usage

### Context Command

The `context` (or `ctx`) subcommand is used to switch between Kubernetes contexts (think of `kubectx`):

```bash
# Interactive mode - select context from a list
kubectl-switch context

# Switch to a specific context
kubectl-switch ctx my-context
```

### Namespace Command

The `namespace` (or `ns`) subcommand is used to switch the current namespace (think of `kubens`):

```bash
# Interactive mode - select namespace from a list
kubectl-switch namespace

# Switch to a specific namespace
kubectl-switch ns kube-system
```

### Quickly Switch to Previous Configuration

Switch back to the previous configuration:

```bash
kubectl-switch -
```

### Usage with kubectl plugin

When installed as a kubectl plugin, you can use it directly with the `kubectl` command:

```sh
# These commands are equivalent
kubectl-switch ctx
kubectl switch ctx
```

## Configuration

`kubectl-switch` uses Viper for configuration management, allowing you to configure the tool via command-line flags or environment variables, with flags taking precedence.

### Configuration Options

| Option               | Flag               | Environment Variable | Default            | Description                                                       |
| -------------------- | ------------------ | -------------------- | ------------------ | ----------------------------------------------------------------- |
| Kubeconfig Directory | `--kubeconfig-dir` | `KUBECONFIG_DIR`     | `~/.kube/configs/` | Directory containing your kubeconfig files                        |
| Kubeconfig           | `--kubeconfig`     | `KUBECONFIG`         | `~/.kube/config`   | Path to the currently active kubeconfig file.                     |
| Log Level            | `--log-level`      | `LOG_LEVEL`          | `info`             | Logging verbosity (trace, debug, info, warn, error, fatal, panic) |
| Log Format           | `--log-format`     | `LOG_FORMAT`         | `text`             | Log output format (text, json)                                    |

## Shell Completion

The `completion` subcommand generates shell completion scripts:

```bash
# Generate completions for bash
kubectl-switch completion bash > /etc/bash_completion.d/kubectl-switch

# Generate completions for zsh
kubectl-switch completion zsh > ~/.zsh/completion/_kubectl-switch

# Generate completions for fish
kubectl-switch completion fish > ~/.config/fish/completions/kubectl-switch.fish

# Generate completions for powershell
kubectl-switch completion powershell > ~/kubectl-switch.ps1
```

## Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.

## License

This project is licensed under the MIT License. See the [`LICENSE`](./LICENSE) file for details.
07070100000009000041ED00000000000000000000000268EC291300000000000000000000000000000000000000000000001900000000kubectl-switch-2.3.0/cmd0707010000000A000081A400000000000000000000000168EC29130000052D000000000000000000000000000000000000002400000000kubectl-switch-2.3.0/cmd/context.gopackage cmd

import (
	"github.com/AlecAivazis/survey/v2"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

var contextCmd = &cobra.Command{
	Use:               "context",
	Aliases:           []string{"ctx"},
	Short:             "Switch the active Kubernetes context",
	ValidArgsFunction: getContextCompletions,
	Args:              cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		contextNames := configManager.GetAllContexts()
		if len(contextNames) == 0 {
			log.Fatal("No kubernetes contexts found in the provided directory")
		}

		var selectedContext string
		if len(args) == 1 {
			selectedContext = args[0]
		} else {
			prompt := &survey.Select{
				Message: "Choose a context:",
				Options: contextNames,
			}
			if err := survey.AskOne(prompt, &selectedContext); err != nil {
				log.Fatalf("Failed to get user input: %v", err)
			}
		}

		if err := configManager.SwitchToContext(selectedContext); err != nil {
			log.Fatalf("Failed to switch context: %v", err)
		}

		log.Infof("Switched to context '%s'", selectedContext)
	},
}

func init() {
	rootCmd.AddCommand(contextCmd)
}

func getContextCompletions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	return configManager.GetAllContexts(), cobra.ShellCompDirectiveNoFileComp
}
0707010000000B000081A400000000000000000000000168EC291300000553000000000000000000000000000000000000002600000000kubectl-switch-2.3.0/cmd/namespace.gopackage cmd

import (
	"github.com/AlecAivazis/survey/v2"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

var namespaceCmd = &cobra.Command{
	Use:               "namespace",
	Aliases:           []string{"ns"},
	Short:             "Switch the active Kubernetes namespace",
	Args:              cobra.MaximumNArgs(1),
	ValidArgsFunction: getNamespaceCompletions,
	Run: func(cmd *cobra.Command, args []string) {
		namespaceNames := configManager.GetAllNamespaces()
		if len(namespaceNames) == 0 {
			log.Fatal("No kubernetes namespaces found in the current cluster")
		}

		var selectedNamespace string
		if len(args) == 1 {
			selectedNamespace = args[0]
		} else {
			prompt := &survey.Select{
				Message: "Choose a namespace:",
				Options: namespaceNames,
			}
			if err := survey.AskOne(prompt, &selectedNamespace); err != nil {
				log.Fatalf("Failed to get user input: %v", err)
			}
		}

		if err := configManager.SwitchToNamespace(selectedNamespace); err != nil {
			log.Fatalf("Failed to switch namespace: %v", err)
		}

		log.Infof("Switched to namespace '%s'", selectedNamespace)
	},
}

func init() {
	rootCmd.AddCommand(namespaceCmd)
}

func getNamespaceCompletions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	return configManager.GetAllNamespaces(), cobra.ShellCompDirectiveNoFileComp
}
0707010000000C000081A400000000000000000000000168EC2913000009DD000000000000000000000000000000000000002100000000kubectl-switch-2.3.0/cmd/root.gopackage cmd

import (
	"os"

	"github.com/mirceanton/kubectl-switch/v2/internal/config"
	"github.com/mirceanton/kubectl-switch/v2/internal/manager"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var (
	version       string
	configManager *manager.Manager
)

var rootCmd = &cobra.Command{
	Use: "kubectl-switch",
	Annotations: map[string]string{
		cobra.CommandDisplayNameAnnotation: "kubectl switch",
	},
	Short:   "A tool to switch Kubernetes contexts",
	Long:    `kubectl-switch is a CLI tool to switch Kubernetes contexts from multiple kubeconfig files.`,
	Version: version,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		// Load configuration
		cfg, err := config.Load()
		if err != nil {
			return err
		}

		// Set up logging
		log.SetLevel(cfg.LogLevel)
		log.SetFormatter(cfg.LogFormat)

		// Create manager with config
		configManager, err = manager.NewManager(cfg.Kubeconfig, cfg.KubeconfigDir)
		if err != nil {
			return err
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 1 && args[0] == "-" {
			if err := configManager.Restore(); err != nil {
				log.Fatalf("Failed to switch to previous config: %v", err)
			}
			return nil
		}
		return cmd.Help()
	},
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		os.Exit(1)
	}
}

func init() {
	// Initialize Viper
	cobra.OnInitialize(config.Init)

	// Bind flags to Viper
	rootCmd.PersistentFlags().String("kubeconfig-dir", "", "Directory containing kubeconfig files (env: KUBECONFIG_DIR)")
	err := viper.BindPFlag("kubeconfig-dir", rootCmd.PersistentFlags().Lookup("kubeconfig-dir"))
	if err != nil {
		log.Fatalf("Failed to bind flag: %v", err)
	}

	rootCmd.PersistentFlags().String("kubeconfig", "", "Currently active kubeconfig file (env: KUBECONFIG)")
	err = viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
	if err != nil {
		log.Fatalf("Failed to bind flag: %v", err)
	}

	rootCmd.PersistentFlags().String("log-level", "info", "Log level (trace, debug, info, warn, error, fatal, panic) (env: LOG_LEVEL)")
	err = viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level"))
	if err != nil {
		log.Fatalf("Failed to bind flag: %v", err)
	}

	rootCmd.PersistentFlags().String("log-format", "text", "Log format (text, json) (env: LOG_FORMAT)")
	err = viper.BindPFlag("log-format", rootCmd.PersistentFlags().Lookup("log-format"))
	if err != nil {
		log.Fatalf("Failed to bind flag: %v", err)
	}
}
0707010000000D000081A400000000000000000000000168EC291300000BB6000000000000000000000000000000000000001C00000000kubectl-switch-2.3.0/go.modmodule github.com/mirceanton/kubectl-switch/v2

go 1.24.0

// v2 versions without /v2 in module path
retract [v2.0.0, v2.2.5]

require (
	github.com/AlecAivazis/survey/v2 v2.3.7
	github.com/sirupsen/logrus v1.9.3
	github.com/spf13/cobra v1.10.1
	github.com/spf13/viper v1.21.0
	k8s.io/apimachinery v0.34.1
	k8s.io/client-go v0.34.1
)

require (
	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
	github.com/emicklei/go-restful/v3 v3.12.2 // indirect
	github.com/fsnotify/fsnotify v1.9.0 // indirect
	github.com/fxamacker/cbor/v2 v2.9.0 // indirect
	github.com/go-logr/logr v1.4.2 // indirect
	github.com/go-openapi/jsonpointer v0.21.0 // indirect
	github.com/go-openapi/jsonreference v0.20.2 // indirect
	github.com/go-openapi/swag v0.23.0 // indirect
	github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
	github.com/gogo/protobuf v1.3.2 // indirect
	github.com/google/gnostic-models v0.7.0 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/inconshreveable/mousetrap v1.1.0 // indirect
	github.com/josharian/intern v1.0.0 // indirect
	github.com/json-iterator/go v1.1.12 // indirect
	github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
	github.com/mailru/easyjson v0.7.7 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
	github.com/pelletier/go-toml/v2 v2.2.4 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/sagikazarmark/locafero v0.11.0 // indirect
	github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
	github.com/spf13/afero v1.15.0 // indirect
	github.com/spf13/cast v1.10.0 // indirect
	github.com/spf13/pflag v1.0.10 // indirect
	github.com/subosito/gotenv v1.6.0 // indirect
	github.com/x448/float16 v0.8.4 // indirect
	go.yaml.in/yaml/v2 v2.4.2 // indirect
	go.yaml.in/yaml/v3 v3.0.4 // indirect
	golang.org/x/net v0.38.0 // indirect
	golang.org/x/oauth2 v0.27.0 // indirect
	golang.org/x/sys v0.31.0 // indirect
	golang.org/x/term v0.30.0 // indirect
	golang.org/x/text v0.28.0 // indirect
	golang.org/x/time v0.9.0 // indirect
	google.golang.org/protobuf v1.36.5 // indirect
	gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
	gopkg.in/inf.v0 v0.9.1 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
	k8s.io/api v0.34.1 // indirect
	k8s.io/klog/v2 v2.130.1 // indirect
	k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
	k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
	sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
	sigs.k8s.io/randfill v1.0.0 // indirect
	sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
	sigs.k8s.io/yaml v1.6.0 // indirect
)
0707010000000E000081A400000000000000000000000168EC2913000051C2000000000000000000000000000000000000001C00000000kubectl-switch-2.3.0/go.sumgithub.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.12.2 h1:DhwDP0vY3k8ZzE0RunuJy8GhNpPL6zqLkDf9B/a0/xU=
github.com/emicklei/go-restful/v3 v3.12.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8=
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
k8s.io/client-go v0.34.1 h1:ZUPJKgXsnKwVwmKKdPfw4tB58+7/Ik3CrjOEhsiZ7mY=
k8s.io/client-go v0.34.1/go.mod h1:kA8v0FP+tk6sZA0yKLRG67LWjqufAoSHA2xVGKw9Of8=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA=
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts=
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y=
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco=
sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
0707010000000F000041ED00000000000000000000000268EC291300000000000000000000000000000000000000000000001E00000000kubectl-switch-2.3.0/internal07070100000010000041ED00000000000000000000000268EC291300000000000000000000000000000000000000000000002500000000kubectl-switch-2.3.0/internal/config07070100000011000081A400000000000000000000000168EC291300000F2C000000000000000000000000000000000000002F00000000kubectl-switch-2.3.0/internal/config/config.gopackage config

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	log "github.com/sirupsen/logrus"

	"github.com/spf13/viper"
)

// Config holds all configuration for the application
type Config struct {
	KubeconfigDir string
	Kubeconfig    string
	LogLevel      log.Level
	LogFormat     log.Formatter
}

const (
	// Configuration keys
	keyKubeconfigDir = "kubeconfig-dir"
	keyKubeconfig    = "kubeconfig"
	keyLogLevel      = "log-level"
	keyLogFormat     = "log-format"

	// Default values
	defaultLogLevel  = "info"
	defaultLogFormat = "text"
)

var (
	defaultKubeconfigDir = filepath.Join(os.Getenv("HOME"), ".kube", "configs/")
	defaultKubeconfig    = filepath.Join(os.Getenv("HOME"), ".kube", "config")
)

// Init initializes Viper configuration
func Init() {
	// Enable reading from environment variables
	viper.AutomaticEnv()

	// Replace hyphens with underscores in env vars
	// This allows --kubeconfig-dir to map to KUBECONFIG_DIR
	viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

	// Set default values
	viper.SetDefault(keyKubeconfigDir, defaultKubeconfigDir)
	viper.SetDefault(keyKubeconfig, defaultKubeconfig)
	viper.SetDefault(keyLogLevel, defaultLogLevel)
	viper.SetDefault(keyLogFormat, defaultLogFormat)
}

// Load returns the current configuration
func Load() (*Config, error) {
	cfg := &Config{}

	// Parse log level
	levelStr := viper.GetString(keyLogLevel)
	level, err := log.ParseLevel(levelStr)
	if err != nil {
		return nil, fmt.Errorf("invalid log level: %s", levelStr)
	}
	cfg.LogLevel = level

	// Parse log format
	formatStr := viper.GetString(keyLogFormat)
	switch strings.ToLower(formatStr) {
	case "json":
		cfg.LogFormat = &log.JSONFormatter{}
	case "text":
		cfg.LogFormat = &log.TextFormatter{FullTimestamp: true}
	default:
		return nil, fmt.Errorf("invalid log format: %s", formatStr)
	}

	// Expand and validate kubeconfig dir path
	cfg.KubeconfigDir, err = expandPath(viper.GetString(keyKubeconfigDir))
	if err != nil {
		return nil, fmt.Errorf("failed to expand kubeconfig directory path: %w", err)
	}
	if err := cfg.validateKubeconfigDir(); err != nil {
		return nil, err
	}

	// Expand and validate kubeconfig dir path
	cfg.Kubeconfig, err = expandPath(viper.GetString(keyKubeconfig))
	if err != nil {
		return nil, fmt.Errorf("failed to expand kubeconfig path: %w", err)
	}
	if err := cfg.validateKubeconfig(); err != nil {
		log.Warnf("Kubeconfig file validation failed: %v", err)
		log.Warn("You can still switch contexts, but namespace operations will not be available")
	}

	return cfg, nil
}

// validateKubeconfigDir validates that the kubeconfig directory exists and is a directory
func (c *Config) validateKubeconfigDir() error {
	info, err := os.Stat(c.KubeconfigDir)
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("kubeconfig directory does not exist: %s", c.KubeconfigDir)
		}
		return fmt.Errorf("failed to stat kubeconfig directory: %w", err)
	}

	if !info.IsDir() {
		return fmt.Errorf("kubeconfig directory path is not a directory: %s", c.KubeconfigDir)
	}

	return nil
}

// validateKubeconfig validates that the kubeconfig file exists and is a file
func (c *Config) validateKubeconfig() error {
	info, err := os.Stat(c.Kubeconfig)
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("kubeconfig file does not exist: %s", c.Kubeconfig)
		}
		return fmt.Errorf("failed to stat kubeconfig file: %w", err)
	}

	if info.IsDir() {
		return fmt.Errorf("kubeconfig path is a directory, expected a file: %s", c.Kubeconfig)
	}

	return nil
}

// expandPath expands a path starting with ~/ to the full home directory path.
func expandPath(path string) (string, error) {
	if !strings.HasPrefix(path, "~/") {
		return path, nil
	}

	homeDir, err := os.UserHomeDir()
	if err != nil {
		return "", fmt.Errorf("failed to get home directory: %w", err)
	}

	return filepath.Join(homeDir, path[2:]), nil
}
07070100000012000041ED00000000000000000000000268EC291300000000000000000000000000000000000000000000002600000000kubectl-switch-2.3.0/internal/manager07070100000013000081A400000000000000000000000168EC291300001946000000000000000000000000000000000000003100000000kubectl-switch-2.3.0/internal/manager/manager.gopackage manager

import (
	"context"
	"fmt"
	"os"
	"path/filepath"

	log "github.com/sirupsen/logrus"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

// Manager handles kubeconfig file operations and Kubernetes context switching.
type Manager struct {
	kubeconfigPath string
	backupPath     string
	kubeconfigDir  string
	contextMap     map[string]string
	contextNames   []string
	namespaceNames []string
}

// NewManager creates a new kubeconfig Manager instance.
// It takes the validated configuration paths and loads available contexts.
func NewManager(kubeconfigPath, kubeconfigDir string) (*Manager, error) {
	m := &Manager{
		kubeconfigPath: kubeconfigPath,
		kubeconfigDir:  kubeconfigDir,
		backupPath:     kubeconfigPath + ".previous",
	}

	// Load available contexts from the config directory
	if err := m.loadContexts(); err != nil {
		return nil, fmt.Errorf("failed to load contexts: %w", err)
	}

	// Load available namespaces from the current cluster
	// This may fail if no kubeconfig is active, which is OK
	if err := m.loadNamespaces(); err != nil {
		log.Warnf("Failed to load namespaces: %v", err)
		log.Warn("Namespace operations will not be available until a valid context is selected")
		m.namespaceNames = []string{} // Initialize to empty slice
	}

	return m, nil
}

// GetAllContexts returns the available context names.
func (m *Manager) GetAllContexts() []string {
	return m.contextNames
}

// GetAllNamespaces retrieves all namespaces from the current Kubernetes cluster.
func (m *Manager) GetAllNamespaces() []string {
	return m.namespaceNames
}

// SwitchToContext switches to the specified Kubernetes context.
func (m *Manager) SwitchToContext(contextName string) error {
	// Find the kubeconfig file containing the desired context
	contextFilePath, exists := m.contextMap[contextName]
	if !exists {
		return fmt.Errorf("context '%s' not found", contextName)
	}

	// Load the kubeconfig file containing the desired context
	kubeconfig, err := clientcmd.LoadFromFile(contextFilePath)
	if err != nil {
		return fmt.Errorf("failed to load kubeconfig from %s: %w", contextFilePath, err)
	}

	// Update the current context in the loaded kubeconfig
	kubeconfig.CurrentContext = contextName

	// Backup current config
	if err := m.backup(); err != nil {
		log.Warnf("Failed to save current configuration as previous: %v", err)
	}

	// Write updated kubeconfig back to the main kubeconfig file
	if err := clientcmd.WriteToFile(*kubeconfig, m.kubeconfigPath); err != nil {
		return fmt.Errorf("failed to write kubeconfig: %w", err)
	}

	return nil
}

// SwitchToNamespace switches the namespace for the current context.
func (m *Manager) SwitchToNamespace(namespace string) error {
	// Parse current kubeconfig
	kubeconfig, err := clientcmd.LoadFromFile(m.kubeconfigPath)
	if err != nil {
		return fmt.Errorf("failed to load current kubeconfig: %w", err)
	}

	// Update namespace for current context
	kubeconfig.Contexts[kubeconfig.CurrentContext].Namespace = namespace

	// Backup current config
	if err := m.backup(); err != nil {
		log.Warnf("Failed to save current configuration as previous: %v", err)
	}

	// Write updated kubeconfig back to file
	if err := clientcmd.WriteToFile(*kubeconfig, m.kubeconfigPath); err != nil {
		return fmt.Errorf("failed to write kubeconfig: %w", err)
	}

	return nil
}

// Restore swaps the current kubeconfig with the previous backup.
func (m *Manager) Restore() error {
	// Read current kubeconfig
	currentConfig, err := os.ReadFile(m.kubeconfigPath)
	if err != nil {
		return fmt.Errorf("failed to read current config: %w", err)
	}

	// Read backup kubeconfig
	prevConfig, err := os.ReadFile(m.backupPath)
	if err != nil {
		return fmt.Errorf("failed to read previous config: %w", err)
	}

	// Swap the files
	if err := os.WriteFile(m.kubeconfigPath, prevConfig, 0o600); err != nil {
		return fmt.Errorf("failed to write current config: %w", err)
	}
	if err := os.WriteFile(m.backupPath, currentConfig, 0o600); err != nil {
		return fmt.Errorf("failed to write previous config: %w", err)
	}

	return nil
}

// ================================================================================================
// Helper functions
// ================================================================================================

// backup backs up the current kubeconfig to config.previous.
func (m *Manager) backup() error {
	data, err := os.ReadFile(m.kubeconfigPath)
	if err != nil {
		return fmt.Errorf("failed to read current kubeconfig: %w", err)
	}

	if err := os.WriteFile(m.backupPath, data, 0o600); err != nil {
		return fmt.Errorf("failed to write previous kubeconfig: %w", err)
	}

	return nil
}

// loadContexts scans the config directory for kubeconfig files and loads all available contexts.
func (m *Manager) loadContexts() error {
	m.contextMap = make(map[string]string)
	m.contextNames = nil

	files, err := os.ReadDir(m.kubeconfigDir)
	if err != nil {
		return fmt.Errorf("failed to read config directory: %w", err)
	}

	for _, file := range files {
		if file.IsDir() {
			continue
		}

		path := filepath.Join(m.kubeconfigDir, file.Name())
		kubeconfig, err := clientcmd.LoadFromFile(path)
		if err != nil {
			log.WithField("file", file.Name()).Warnf("Failed to parse kubeconfig file: %v", err)
			continue
		}

		for contextName := range kubeconfig.Contexts {
			if existingPath, exists := m.contextMap[contextName]; exists {
				log.Warnf("Duplicate context name '%s' found in files:\n  - %s\n  - %s",
					contextName, existingPath, path)
				continue
			}
			m.contextMap[contextName] = path
			m.contextNames = append(m.contextNames, contextName)
		}
	}

	return nil
}

// loadNamespaces loads all namespaces from the current Kubernetes cluster.
func (m *Manager) loadNamespaces() error {
	config, err := clientcmd.BuildConfigFromFlags("", m.kubeconfigPath)
	if err != nil {
		return fmt.Errorf("failed to build config: %w", err)
	}

	clientset, err := kubernetes.NewForConfig(config)
	if err != nil {
		return fmt.Errorf("failed to create clientset: %w", err)
	}

	namespaces, err := clientset.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		return fmt.Errorf("failed to list namespaces: %w", err)
	}

	m.namespaceNames = make([]string, 0, len(namespaces.Items))
	for _, ns := range namespaces.Items {
		m.namespaceNames = append(m.namespaceNames, ns.Name)
	}

	return nil
}
07070100000014000081A400000000000000000000000168EC291300000068000000000000000000000000000000000000001D00000000kubectl-switch-2.3.0/main.gopackage main

import (
	"github.com/mirceanton/kubectl-switch/v2/cmd"
)

func main() {
	cmd.Execute()
}
07070100000015000041ED00000000000000000000000268EC291300000000000000000000000000000000000000000000001D00000000kubectl-switch-2.3.0/scripts07070100000016000081A400000000000000000000000168EC291300000D9B000000000000000000000000000000000000002500000000kubectl-switch-2.3.0/scripts/test.sh#!/bin/bash
set -e

# Create config directory if it doesn't exist
export KUBECONFIG="./test/config"
export KUBECONFIG_DIR="./test/configs/"
mkdir -p $KUBECONFIG_DIR


setup() {
    echo "Performing setup..."

    # Build kubectl-switch
    echo "Building kubectl-switch..."
    go build -o kubectl-switch

    # Set up Kubernetes clusters
    echo "Setting up test clusters..."
    KUBECONFIG=$KUBECONFIG_DIR/cluster1.yaml minikube start -p test-cluster-1 &
    KUBECONFIG=$KUBECONFIG_DIR/cluster2.yaml minikube start -p test-cluster-2 &
    wait

    echo "Setup completed."
}

cleanup() {
    echo "Performing cleanup..."

    # Stop and delete minikube clusters
    echo "Stopping and deleting test-cluster-1..."
    KUBECONFIG=$KUBECONFIG_DIR/cluster1.yaml minikube stop -p test-cluster-1 || true
    KUBECONFIG=$KUBECONFIG_DIR/cluster1.yaml minikube delete -p test-cluster-1 || true

    echo "Stopping and deleting test-cluster-2..."
    KUBECONFIG=$KUBECONFIG_DIR/cluster2.yaml minikube stop -p test-cluster-2 || true
    KUBECONFIG=$KUBECONFIG_DIR/cluster2.yaml minikube delete -p test-cluster-2 || true

    # Remove config directory
    echo "Removing test directory..."
    rm -rf tests/
    rm kubectl-switch

    echo "Cleanup completed."
}


run_tests() {
    echo "Running tests..."

    # Test cluster switching and namespace operations
    echo "Switching context to test-cluster-1..."
    ./kubectl-switch context test-cluster-1

    echo "Validating cluster switch to test-cluster-1..."
    kubectl get nodes | grep "test-cluster-1" || {
        echo "Error: test-cluster-1 not found in node list!" >&2
        exit 1
    }

    echo "Checking no pods in default namespace..."
    kubectl get pods --namespace=default 2>&1 | grep "No resources found" || {
        echo "Error: Pods found in default namespace!" >&2
        exit 1
    }

    echo "Switching to kube-system namespace..."
    ./kubectl-switch namespace kube-system

    echo "Validating kube-system namespace selection and kube-apiserver running..."
    kubectl get pods --namespace=kube-system | grep "kube-apiserver" || {
        echo "Error: kube-apiserver not found in kube-system!" >&2
        exit 1
    }

    echo "Switching back to default namespace..."
    ./kubectl-switch namespace default

    echo "Checking again that no pods are in default namespace..."
    kubectl get pods --namespace=default 2>&1 | grep "No resources found" || {
        echo "Error: Pods found in default namespace!" >&2
        exit 1
    }

    echo "Switching context to test-cluster-2..."
    ./kubectl-switch context test-cluster-2

    echo "Validating cluster switch to test-cluster-2..."
    kubectl get nodes | grep "test-cluster-2" || {
        echo "Error: test-cluster-2 not found in node list!" >&2
        exit 1
    }

    echo "Switching to previous context..."
    ./kubectl-switch -

    echo "Validating cluster switch to test-cluster-1..."
    kubectl get nodes | grep "test-cluster-1" || {
        echo "Error: test-cluster-1 not found in node list!" >&2
        exit 1
    }
    echo "========================================================================================="
    echo "Tests completed successfully!"
    echo "========================================================================================="
}

# Set up trap to ensure cleanup happens on exit
trap cleanup EXIT

# Main execution
echo "Starting E2E tests..."
setup
run_tests
echo "E2E tests completed successfully!"
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!119 blocks
openSUSE Build Service is sponsored by