mirror of
https://github.com/ahmetb/kubectx.git
synced 2026-03-09 15:32:15 +00:00
Compare commits
55 Commits
v0.9.1
...
feature/ky
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
741e2b9986 | ||
|
|
ed644ff0a6 | ||
|
|
004cdecf2b | ||
|
|
267d8dd5a8 | ||
|
|
4a91c2170a | ||
|
|
042d269721 | ||
|
|
4c9e8fb81e | ||
|
|
5a29645996 | ||
|
|
c52b598c2c | ||
|
|
013b6bc252 | ||
|
|
0bcd0d5dd5 | ||
|
|
561793c356 | ||
|
|
b5daf2cef7 | ||
|
|
4997a261dc | ||
|
|
8fb8c9f2f2 | ||
|
|
11c19c0fb7 | ||
|
|
92e5b5f43b | ||
|
|
33c27c03b2 | ||
|
|
7560b8f04f | ||
|
|
d8ff2847ba | ||
|
|
da454d8a0c | ||
|
|
021c1bc736 | ||
|
|
29850e1a75 | ||
|
|
7d6b179aed | ||
|
|
e5e7f53336 | ||
|
|
e6de7ba0a2 | ||
|
|
b6b364685a | ||
|
|
617e4f0562 | ||
|
|
60523045a5 | ||
|
|
38117be348 | ||
|
|
f123e3864e | ||
|
|
207dd606bb | ||
|
|
bdb1ea9e9d | ||
|
|
a509657288 | ||
|
|
e449e739f8 | ||
|
|
33212062fb | ||
|
|
13695147d1 | ||
|
|
58a5c4693e | ||
|
|
979012e094 | ||
|
|
ff2f9661a2 | ||
|
|
34e9024835 | ||
|
|
3504e66edb | ||
|
|
55548e15ed | ||
|
|
9b4aea3b59 | ||
|
|
767218a9a6 | ||
|
|
438ba19fb0 | ||
|
|
1e49c336fc | ||
|
|
8c323c5653 | ||
|
|
9527e308e5 | ||
|
|
8241576f28 | ||
|
|
5aba9fa311 | ||
|
|
a8a63da51c | ||
|
|
8c8aeada3d | ||
|
|
ab50545ecd | ||
|
|
51c61b862d |
42
.github/workflows/ci.yml
vendored
42
.github/workflows/ci.yml
vendored
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Go implementation (CI)
|
||||
on:
|
||||
push:
|
||||
@@ -9,23 +23,37 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
go-version: '1.22'
|
||||
- id: go-cache-paths
|
||||
run: |
|
||||
echo "::set-output name=go-build::$(go env GOCACHE)"
|
||||
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
|
||||
- name: Go Build Cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.go-cache-paths.outputs.go-build }}
|
||||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
|
||||
- name: Go Mod Cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.go-cache-paths.outputs.go-mod }}
|
||||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
|
||||
- name: Ensure gofmt
|
||||
run: test -z "$(gofmt -s -d .)"
|
||||
- name: Ensure go.mod is already tidied
|
||||
run: go mod tidy && git diff --no-patch --exit-code
|
||||
run: go mod tidy && git diff --exit-code
|
||||
- name: Run unit tests
|
||||
run: go test ./...
|
||||
- name: Build with Goreleaser
|
||||
uses: goreleaser/goreleaser-action@v1
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --snapshot --skip-publish --rm-dist
|
||||
args: release --snapshot --skip publish,snapcraft --clean
|
||||
- name: Setup BATS framework
|
||||
run: sudo npm install -g bats
|
||||
- name: kubectx (Go) integration tests
|
||||
run: COMMAND=./dist/kubectx_linux_amd64/kubectx bats test/kubectx.bats
|
||||
run: COMMAND=./dist/kubectx_linux_amd64_v1/kubectx bats test/kubectx.bats
|
||||
- name: kubens (Go) integration tests
|
||||
run: COMMAND=./dist/kubens_linux_amd64/kubens bats test/kubens.bats
|
||||
run: COMMAND=./dist/kubens_linux_amd64_v1/kubens bats test/kubens.bats
|
||||
|
||||
36
.github/workflows/release.yml
vendored
36
.github/workflows/release.yml
vendored
@@ -1,3 +1,17 @@
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
@@ -5,19 +19,29 @@ on:
|
||||
- 'v*.*.*'
|
||||
jobs:
|
||||
goreleaser:
|
||||
permissions:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- run: git fetch --tags
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
go-version: '1.22'
|
||||
- name: Install Snapcraft
|
||||
uses: samuelmeuli/action-snapcraft@v1
|
||||
- name: Setup Snapcraft
|
||||
run: |
|
||||
# https://github.com/goreleaser/goreleaser/issues/1715
|
||||
mkdir -p $HOME/.cache/snapcraft/download
|
||||
mkdir -p $HOME/.cache/snapcraft/stage-packages
|
||||
- name: GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v1
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Update new version for plugin 'ctx' in krew-index
|
||||
@@ -28,3 +52,7 @@ jobs:
|
||||
uses: rajatjindal/krew-release-bot@v0.0.38
|
||||
with:
|
||||
krew_template_file: .krew/ns.yaml
|
||||
- name: Publish Snaps to the Snap Store (stable channel)
|
||||
run: for snap in $(ls dist/*.snap); do snapcraft upload --release=stable $snap; done
|
||||
env:
|
||||
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This is an example goreleaser.yaml file with some sane defaults.
|
||||
# Make sure to check the documentation at http://goreleaser.com
|
||||
|
||||
version: 2
|
||||
before:
|
||||
hooks:
|
||||
- go mod download
|
||||
@@ -17,6 +35,8 @@ builds:
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
- ppc64le
|
||||
- s390x
|
||||
goarm: [6, 7]
|
||||
- id: kubens
|
||||
main: ./cmd/kubens
|
||||
@@ -31,11 +51,19 @@ builds:
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
- ppc64le
|
||||
- s390x
|
||||
goarm: [6, 7]
|
||||
archives:
|
||||
- id: kubectx-archive
|
||||
name_template: |-
|
||||
kubectx_{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
|
||||
kubectx_{{ .Tag }}_{{ .Os }}_
|
||||
{{- with .Arch -}}
|
||||
{{- if (eq . "386") -}}i386
|
||||
{{- else if (eq . "amd64") -}}x86_64
|
||||
{{- else -}}{{- . -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
{{- with .Arm -}}
|
||||
{{- if (eq . "6") -}}hf
|
||||
{{- else -}}v{{- . -}}
|
||||
@@ -43,16 +71,19 @@ archives:
|
||||
{{- end -}}
|
||||
builds:
|
||||
- kubectx
|
||||
replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files: ["LICENSE"]
|
||||
- id: kubens-archive
|
||||
name_template: |-
|
||||
kubens_{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
|
||||
kubens_{{ .Tag }}_{{ .Os }}_
|
||||
{{- with .Arch -}}
|
||||
{{- if (eq . "386") -}}i386
|
||||
{{- else if (eq . "amd64") -}}x86_64
|
||||
{{- else -}}{{- . -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
{{- with .Arm -}}
|
||||
{{- if (eq . "6") -}}hf
|
||||
{{- else -}}v{{- . -}}
|
||||
@@ -60,9 +91,6 @@ archives:
|
||||
{{- end -}}
|
||||
builds:
|
||||
- kubens
|
||||
replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
@@ -74,3 +102,20 @@ release:
|
||||
extra_files:
|
||||
- glob: ./kubens
|
||||
- glob: ./kubectx
|
||||
snapcrafts:
|
||||
- id: kubectx
|
||||
name: kubectx
|
||||
summary: 'kubectx + kubens: Power tools for kubectl'
|
||||
description: |
|
||||
kubectx is a tool to switch between contexts (clusters) on kubectl faster.
|
||||
kubens is a tool to switch between Kubernetes namespaces (and configure them for kubectl) easily.
|
||||
grade: stable
|
||||
confinement: classic
|
||||
base: core20
|
||||
apps:
|
||||
kubectx:
|
||||
command: kubectx
|
||||
completer: completion/kubectx.bash
|
||||
kubens:
|
||||
command: kubens
|
||||
completer: completion/kubens.bash
|
||||
|
||||
353
README.md
353
README.md
@@ -2,116 +2,110 @@
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
[/badge.svg)](https://github.com/ahmetb/kubectx/actions?query=workflow%3A"Go+implementation+(CI)")
|
||||

|
||||
|
||||
This repository provides both `kubectx` and `kubens` tools.
|
||||
[Install →](#installation)
|
||||
|
||||
> **🥳📰 NEWS:** With v0.9.0 `kubectx` and `kubens` **are now rewritten in Go**.
|
||||
> (Don't worry, our lovely **bash** versions are still available!) Please test
|
||||
> this new Go binaries by downloading them from
|
||||
> [**Releases →**](https://github.com/ahmetb/kubectx/releases)
|
||||
## What are `kubectx` and `kubens`?
|
||||
|
||||
**`kubectx`** helps you switch between clusters back and forth:
|
||||
**kubectx** is a tool to switch between contexts (clusters) on kubectl
|
||||
faster.<br/>
|
||||
**kubens** is a tool to switch between Kubernetes namespaces (and
|
||||
configure them for kubectl) easily.
|
||||
|
||||
Here's a **`kubectx`** demo:
|
||||

|
||||
|
||||
**`kubens`** helps you switch between Kubernetes namespaces smoothly:
|
||||
...and here's a **`kubens`** demo:
|
||||

|
||||
|
||||
# kubectx(1)
|
||||
|
||||
kubectx is a utility to manage and switch between kubectl(1) contexts.
|
||||
|
||||
```
|
||||
USAGE:
|
||||
kubectx : list the contexts
|
||||
kubectx <NAME> : switch to context <NAME>
|
||||
kubectx - : switch to the previous context
|
||||
kubectx -c, --current : show the current context name
|
||||
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
||||
kubectx <NEW_NAME>=. : rename current-context to <NEW_NAME>
|
||||
kubectx -d <NAME> : delete context <NAME> ('.' for current-context)
|
||||
(this command won't delete the user/cluster entry
|
||||
that is used by the context)
|
||||
kubectx -u, --unset : unset the current context
|
||||
```
|
||||
|
||||
### Usage
|
||||
### Examples
|
||||
|
||||
```sh
|
||||
# switch to another cluster that's in kubeconfig
|
||||
$ kubectx minikube
|
||||
Switched to context "minikube".
|
||||
|
||||
# switch back to previous cluster
|
||||
$ kubectx -
|
||||
Switched to context "oregon".
|
||||
|
||||
$ kubectx -
|
||||
Switched to context "minikube".
|
||||
# start an "isolated shell" that only has a single context
|
||||
$ kubectx -s minikube
|
||||
|
||||
# rename context
|
||||
$ kubectx dublin=gke_ahmetb_europe-west1-b_dublin
|
||||
Context "dublin" set.
|
||||
Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin".
|
||||
```
|
||||
Context "gke_ahmetb_europe-west1-b_dublin" renamed to "dublin".
|
||||
|
||||
`kubectx` supports <kbd>Tab</kbd> completion on bash/zsh/fish shells to help with
|
||||
long context names. You don't have to remember full context names anymore.
|
||||
|
||||
-----
|
||||
|
||||
# kubens(1)
|
||||
|
||||
kubens is a utility to switch between Kubernetes namespaces.
|
||||
|
||||
```
|
||||
USAGE:
|
||||
kubens : list the namespaces
|
||||
kubens <NAME> : change the active namespace
|
||||
kubens - : switch to the previous namespace
|
||||
kubens -c, --current : show the current namespace
|
||||
```
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
# change the active namespace on kubectl
|
||||
$ kubens kube-system
|
||||
Context "test" set.
|
||||
Active namespace is "kube-system".
|
||||
|
||||
# go back to the previous namespace
|
||||
$ kubens -
|
||||
Context "test" set.
|
||||
Active namespace is "default".
|
||||
|
||||
# change the active namespace even if it doesn't exist
|
||||
$ kubens not-found-namespace --force
|
||||
Context "test" set.
|
||||
Active namespace is "not-found-namespace".
|
||||
---
|
||||
$ kubens not-found-namespace -f
|
||||
Context "test" set.
|
||||
Active namespace is "not-found-namespace".
|
||||
```
|
||||
|
||||
`kubens` also supports <kbd>Tab</kbd> completion on bash/zsh/fish shells.
|
||||
If you have [`fzf`](https://github.com/junegunn/fzf) installed, you can also
|
||||
**interactively** select a context or cluster, or fuzzy-search by typing a few
|
||||
characters. To learn more, read [interactive mode →](#interactive-mode)
|
||||
|
||||
Both `kubectx` and `kubens` support <kbd>Tab</kbd> completion on bash/zsh/fish
|
||||
shells to help with long context names. You don't have to remember full context
|
||||
names anymore.
|
||||
|
||||
-----
|
||||
|
||||
## Installation
|
||||
|
||||
> **🥳📰 NEWS:** With v0.9.0 `kubectx` and `kubens` **are now rewritten in Go**.
|
||||
> (Don't worry, our lovely **bash** versions are still available!) Please test
|
||||
> this new Go binaries by downloading them from
|
||||
> [**Releases →**](https://github.com/ahmetb/kubectx/releases)
|
||||
Stable versions of `kubectx` and `kubens` are small bash scripts that you
|
||||
can find in this repository.
|
||||
|
||||
There are several installation options:
|
||||
Starting with v0.9.0, `kubectx` and `kubens` **are now rewritten in Go**. They
|
||||
should work the same way (and we'll keep the bash-based implementations around)
|
||||
but the new features will be added to the new Go programs. Please help us test
|
||||
this new Go implementation by downloading the binaries from the [**Releases page
|
||||
→**](https://github.com/ahmetb/kubectx/releases)
|
||||
|
||||
- As kubectl plugins (macOS/Linux)
|
||||
- macOS
|
||||
- Homebrew (recommended)
|
||||
- MacPorts
|
||||
- Linux
|
||||
- Manual installation/upgrades
|
||||
- Arch Linux
|
||||
- Debian
|
||||
**Installation options:**
|
||||
|
||||
- [as kubectl plugins (macOS & Linux)](#kubectl-plugins-macos-and-linux)
|
||||
- [with Homebrew (macOS & Linux)](#homebrew-macos-and-linux)
|
||||
- [with MacPorts (macOS)](#macports-macos)
|
||||
- [with apt (Debian)](#apt-debian)
|
||||
- [with pacman (Arch Linux)](#pacman-arch-linux)
|
||||
- [with Chocolatey (Windows)](#windows-installation-using-chocolatey)
|
||||
- [Windows Installation (using Scoop)](#windows-installation-using-scoop)
|
||||
- [with winget (Windows)](#windows-installation-using-winget)
|
||||
- [manually (macOS & Linux)](#manual-installation-macos-and-linux)
|
||||
|
||||
If you like to add context/namespace information to your shell prompt (`$PS1`),
|
||||
you can try out [kube-ps1].
|
||||
|
||||
[kube-ps1]: https://github.com/jonmosco/kube-ps1
|
||||
|
||||
### Kubectl Plugins (macOS and Linux)
|
||||
|
||||
You can install and use [Krew](https://github.com/kubernetes-sigs/krew/) kubectl
|
||||
plugin manager to get `kubectx` and `kubens`. **NOTE:** This will not install
|
||||
shell completion scripts, if you want those, choose another installation method
|
||||
below.
|
||||
You can install and use the [Krew](https://github.com/kubernetes-sigs/krew/) kubectl
|
||||
plugin manager to get `kubectx` and `kubens`.
|
||||
|
||||
**Note:** This will not install the shell completion scripts. If you want them,
|
||||
*choose another installation method
|
||||
or install the scripts [manually](#manual-installation-macos-and-linux).
|
||||
|
||||
```sh
|
||||
kubectl krew install ctx
|
||||
@@ -120,28 +114,72 @@ kubectl krew install ns
|
||||
|
||||
After installing, the tools will be available as `kubectl ctx` and `kubectl ns`.
|
||||
|
||||
### macOS
|
||||
### Homebrew (macOS and Linux)
|
||||
|
||||
#### Homebrew
|
||||
If you use [Homebrew](https://brew.sh/) you can install like this:
|
||||
|
||||
:confetti_ball: If you use [Homebrew](https://brew.sh/) you can install like this:
|
||||
```sh
|
||||
brew install kubectx
|
||||
```
|
||||
|
||||
brew install kubectx
|
||||
This command will set up bash/zsh/fish completion scripts automatically. Make sure you [configure your shell](https://docs.brew.sh/Shell-Completion) to load completions for installed Homebrew formulas.
|
||||
|
||||
This command will set up bash/zsh/fish completion scripts automatically.
|
||||
|
||||
- If you like to add context/namespace info to your shell prompt (`$PS1`),
|
||||
I recommend trying out [kube-ps1](https://github.com/jonmosco/kube-ps1).
|
||||
|
||||
#### MacPorts
|
||||
### MacPorts (macOS)
|
||||
|
||||
If you use [MacPorts](https://www.macports.org) you can install like this:
|
||||
|
||||
sudo port install kubectx
|
||||
```sh
|
||||
sudo port install kubectx
|
||||
```
|
||||
|
||||
### Linux
|
||||
### apt (Debian)
|
||||
|
||||
Since `kubectx`/`kubens` are written in Bash, you should be able to install
|
||||
``` bash
|
||||
sudo apt install kubectx
|
||||
```
|
||||
Newer versions might be available on repos like
|
||||
[Debian Buster (testing)](https://packages.debian.org/buster/kubectx),
|
||||
[Sid (unstable)](https://packages.debian.org/sid/kubectx)
|
||||
(_if you are unfamiliar with the Debian release process and how to enable
|
||||
testing/unstable repos, check out the
|
||||
[Debian Wiki](https://wiki.debian.org/DebianReleases)_):
|
||||
|
||||
|
||||
### pacman (Arch Linux)
|
||||
|
||||
Available as official Arch Linux package. Install it via:
|
||||
|
||||
```bash
|
||||
sudo pacman -S kubectx
|
||||
```
|
||||
|
||||
### Windows Installation (using Chocolatey)
|
||||
|
||||
Available as packages on [Chocolatey](https://chocolatey.org/why-chocolatey)
|
||||
```pwsh
|
||||
choco install kubens kubectx
|
||||
```
|
||||
|
||||
### Windows Installation (using Scoop)
|
||||
|
||||
Available as packages on [Scoop](https://scoop.sh/)
|
||||
```pwsh
|
||||
scoop bucket add main
|
||||
scoop install main/kubens main/kubectx
|
||||
```
|
||||
|
||||
### Windows Installation (using winget)
|
||||
|
||||
Available as packages on [winget](https://learn.microsoft.com/en-us/windows/package-manager/)
|
||||
```pwsh
|
||||
winget install --id ahmetb.kubectx
|
||||
winget install --id ahmetb.kubens
|
||||
```
|
||||
|
||||
### Manual Installation (macOS and Linux)
|
||||
|
||||
Since `kubectx` and `kubens` are written in Bash, you should be able to install
|
||||
them to any POSIX environment that has Bash installed.
|
||||
|
||||
- Download the `kubectx`, and `kubens` scripts.
|
||||
@@ -150,38 +188,6 @@ them to any POSIX environment that has Bash installed.
|
||||
- or save them to a directory, then create symlinks to `kubectx`/`kubens` from
|
||||
somewhere in your `PATH`, like `/usr/local/bin`
|
||||
- Make `kubectx` and `kubens` executable (`chmod +x ...`)
|
||||
- Install bash/zsh/fish [completion scripts](completion/).
|
||||
- For zsh:
|
||||
The completion scripts have to be in a path that belongs to `$fpath`. Either link or copy them to an existing folder.
|
||||
If using oh-my-zsh you can do as follows:
|
||||
```bash
|
||||
mkdir -p ~/.oh-my-zsh/completions
|
||||
chmod -R 755 ~/.oh-my-zsh/completions
|
||||
ln -s /opt/kubectx/completion/kubectx.zsh ~/.oh-my-zsh/completions/_kubectx.zsh
|
||||
ln -s /opt/kubectx/completion/kubens.zsh ~/.oh-my-zsh/completions/_kubens.zsh
|
||||
```
|
||||
Note that the leading underscore seems to be a convention. If completion doesn't work, add `autoload -U compinit && compinit` to your `.zshrc` (similar to [`zsh-completions`](https://github.com/zsh-users/zsh-completions/blob/master/README.md#oh-my-zsh)).
|
||||
If not using oh-my-zsh, you could link to `/usr/share/zsh/functions/Completion` (might require sudo), depending on the `$fpath` of your zsh installation.
|
||||
In case of error, calling `compaudit` might help.
|
||||
- For bash:
|
||||
```bash
|
||||
git clone https://github.com/ahmetb/kubectx.git ~/.kubectx
|
||||
COMPDIR=$(pkg-config --variable=completionsdir bash-completion)
|
||||
ln -sf ~/.kubectx/completion/kubens.bash $COMPDIR/kubens
|
||||
ln -sf ~/.kubectx/completion/kubectx.bash $COMPDIR/kubectx
|
||||
cat << FOE >> ~/.bashrc
|
||||
|
||||
|
||||
#kubectx and kubens
|
||||
export PATH=~/.kubectx:\$PATH
|
||||
FOE
|
||||
```
|
||||
- For fish:
|
||||
```fish
|
||||
mkdir -p ~/.config/fish/completions
|
||||
ln -s /opt/kubectx/completion/kubectx.fish ~/.config/fish/completions/
|
||||
ln -s /opt/kubectx/completion/kubens.fish ~/.config/fish/completions/
|
||||
```
|
||||
|
||||
Example installation steps:
|
||||
|
||||
@@ -191,20 +197,74 @@ sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
|
||||
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens
|
||||
```
|
||||
|
||||
#### Arch Linux
|
||||
If you also want to have shell completions, pick an installation method for the
|
||||
[completion scripts](completion/) that fits your system best: [`zsh` with
|
||||
`antibody`](#completion-scripts-for-zsh-with-antibody), [plain
|
||||
`zsh`](#completion-scripts-for-plain-zsh),
|
||||
[`bash`](#completion-scripts-for-bash) or
|
||||
[`fish`](#completion-scripts-for-fish).
|
||||
|
||||
Available as official Arch Linux package. Install it via:
|
||||
#### Completion scripts for `zsh` with [antibody](https://getantibody.github.io)
|
||||
|
||||
```bash
|
||||
sudo pacman -S kubectx
|
||||
Add this line to your [Plugins File](https://getantibody.github.io/usage/) (e.g.
|
||||
`~/.zsh_plugins.txt`):
|
||||
|
||||
```
|
||||
ahmetb/kubectx path:completion kind:fpath
|
||||
```
|
||||
|
||||
#### Debian
|
||||
Depending on your setup, you might or might not need to call `compinit` or
|
||||
`autoload -U compinit && compinit` in your `~/.zshrc` after you load the Plugins
|
||||
file. If you use [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh), load the
|
||||
completions before you load `oh-my-zsh` because `oh-my-zsh` will call
|
||||
`compinit`.
|
||||
|
||||
Available as a Debian package for [Debian Buster (testing)](https://packages.debian.org/buster/kubectx), [Sid (unstable)](https://packages.debian.org/sid/kubectx) (_note: if you are unfamiliar with Debian release process and how to enable testing/unstable repos, check the [Debian Wiki](https://wiki.debian.org/DebianReleases)_):
|
||||
#### Completion scripts for plain `zsh`
|
||||
|
||||
``` bash
|
||||
sudo apt install kubectx
|
||||
The completion scripts have to be in a path that belongs to `$fpath`. Either
|
||||
link or copy them to an existing folder.
|
||||
|
||||
Example with [`oh-my-zsh`](https://github.com/ohmyzsh/ohmyzsh):
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.oh-my-zsh/custom/completions
|
||||
chmod -R 755 ~/.oh-my-zsh/custom/completions
|
||||
ln -s /opt/kubectx/completion/_kubectx.zsh ~/.oh-my-zsh/custom/completions/_kubectx.zsh
|
||||
ln -s /opt/kubectx/completion/_kubens.zsh ~/.oh-my-zsh/custom/completions/_kubens.zsh
|
||||
echo "fpath=($ZSH/custom/completions $fpath)" >> ~/.zshrc
|
||||
```
|
||||
|
||||
If completion doesn't work, add `autoload -U compinit && compinit` to your
|
||||
`.zshrc` (similar to
|
||||
[`zsh-completions`](https://github.com/zsh-users/zsh-completions/blob/master/README.md#oh-my-zsh)).
|
||||
|
||||
If you are not using [`oh-my-zsh`](https://github.com/ohmyzsh/ohmyzsh), you
|
||||
could link to `/usr/share/zsh/functions/Completion` (might require sudo),
|
||||
depending on the `$fpath` of your zsh installation.
|
||||
|
||||
In case of errors, calling `compaudit` might help.
|
||||
|
||||
#### Completion scripts for `bash`
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ahmetb/kubectx.git ~/.kubectx
|
||||
COMPDIR=$(pkg-config --variable=completionsdir bash-completion)
|
||||
ln -sf ~/.kubectx/completion/kubens.bash $COMPDIR/kubens
|
||||
ln -sf ~/.kubectx/completion/kubectx.bash $COMPDIR/kubectx
|
||||
cat << EOF >> ~/.bashrc
|
||||
|
||||
|
||||
#kubectx and kubens
|
||||
export PATH=~/.kubectx:\$PATH
|
||||
EOF
|
||||
```
|
||||
|
||||
#### Completion scripts for `fish`
|
||||
|
||||
```fish
|
||||
mkdir -p ~/.config/fish/completions
|
||||
ln -s /opt/kubectx/completion/kubectx.fish ~/.config/fish/completions/
|
||||
ln -s /opt/kubectx/completion/kubens.fish ~/.config/fish/completions/
|
||||
```
|
||||
|
||||
-----
|
||||
@@ -213,55 +273,42 @@ sudo apt install kubectx
|
||||
|
||||
If you want `kubectx` and `kubens` commands to present you an interactive menu
|
||||
with fuzzy searching, you just need to [install
|
||||
`fzf`](https://github.com/junegunn/fzf) in your PATH.
|
||||
`fzf`](https://github.com/junegunn/fzf) in your `$PATH`.
|
||||
|
||||

|
||||
|
||||
If you have `fzf` installed, but want to opt out of using this feature, set the environment variable `KUBECTX_IGNORE_FZF=1`.
|
||||
|
||||
If you want to keep `fzf` interactive mode but need the default behavior of the command, you can do it using Unix composability:
|
||||
```
|
||||
kubectx | cat
|
||||
```
|
||||
If you have `fzf` installed, but want to opt out of using this feature, set the
|
||||
environment variable `KUBECTX_IGNORE_FZF=1`.
|
||||
|
||||
If you want to keep `fzf` interactive mode but need the default behavior of the
|
||||
command, you can do it by piping the output to another command (e.g. `kubectx |
|
||||
cat `).
|
||||
|
||||
-----
|
||||
|
||||
### Customizing colors
|
||||
|
||||
If you like to customize the colors indicating the current namespace or context, set the environment variables `KUBECTX_CURRENT_FGCOLOR` and `KUBECTX_CURRENT_BGCOLOR` (refer color codes [here](https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/)):
|
||||
If you like to customize the colors indicating the current namespace or context,
|
||||
set the environment variables `KUBECTX_CURRENT_FGCOLOR` and
|
||||
`KUBECTX_CURRENT_BGCOLOR` (refer color codes
|
||||
[here](https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/)):
|
||||
|
||||
```
|
||||
```sh
|
||||
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6) # blue text
|
||||
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7) # white background
|
||||
```
|
||||
|
||||
Colors in the output can be disabled by setting the
|
||||
[`NO_COLOR`](http://no-color.org/) environment variable.
|
||||
[`NO_COLOR`](https://no-color.org/) environment variable.
|
||||
|
||||
-----
|
||||
|
||||
#### Users
|
||||
|
||||
| What are others saying about kubectx? |
|
||||
| ---- |
|
||||
| _“Thank you for kubectx & kubens - I use them all the time & have them in my k8s toolset to maintain happiness :) ”_ – [@pbouwer](https://twitter.com/pbouwer/status/925896377929949184) |
|
||||
| _“I can't imagine working without kubectx and especially kubens anymore. It's pure gold.”_ – [@timoreimann](https://twitter.com/timoreimann/status/925801946757419008) |
|
||||
| _“I'm liking kubectx from @ahmetb, makes it super-easy to switch #Kubernetes contexts [...]”_ — [@lizrice](https://twitter.com/lizrice/status/928556415517589505) |
|
||||
| _“Also using it on a daily basis. This and my zsh config that shows me the current k8s context 😉”_ – [@puja108](https://twitter.com/puja108/status/928742521139810305) |
|
||||
| _“Lately I've found myself using the kubens command more than kubectx. Both very useful though :-)”_ – [@stuartleeks](https://twitter.com/stuartleeks/status/928562850464907264) |
|
||||
| _“yeah kubens rocks!”_ – [@embano1](https://twitter.com/embano1/status/928698440732815360) |
|
||||
| _“Special thanks to Ahmet Alp Balkan for creating kubectx, kubens, and kubectl aliases, as these tools made my life better.”_ – [@strebeld](https://medium.com/@strebeld/5-ways-to-enhance-kubectl-ux-97c8893227a) |
|
||||
| _“❤️ this shell script @ahmetb wrote to help make switching between kubectl config contexts a breeze.”_ – [@briandanowski](https://twitter.com/briandanowski/status/1085409568165896193) |
|
||||
|
||||
> If you liked `kubectx`, you may like my [`kubectl-aliases`](https://github.com/ahmetb/kubectl-aliases) project, too.
|
||||
|
||||
-----
|
||||
|
||||
Disclaimer: This is not an official Google product.
|
||||
|
||||
If you liked `kubectx`, you may like my
|
||||
[`kubectl-aliases`](https://github.com/ahmetb/kubectl-aliases) project, too. I
|
||||
recommend pairing kubectx and kubens with [fzf](#interactive-mode) and
|
||||
[kube-ps1].
|
||||
|
||||
#### Stargazers over time
|
||||
|
||||
[](https://starcharts.herokuapp.com/ahmetb/kubectx)
|
||||

|
||||
[](https://starchart.cc/ahmetb/kubectx)
|
||||
 <!-- TODO broken since Aug 2021 as igrigorik left Google -->
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,6 +27,9 @@ import (
|
||||
type CurrentOp struct{}
|
||||
|
||||
func (_op CurrentOp) Run(stdout, _ io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -16,11 +30,14 @@ type DeleteOp struct {
|
||||
|
||||
// deleteContexts deletes context entries one by one.
|
||||
func (op DeleteOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, ctx := range op.Contexts {
|
||||
// TODO inefficency here. we open/write/close the same file many times.
|
||||
// TODO inefficiency here. we open/write/close the same file many times.
|
||||
deletedName, wasActiveContext, err := deleteContext(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error deleting context %q", deletedName)
|
||||
return errors.Wrapf(err, "error deleting context \"%s\"", deletedName)
|
||||
}
|
||||
if wasActiveContext {
|
||||
printer.Warning(stderr, "You deleted the current context. Use \"%s\" to select a new context.",
|
||||
|
||||
@@ -1 +1,15 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -26,9 +40,20 @@ func parseArgs(argv []string) Op {
|
||||
return ListOp{}
|
||||
}
|
||||
|
||||
if argv[0] == "--shell" || argv[0] == "-s" {
|
||||
if len(argv) != 2 {
|
||||
return UnsupportedOp{Err: fmt.Errorf("'%s' requires exactly one context name argument", argv[0])}
|
||||
}
|
||||
return ShellOp{Target: argv[1]}
|
||||
}
|
||||
|
||||
if argv[0] == "-d" {
|
||||
if len(argv) == 1 {
|
||||
return UnsupportedOp{Err: fmt.Errorf("'-d' needs arguments")}
|
||||
if cmdutil.IsInteractiveMode(os.Stdout) {
|
||||
return InteractiveDeleteOp{SelfCmd: os.Args[0]}
|
||||
} else {
|
||||
return UnsupportedOp{Err: fmt.Errorf("'-d' needs arguments")}
|
||||
}
|
||||
}
|
||||
return DeleteOp{Contexts: argv[1:]}
|
||||
}
|
||||
@@ -38,6 +63,9 @@ func parseArgs(argv []string) Op {
|
||||
if v == "--help" || v == "-h" {
|
||||
return HelpOp{}
|
||||
}
|
||||
if v == "--version" || v == "-V" {
|
||||
return VersionOp{}
|
||||
}
|
||||
if v == "--current" || v == "-c" {
|
||||
return CurrentOp{}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -58,6 +72,18 @@ func Test_parseArgs_new(t *testing.T) {
|
||||
{name: "rename context with old=current",
|
||||
args: []string{"a=."},
|
||||
want: RenameOp{"a", "."}},
|
||||
{name: "shell shorthand",
|
||||
args: []string{"-s", "prod"},
|
||||
want: ShellOp{Target: "prod"}},
|
||||
{name: "shell long form",
|
||||
args: []string{"--shell", "prod"},
|
||||
want: ShellOp{Target: "prod"}},
|
||||
{name: "shell without context name",
|
||||
args: []string{"-s"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("'-s' requires exactly one context name argument")}},
|
||||
{name: "shell with too many args",
|
||||
args: []string{"--shell", "a", "b"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("'--shell' requires exactly one context name argument")}},
|
||||
{name: "unrecognized flag",
|
||||
args: []string{"-x"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported option '-x'")}},
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -20,7 +34,14 @@ type InteractiveSwitchOp struct {
|
||||
SelfCmd string
|
||||
}
|
||||
|
||||
type InteractiveDeleteOp struct {
|
||||
SelfCmd string
|
||||
}
|
||||
|
||||
func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
// parse kubeconfig just to see if it can be loaded
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
if err := kc.Parse(); err != nil {
|
||||
@@ -54,6 +75,60 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch context")
|
||||
}
|
||||
printer.Success(stderr, "Switched to context %s.", printer.SuccessColor.Sprint(name))
|
||||
printer.Success(stderr, "Switched to context \"%s\".", printer.SuccessColor.Sprint(name))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (op InteractiveDeleteOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
// parse kubeconfig just to see if it can be loaded
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
if err := kc.Parse(); err != nil {
|
||||
if cmdutil.IsNotFoundErr(err) {
|
||||
printer.Warning(stderr, "kubeconfig file not found")
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
kc.Close()
|
||||
|
||||
if len(kc.ContextNames()) == 0 {
|
||||
return errors.New("no contexts found in config")
|
||||
}
|
||||
|
||||
cmd := exec.Command("fzf", "--ansi", "--no-preview")
|
||||
var out bytes.Buffer
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = stderr
|
||||
cmd.Stdout = &out
|
||||
|
||||
cmd.Env = append(os.Environ(),
|
||||
fmt.Sprintf("FZF_DEFAULT_COMMAND=%s", op.SelfCmd),
|
||||
fmt.Sprintf("%s=1", env.EnvForceColor))
|
||||
if err := cmd.Run(); err != nil {
|
||||
if _, ok := err.(*exec.ExitError); !ok {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
choice := strings.TrimSpace(out.String())
|
||||
if choice == "" {
|
||||
return errors.New("you did not choose any of the options")
|
||||
}
|
||||
|
||||
name, wasActiveContext, err := deleteContext(choice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete context")
|
||||
}
|
||||
|
||||
if wasActiveContext {
|
||||
printer.Warning(stderr, "You deleted the current context. Use \"%s\" to select a new context.",
|
||||
selfName())
|
||||
}
|
||||
|
||||
printer.Success(stderr, `Deleted context %s.`, printer.SuccessColor.Sprint(name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -25,11 +39,13 @@ func printUsage(out io.Writer) error {
|
||||
%PROG% -c, --current : show the current context name
|
||||
%PROG% <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
||||
%PROG% <NEW_NAME>=. : rename current-context to <NEW_NAME>
|
||||
%PROG% -u, --unset : unset the current context
|
||||
%PROG% -u, --unset : unset the current context
|
||||
%PROG% -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
|
||||
%SPAC% (this command won't delete the user/cluster entry
|
||||
%SPAC% referenced by the context entry)
|
||||
%PROG% -h,--help : show this message`
|
||||
%PROG% -s, --shell <NAME> : start a shell scoped to context <NAME>
|
||||
%PROG% -h,--help : show this message
|
||||
%PROG% -V,--version : show version`
|
||||
help = strings.ReplaceAll(help, "%PROG%", selfName())
|
||||
help = strings.ReplaceAll(help, "%SPAC%", strings.Repeat(" ", len(selfName())))
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,10 +28,10 @@ func TestPrintHelp(t *testing.T) {
|
||||
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "USAGE:") {
|
||||
t.Errorf("help string doesn't contain USAGE: ; output=%q", out)
|
||||
t.Errorf("help string doesn't contain USAGE: ; output=\"%s\"", out)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(out, "\n") {
|
||||
t.Errorf("does not end with New line; output=%q", out)
|
||||
t.Errorf("does not end with New line; output=\"%s\"", out)
|
||||
}
|
||||
}
|
||||
|
||||
24
cmd/kubectx/isolated_shell_guard.go
Normal file
24
cmd/kubectx/isolated_shell_guard.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/env"
|
||||
"github.com/ahmetb/kubectx/internal/kubeconfig"
|
||||
)
|
||||
|
||||
func checkIsolatedMode() error {
|
||||
if os.Getenv(env.EnvIsolatedShell) != "1" {
|
||||
return nil
|
||||
}
|
||||
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
return fmt.Errorf("you are in a locked single-context shell, use 'exit' to leave")
|
||||
}
|
||||
|
||||
cur := kc.GetCurrentContext()
|
||||
return fmt.Errorf("you are in a locked single-context shell (\"%s\"), use 'exit' to leave", cur)
|
||||
}
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -16,6 +30,9 @@ import (
|
||||
type ListOp struct{}
|
||||
|
||||
func (_ ListOp) Run(stdout, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -34,6 +48,9 @@ func parseRenameSyntax(v string) (string, string, bool) {
|
||||
// to the "new" value. If the old refers to the current-context,
|
||||
// current-context preference is also updated.
|
||||
func (op RenameOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
@@ -46,11 +63,11 @@ func (op RenameOp) Run(_, stderr io.Writer) error {
|
||||
}
|
||||
|
||||
if !kc.ContextExists(op.Old) {
|
||||
return errors.Errorf("context %q not found, can't rename it", op.Old)
|
||||
return errors.Errorf("context \"%s\" not found, can't rename it", op.Old)
|
||||
}
|
||||
|
||||
if kc.ContextExists(op.New) {
|
||||
printer.Warning(stderr, "context %q exists, overwriting it.", op.New)
|
||||
printer.Warning(stderr, "context \"%s\" exists, overwriting it.", op.New)
|
||||
if err := kc.DeleteContextEntry(op.New); err != nil {
|
||||
return errors.Wrap(err, "failed to delete new context to overwrite it")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
135
cmd/kubectx/shell.go
Normal file
135
cmd/kubectx/shell.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/env"
|
||||
"github.com/ahmetb/kubectx/internal/kubeconfig"
|
||||
"github.com/ahmetb/kubectx/internal/printer"
|
||||
)
|
||||
|
||||
// ShellOp indicates intention to start a scoped sub-shell for a context.
|
||||
type ShellOp struct {
|
||||
Target string
|
||||
}
|
||||
|
||||
func (op ShellOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kubectlPath, err := resolveKubectl()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Verify context exists and get current context for exit message
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
if !kc.ContextExists(op.Target) {
|
||||
return fmt.Errorf("no context exists with the name: \"%s\"", op.Target)
|
||||
}
|
||||
previousCtx := kc.GetCurrentContext()
|
||||
|
||||
// Extract minimal kubeconfig using kubectl
|
||||
data, err := extractMinimalKubeconfig(kubectlPath, op.Target)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to extract kubeconfig for context")
|
||||
}
|
||||
|
||||
// Write to temp file
|
||||
tmpFile, err := os.CreateTemp("", "kubectx-shell-*.yaml")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp kubeconfig file")
|
||||
}
|
||||
tmpPath := tmpFile.Name()
|
||||
defer os.Remove(tmpPath)
|
||||
|
||||
if _, err := tmpFile.Write(data); err != nil {
|
||||
tmpFile.Close()
|
||||
return errors.Wrap(err, "failed to write temp kubeconfig")
|
||||
}
|
||||
tmpFile.Close()
|
||||
|
||||
// Print entry message
|
||||
badgeColor := color.New(color.BgRed, color.FgWhite, color.Bold)
|
||||
printer.EnableOrDisableColor(badgeColor)
|
||||
fmt.Fprintf(stderr, "%s kubectl context is %s in this shell — type 'exit' to leave.\n",
|
||||
badgeColor.Sprint("[ISOLATED SHELL]"), printer.WarningColor.Sprint(op.Target))
|
||||
|
||||
// Detect and start shell
|
||||
shellBin := detectShell()
|
||||
cmd := exec.Command(shellBin)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Env = append(os.Environ(),
|
||||
"KUBECONFIG="+tmpPath,
|
||||
env.EnvIsolatedShell+"=1",
|
||||
)
|
||||
|
||||
_ = cmd.Run()
|
||||
|
||||
// Print exit message
|
||||
fmt.Fprintf(stderr, "%s kubectl context is now %s.\n",
|
||||
badgeColor.Sprint("[ISOLATED SHELL EXITED]"), printer.WarningColor.Sprint(previousCtx))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveKubectl() (string, error) {
|
||||
if v := os.Getenv("KUBECTL"); v != "" {
|
||||
return v, nil
|
||||
}
|
||||
path, err := exec.LookPath("kubectl")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("kubectl is required for --shell but was not found in PATH")
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func extractMinimalKubeconfig(kubectlPath, contextName string) ([]byte, error) {
|
||||
cmd := exec.Command(kubectlPath, "config", "view", "--minify", "--flatten",
|
||||
"--context", contextName)
|
||||
cmd.Env = os.Environ()
|
||||
data, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubectl config view failed: %w", err)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func detectShell() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
// cmd.exe always sets the PROMPT env var, so if it is present
|
||||
// we can reliably assume we are running inside cmd.exe.
|
||||
if os.Getenv("PROMPT") != "" {
|
||||
return "cmd.exe"
|
||||
}
|
||||
// Otherwise assume PowerShell. PSModulePath is always set on
|
||||
// Windows regardless of the shell, so it cannot be used as a
|
||||
// discriminator; however the absence of PROMPT is a strong
|
||||
// enough signal that we are in a PowerShell session.
|
||||
if pwsh, err := exec.LookPath("pwsh"); err == nil {
|
||||
return pwsh
|
||||
}
|
||||
if powershell, err := exec.LookPath("powershell"); err == nil {
|
||||
return powershell
|
||||
}
|
||||
return "cmd.exe"
|
||||
}
|
||||
if v := os.Getenv("SHELL"); v != "" {
|
||||
return v
|
||||
}
|
||||
return "/bin/sh"
|
||||
}
|
||||
131
cmd/kubectx/shell_test.go
Normal file
131
cmd/kubectx/shell_test.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/env"
|
||||
)
|
||||
|
||||
func Test_detectShell_unix(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("skipping unix shell detection test on windows")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
shellEnv string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "SHELL env set",
|
||||
shellEnv: "/bin/zsh",
|
||||
want: "/bin/zsh",
|
||||
},
|
||||
{
|
||||
name: "SHELL env empty, falls back to /bin/sh",
|
||||
shellEnv: "",
|
||||
want: "/bin/sh",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
orig := os.Getenv("SHELL")
|
||||
defer os.Setenv("SHELL", orig)
|
||||
|
||||
os.Setenv("SHELL", tt.shellEnv)
|
||||
if tt.shellEnv == "" {
|
||||
os.Unsetenv("SHELL")
|
||||
}
|
||||
|
||||
got := detectShell()
|
||||
if got != tt.want {
|
||||
t.Errorf("detectShell() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ShellOp_blockedWhenNested(t *testing.T) {
|
||||
// Simulate being inside an isolated shell
|
||||
orig := os.Getenv(env.EnvIsolatedShell)
|
||||
defer os.Setenv(env.EnvIsolatedShell, orig)
|
||||
os.Setenv(env.EnvIsolatedShell, "1")
|
||||
|
||||
op := ShellOp{Target: "some-context"}
|
||||
var stdout, stderr bytes.Buffer
|
||||
err := op.Run(&stdout, &stderr)
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("expected error when running ShellOp inside isolated shell, got nil")
|
||||
}
|
||||
|
||||
want := "locked single-context shell to"
|
||||
if !bytes.Contains([]byte(err.Error()), []byte(want)) {
|
||||
// The error may not contain the context name if kubeconfig is not available,
|
||||
// but it should still be blocked
|
||||
want2 := "locked single-context shell"
|
||||
if !bytes.Contains([]byte(err.Error()), []byte(want2)) {
|
||||
t.Errorf("error message %q does not contain %q", err.Error(), want2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_resolveKubectl_envVar(t *testing.T) {
|
||||
orig := os.Getenv("KUBECTL")
|
||||
defer os.Setenv("KUBECTL", orig)
|
||||
|
||||
os.Setenv("KUBECTL", "/custom/path/kubectl")
|
||||
got, err := resolveKubectl()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got != "/custom/path/kubectl" {
|
||||
t.Errorf("resolveKubectl() = %q, want %q", got, "/custom/path/kubectl")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_resolveKubectl_inPath(t *testing.T) {
|
||||
orig := os.Getenv("KUBECTL")
|
||||
defer os.Setenv("KUBECTL", orig)
|
||||
os.Unsetenv("KUBECTL")
|
||||
|
||||
// kubectl should be findable in PATH on most dev machines
|
||||
got, err := resolveKubectl()
|
||||
if err != nil {
|
||||
t.Skip("kubectl not in PATH, skipping")
|
||||
}
|
||||
if got == "" {
|
||||
t.Error("resolveKubectl() returned empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkIsolatedMode_notSet(t *testing.T) {
|
||||
orig := os.Getenv(env.EnvIsolatedShell)
|
||||
defer os.Setenv(env.EnvIsolatedShell, orig)
|
||||
os.Unsetenv(env.EnvIsolatedShell)
|
||||
|
||||
err := checkIsolatedMode()
|
||||
if err != nil {
|
||||
t.Errorf("expected nil error when not in isolated mode, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkIsolatedMode_set(t *testing.T) {
|
||||
orig := os.Getenv(env.EnvIsolatedShell)
|
||||
defer os.Setenv(env.EnvIsolatedShell, orig)
|
||||
os.Setenv(env.EnvIsolatedShell, "1")
|
||||
|
||||
err := checkIsolatedMode()
|
||||
if err == nil {
|
||||
t.Fatal("expected error when in isolated mode, got nil")
|
||||
}
|
||||
|
||||
want := "locked single-context shell"
|
||||
if !bytes.Contains([]byte(err.Error()), []byte(want)) {
|
||||
t.Errorf("error message %q does not contain %q", err.Error(), want)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,7 +29,7 @@ func Test_readLastContext_nonExistingFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s != "" {
|
||||
t.Fatalf("expected empty string; got=%q", s)
|
||||
t.Fatalf("expected empty string; got=\"%s\"", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +42,7 @@ func Test_readLastContext(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "foo"; s != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, s)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +70,7 @@ func Test_writeLastContext(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "ctx1"; v != expected {
|
||||
t.Fatalf("read wrong value=%q; expected=%q", v, expected)
|
||||
t.Fatalf("read wrong value=\"%s\"; expected=\"%s\"", v, expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +85,7 @@ func Test_kubectxFilePath(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\" got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,6 +29,9 @@ type SwitchOp struct {
|
||||
}
|
||||
|
||||
func (op SwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
var newCtx string
|
||||
var err error
|
||||
if op.Target == "-" {
|
||||
@@ -25,7 +42,7 @@ func (op SwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch context")
|
||||
}
|
||||
err = printer.Success(stderr, "Switched to context %q.", newCtx)
|
||||
err = printer.Success(stderr, "Switched to context \"%s\".", printer.SuccessColor.Sprint(newCtx))
|
||||
return errors.Wrap(err, "print error")
|
||||
}
|
||||
|
||||
@@ -44,7 +61,7 @@ func switchContext(name string) (string, error) {
|
||||
|
||||
prev := kc.GetCurrentContext()
|
||||
if !kc.ContextExists(name) {
|
||||
return "", errors.Errorf("no context exists with the name: %q", name)
|
||||
return "", errors.Errorf("no context exists with the name: \"%s\"", name)
|
||||
}
|
||||
if err := kc.ModifyCurrentContext(name); err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,6 +27,9 @@ import (
|
||||
type UnsetOp struct{}
|
||||
|
||||
func (_ UnsetOp) Run(_, stderr io.Writer) error {
|
||||
if err := checkIsolatedMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
|
||||
20
cmd/kubectx/version.go
Normal file
20
cmd/kubectx/version.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "v0.0.0+unknown" // populated by goreleaser
|
||||
)
|
||||
|
||||
// VersionOp describes printing version string.
|
||||
type VersionOp struct{}
|
||||
|
||||
func (_ VersionOp) Run(stdout, _ io.Writer) error {
|
||||
_, err := fmt.Fprintf(stdout, "%s\n", version)
|
||||
return errors.Wrap(err, "write error")
|
||||
}
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -24,7 +38,7 @@ func (c CurrentOp) Run(stdout, _ io.Writer) error {
|
||||
}
|
||||
ns, err := kc.NamespaceOfContext(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read namespace of %q", ctx)
|
||||
return errors.Wrapf(err, "failed to read namespace of \"%s\"", ctx)
|
||||
}
|
||||
_, err = fmt.Fprintln(stdout, ns)
|
||||
return errors.Wrap(err, "write error")
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/cmdutil"
|
||||
@@ -19,25 +34,51 @@ func (op UnsupportedOp) Run(_, _ io.Writer) error {
|
||||
// parseArgs looks at flags (excl. executable name, i.e. argv[0])
|
||||
// and decides which operation should be taken.
|
||||
func parseArgs(argv []string) Op {
|
||||
if len(argv) == 0 {
|
||||
n := len(argv)
|
||||
|
||||
if n == 0 {
|
||||
if cmdutil.IsInteractiveMode(os.Stdout) {
|
||||
return InteractiveSwitchOp{SelfCmd: os.Args[0]}
|
||||
}
|
||||
return ListOp{}
|
||||
}
|
||||
|
||||
if len(argv) == 1 {
|
||||
if n == 1 {
|
||||
v := argv[0]
|
||||
if v == "--help" || v == "-h" {
|
||||
switch v {
|
||||
case "--help", "-h":
|
||||
return HelpOp{}
|
||||
}
|
||||
if v == "--current" || v == "-c" {
|
||||
case "--version", "-V":
|
||||
return VersionOp{}
|
||||
case "--current", "-c":
|
||||
return CurrentOp{}
|
||||
default:
|
||||
return getSwitchOp(v, false)
|
||||
}
|
||||
if strings.HasPrefix(v, "-") && v != "-" {
|
||||
return UnsupportedOp{Err: fmt.Errorf("unsupported option '%s'", v)}
|
||||
} else if n == 2 {
|
||||
// {namespace} -f|--force
|
||||
name := argv[0]
|
||||
force := slices.Contains([]string{"-f", "--force"}, argv[1])
|
||||
|
||||
if !force {
|
||||
if !slices.Contains([]string{"-f", "--force"}, argv[0]) {
|
||||
return UnsupportedOp{Err: fmt.Errorf("unsupported arguments %q", argv)}
|
||||
}
|
||||
|
||||
// -f|--force {namespace}
|
||||
force = true
|
||||
name = argv[1]
|
||||
}
|
||||
return SwitchOp{Target: argv[0]}
|
||||
|
||||
return getSwitchOp(name, force)
|
||||
}
|
||||
|
||||
return UnsupportedOp{Err: fmt.Errorf("too many arguments")}
|
||||
}
|
||||
|
||||
func getSwitchOp(v string, force bool) Op {
|
||||
if strings.HasPrefix(v, "-") && v != "-" {
|
||||
return UnsupportedOp{Err: fmt.Errorf("unsupported option %q", v)}
|
||||
}
|
||||
return SwitchOp{Target: v, Force: force}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -34,12 +48,30 @@ func Test_parseArgs_new(t *testing.T) {
|
||||
{name: "switch by name",
|
||||
args: []string{"foo"},
|
||||
want: SwitchOp{Target: "foo"}},
|
||||
{name: "switch by name force short flag",
|
||||
args: []string{"foo", "-f"},
|
||||
want: SwitchOp{Target: "foo", Force: true}},
|
||||
{name: "switch by name force long flag",
|
||||
args: []string{"foo", "--force"},
|
||||
want: SwitchOp{Target: "foo", Force: true}},
|
||||
{name: "switch by name force short flag before name",
|
||||
args: []string{"-f", "foo"},
|
||||
want: SwitchOp{Target: "foo", Force: true}},
|
||||
{name: "switch by name force long flag before name",
|
||||
args: []string{"--force", "foo"},
|
||||
want: SwitchOp{Target: "foo", Force: true}},
|
||||
{name: "switch by name unknown arguments",
|
||||
args: []string{"foo", "-x"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported arguments %q", []string{"foo", "-x"})}},
|
||||
{name: "switch by name unknown arguments",
|
||||
args: []string{"-x", "foo"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported arguments %q", []string{"-x", "foo"})}},
|
||||
{name: "switch by swap",
|
||||
args: []string{"-"},
|
||||
want: SwitchOp{Target: "-"}},
|
||||
{name: "unrecognized flag",
|
||||
args: []string{"-x"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported option '-x'")}},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported option %q", "-x")}},
|
||||
{name: "too many args",
|
||||
args: []string{"a", "b", "c"},
|
||||
want: UnsupportedOp{Err: fmt.Errorf("too many arguments")}},
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -51,10 +65,10 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
if choice == "" {
|
||||
return errors.New("you did not choose any of the options")
|
||||
}
|
||||
name, err := switchNamespace(kc, choice)
|
||||
name, err := switchNamespace(kc, choice, false)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch namespace")
|
||||
}
|
||||
printer.Success(stderr, "Active namespace is %q.", printer.SuccessColor.Sprint(name))
|
||||
printer.Success(stderr, "Active namespace is \"%s\".", printer.SuccessColor.Sprint(name))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -21,10 +35,12 @@ func printUsage(out io.Writer) error {
|
||||
help := `USAGE:
|
||||
%PROG% : list the namespaces in the current context
|
||||
%PROG% <NAME> : change the active namespace of current context
|
||||
%PROG% <NAME> --force/-f : force change the active namespace of current context (even if it doesn't exist)
|
||||
%PROG% - : switch to the previous namespace in this context
|
||||
%PROG% -c, --current : show the current namespace
|
||||
%PROG% -h,--help : show this message
|
||||
`
|
||||
%PROG% -V,--version : show version`
|
||||
|
||||
// TODO this replace logic is duplicated between this and kubectx
|
||||
help = strings.ReplaceAll(help, "%PROG%", selfName())
|
||||
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -61,10 +76,12 @@ func queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {
|
||||
var out []string
|
||||
var next string
|
||||
for {
|
||||
list, err := clientset.CoreV1().Namespaces().List(metav1.ListOptions{
|
||||
Limit: 500,
|
||||
Continue: next,
|
||||
})
|
||||
list, err := clientset.CoreV1().Namespaces().List(
|
||||
context.Background(),
|
||||
metav1.ListOptions{
|
||||
Limit: 500,
|
||||
Continue: next,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to list namespaces from k8s API")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -37,7 +51,7 @@ func TestNSFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "bar"; v != expected {
|
||||
t.Fatalf("Load()=%q; expected=%q", v, expected)
|
||||
t.Fatalf("Load()=\"%s\"; expected=\"%s\"", v, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
@@ -14,6 +29,7 @@ import (
|
||||
|
||||
type SwitchOp struct {
|
||||
Target string // '-' for back and forth, or NAME
|
||||
Force bool // force switch even if the namespace doesn't exist
|
||||
}
|
||||
|
||||
func (s SwitchOp) Run(_, stderr io.Writer) error {
|
||||
@@ -23,22 +39,22 @@ func (s SwitchOp) Run(_, stderr io.Writer) error {
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
|
||||
toNS, err := switchNamespace(kc, s.Target)
|
||||
toNS, err := switchNamespace(kc, s.Target, s.Force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = printer.Success(stderr, "Active namespace is %q", toNS)
|
||||
err = printer.Success(stderr, "Active namespace is \"%s\"", printer.SuccessColor.Sprint(toNS))
|
||||
return err
|
||||
}
|
||||
|
||||
func switchNamespace(kc *kubeconfig.Kubeconfig, ns string) (string, error) {
|
||||
func switchNamespace(kc *kubeconfig.Kubeconfig, ns string, force bool) (string, error) {
|
||||
ctx := kc.GetCurrentContext()
|
||||
if ctx == "" {
|
||||
return "", errors.New("current-context is not set")
|
||||
}
|
||||
curNS, err := kc.NamespaceOfContext(ctx)
|
||||
if ctx == "" {
|
||||
return "", errors.New("failed to get current namespace")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get current namespace")
|
||||
}
|
||||
|
||||
f := NewNSFile(ctx)
|
||||
@@ -54,16 +70,18 @@ func switchNamespace(kc *kubeconfig.Kubeconfig, ns string) (string, error) {
|
||||
ns = prev
|
||||
}
|
||||
|
||||
ok, err := namespaceExists(kc, ns)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to query if namespace exists (is cluster accessible?)")
|
||||
}
|
||||
if !ok {
|
||||
return "", errors.Errorf("no namespace exists with name %q", ns)
|
||||
if !force {
|
||||
ok, err := namespaceExists(kc, ns)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to query if namespace exists (is cluster accessible?)")
|
||||
}
|
||||
if !ok {
|
||||
return "", errors.Errorf("no namespace exists with name \"%s\"", ns)
|
||||
}
|
||||
}
|
||||
|
||||
if err := kc.SetNamespace(ctx, ns); err != nil {
|
||||
return "", errors.Wrapf(err, "failed to change to namespace %q", ns)
|
||||
return "", errors.Wrapf(err, "failed to change to namespace \"%s\"", ns)
|
||||
}
|
||||
if err := kc.Save(); err != nil {
|
||||
return "", errors.Wrap(err, "failed to save kubeconfig file")
|
||||
@@ -87,7 +105,7 @@ func namespaceExists(kc *kubeconfig.Kubeconfig, ns string) (bool, error) {
|
||||
return false, errors.Wrap(err, "failed to initialize k8s REST client")
|
||||
}
|
||||
|
||||
namespace, err := clientset.CoreV1().Namespaces().Get(ns, metav1.GetOptions{})
|
||||
namespace, err := clientset.CoreV1().Namespaces().Get(context.Background(), ns, metav1.GetOptions{})
|
||||
if errors2.IsNotFound(err) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
20
cmd/kubens/version.go
Normal file
20
cmd/kubens/version.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "v0.0.0+unknown" // populated by goreleaser
|
||||
)
|
||||
|
||||
// VersionOp describes printing version string.
|
||||
type VersionOp struct{}
|
||||
|
||||
func (_ VersionOp) Run(stdout, _ io.Writer) error {
|
||||
_, err := fmt.Fprintf(stdout, "%s\n", version)
|
||||
return errors.Wrap(err, "write error")
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
local KUBECTX="${HOME}/.kube/kubectx"
|
||||
PREV=""
|
||||
|
||||
local all_contexts="$(kubectl config get-contexts --output='name')"
|
||||
local context_array=("${(@f)$(kubectl config get-contexts --output='name')}")
|
||||
local all_contexts=(\'${^context_array}\')
|
||||
|
||||
if [ -f "$KUBECTX" ]; then
|
||||
# show '-' only if there's a saved previous context
|
||||
local PREV=$(cat "${KUBECTX}")
|
||||
@@ -1,3 +1,10 @@
|
||||
# kubectx
|
||||
complete -f -c kubectx -a "- (kubectl config get-contexts --output='name')"
|
||||
|
||||
function __fish_kubectx_arg_number -a number
|
||||
set -l cmd (commandline -opc)
|
||||
test (count $cmd) -eq $number
|
||||
end
|
||||
|
||||
complete -f -c kubectx
|
||||
complete -f -x -c kubectx -n '__fish_kubectx_arg_number 1' -a "(kubectl config get-contexts --output='name')"
|
||||
complete -f -x -c kubectx -n '__fish_kubectx_arg_number 1' -a "-" -d "switch to the previous namespace in this context"
|
||||
|
||||
62
go.mod
62
go.mod
@@ -1,22 +1,56 @@
|
||||
module github.com/ahmetb/kubectx
|
||||
|
||||
go 1.14
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
|
||||
github.com/fatih/color v1.9.0
|
||||
github.com/gogo/protobuf v1.3.1 // indirect
|
||||
github.com/google/go-cmp v0.4.0
|
||||
github.com/google/gofuzz v1.1.0 // indirect
|
||||
github.com/googleapis/gnostic v0.1.0 // indirect
|
||||
github.com/imdario/mergo v0.3.9 // indirect
|
||||
github.com/mattn/go-isatty v0.0.12
|
||||
github.com/google/go-cmp v0.5.9
|
||||
github.com/mattn/go-isatty v0.0.14
|
||||
github.com/pkg/errors v0.9.1
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
|
||||
k8s.io/apimachinery v0.17.0
|
||||
k8s.io/client-go v0.17.0
|
||||
k8s.io/utils v0.0.0-20200414100711-2df71ebbae66 // indirect
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
k8s.io/apimachinery v0.28.5
|
||||
k8s.io/client-go v0.28.5
|
||||
sigs.k8s.io/kustomize/kyaml v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||
github.com/go-openapi/swag v0.22.3 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/gnostic-models v0.6.8 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/imdario/mergo v0.3.9 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.4 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/oauth2 v0.8.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/api v0.28.5 // indirect
|
||||
k8s.io/klog/v2 v2.100.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
|
||||
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
||||
314
go.sum
314
go.sum
@@ -1,233 +1,167 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:1pSweJFeR3Pqx7uoelppkzeegfUBXL6I2FFAbfXw570=
|
||||
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:npRYmtaITVom7rcSo+pRURltHSG2r4TQM1cdqJ2dUB0=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0 h1:MRvx8gncNaXJqOoLmhNjUAKh33JJF8LyxPhomEtOsjs=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0 h1:q2gDruN08/guU9vAjuPWff0+QIrpH6ediguzdAzXAUU=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0 h1:Ww5g4zThfD/6cLb4z6xxgeyDa7QDkizMkJKe0ysZXp0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
|
||||
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
|
||||
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
|
||||
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
|
||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
|
||||
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
||||
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
|
||||
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 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
|
||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
|
||||
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/googleapis/gnostic v0.1.0 h1:rVsPeBmXbYv4If/cumu1AzZPwV58q433hvONV1UEZoI=
|
||||
github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/gophercloud/gophercloud v0.1.0 h1:P/nh25+rzXouhytV2pUHBb65fnds26Ghl8/391+sT5o=
|
||||
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
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/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.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
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.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
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 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
|
||||
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/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.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE=
|
||||
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
|
||||
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 v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
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/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
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.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
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/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
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.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
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/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-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
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.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
|
||||
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=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
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/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.17.0 h1:H9d/lw+VkZKEVIUc8F3wgiQ+FUXTTr21M87jXLU7yqM=
|
||||
k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI=
|
||||
k8s.io/apimachinery v0.17.0 h1:xRBnuie9rXcPxUkDizUsGvPf1cnlZCFu210op7J7LJo=
|
||||
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
|
||||
k8s.io/client-go v0.17.0 h1:8QOGvUGdqDMFrm9sD6IUFl256BcffynGoe80sxgTEDg=
|
||||
k8s.io/client-go v0.17.0/go.mod h1:TYgR6EUHs6k45hb6KWjVD6jFZvJV4gHDikv/It0xz+k=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
k8s.io/utils v0.0.0-20200414100711-2df71ebbae66 h1:Ly1Oxdu5p5ZFmiVT71LFgeZETvMfZ1iBIGeOenT2JeM=
|
||||
k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e h1:4Z09Hglb792X0kfOBBJUPFEyvVfQWrYT/l8h5EKA6JQ=
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
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.28.5 h1:XIPNr3nBgTEaCdEiwZ+dXaO9SB4NeTOZ2pNDRrFgfb4=
|
||||
k8s.io/api v0.28.5/go.mod h1:98zkTCc60iSnqqCIyCB1GI7PYDiRDYTSfL0PRIxpM4c=
|
||||
k8s.io/apimachinery v0.28.5 h1:EEj2q1qdTcv2p5wl88KavAn3VlFRjREgRu8Sm/EuMPY=
|
||||
k8s.io/apimachinery v0.28.5/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg=
|
||||
k8s.io/client-go v0.28.5 h1:6UNmc33vuJhh3+SAOEKku3QnKa+DtPKGnhO2MR0IEbk=
|
||||
k8s.io/client-go v0.28.5/go.mod h1:+pt086yx1i0HAlHzM9S+RZQDqdlzuXFl4hY01uhpcpA=
|
||||
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
|
||||
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
|
||||
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
|
||||
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
|
||||
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
|
||||
sigs.k8s.io/kustomize/kyaml v0.16.0 h1:6J33uKSoATlKZH16unr2XOhDI+otoe2sR3M8PDzW3K0=
|
||||
sigs.k8s.io/kustomize/kyaml v0.16.0/go.mod h1:xOK/7i+vmE14N2FdFyugIshB8eF6ALpy7jI87Q2nRh4=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
|
||||
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
@@ -26,9 +40,9 @@ func TestPrintDeprecatedEnvWarnings_bgColors(t *testing.T) {
|
||||
})
|
||||
v := out.String()
|
||||
if !strings.Contains(v, "KUBECTX_CURRENT_FGCOLOR") {
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_FGCOLOR': %q", v)
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_FGCOLOR': \"%s\"", v)
|
||||
}
|
||||
if !strings.Contains(v, "KUBECTX_CURRENT_BGCOLOR") {
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_BGCOLOR': %q", v)
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_BGCOLOR': \"%s\"", v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
@@ -7,9 +21,6 @@ import (
|
||||
)
|
||||
|
||||
func HomeDir() string {
|
||||
if v := os.Getenv("XDG_CACHE_HOME"); v != "" {
|
||||
return v
|
||||
}
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
home = os.Getenv("USERPROFILE") // windows
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
@@ -14,12 +28,12 @@ func Test_homeDir(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "XDG_CACHE_HOME precedence",
|
||||
name: "don't use XDG_CACHE_HOME as homedir",
|
||||
envs: []env{
|
||||
{"XDG_CACHE_HOME", "xdg"},
|
||||
{"HOME", "home"},
|
||||
},
|
||||
want: "xdg",
|
||||
want: "home",
|
||||
},
|
||||
{
|
||||
name: "HOME over USERPROFILE",
|
||||
@@ -32,7 +46,6 @@ func Test_homeDir(t *testing.T) {
|
||||
{
|
||||
name: "only USERPROFILE available",
|
||||
envs: []env{
|
||||
{"XDG_CACHE_HOME", ""},
|
||||
{"HOME", ""},
|
||||
{"USERPROFILE", "up"},
|
||||
},
|
||||
@@ -41,7 +54,6 @@ func Test_homeDir(t *testing.T) {
|
||||
{
|
||||
name: "none available",
|
||||
envs: []env{
|
||||
{"XDG_CACHE_HOME", ""},
|
||||
{"HOME", ""},
|
||||
{"USERPROFILE", ""},
|
||||
},
|
||||
|
||||
18
internal/env/constants.go
vendored
18
internal/env/constants.go
vendored
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package env
|
||||
|
||||
const (
|
||||
@@ -5,7 +19,7 @@ const (
|
||||
// interactive context selection when fzf is installed.
|
||||
EnvFZFIgnore = "KUBECTX_IGNORE_FZF"
|
||||
|
||||
// EnvForceColor describes the environment variable to disable color usage
|
||||
// EnvNoColor describes the environment variable to disable color usage
|
||||
// when printing current context in a list.
|
||||
EnvNoColor = `NO_COLOR`
|
||||
|
||||
@@ -15,4 +29,6 @@ const (
|
||||
|
||||
// EnvDebug describes the internal environment variable for more verbose logging.
|
||||
EnvDebug = `DEBUG`
|
||||
|
||||
EnvIsolatedShell = "KUBECTX_ISOLATED_SHELL"
|
||||
)
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
"errors"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
func (k *Kubeconfig) DeleteContextEntry(deleteName string) error {
|
||||
@@ -10,60 +25,34 @@ func (k *Kubeconfig) DeleteContextEntry(deleteName string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i := -1
|
||||
for j, ctxNode := range contexts.Content {
|
||||
nameNode := valueOf(ctxNode, "name")
|
||||
if nameNode != nil && nameNode.Kind == yaml.ScalarNode && nameNode.Value == deleteName {
|
||||
i = j
|
||||
break
|
||||
}
|
||||
}
|
||||
if i >= 0 {
|
||||
copy(contexts.Content[i:], contexts.Content[i+1:])
|
||||
contexts.Content[len(contexts.Content)-1] = nil
|
||||
contexts.Content = contexts.Content[:len(contexts.Content)-1]
|
||||
if err := contexts.PipeE(
|
||||
yaml.ElementSetter{
|
||||
Keys: []string{"name"},
|
||||
Values: []string{deleteName},
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) ModifyCurrentContext(name string) error {
|
||||
currentCtxNode := valueOf(k.rootNode, "current-context")
|
||||
if currentCtxNode != nil {
|
||||
currentCtxNode.Value = name
|
||||
return nil
|
||||
if err := k.config.PipeE(yaml.SetField("current-context", yaml.NewScalarRNode(name))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if current-context field doesn't exist, create new field
|
||||
keyNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "current-context",
|
||||
Tag: "!!str"}
|
||||
valueNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: name,
|
||||
Tag: "!!str"}
|
||||
k.rootNode.Content = append(k.rootNode.Content, keyNode, valueNode)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) ModifyContextName(old, new string) error {
|
||||
contexts, err := k.contextsNode()
|
||||
context, err := k.config.Pipe(yaml.Lookup("contexts", "[name="+old+"]"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var changed bool
|
||||
for _, contextNode := range contexts.Content {
|
||||
nameNode := valueOf(contextNode, "name")
|
||||
if nameNode.Kind == yaml.ScalarNode && nameNode.Value == old {
|
||||
nameNode.Value = new
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
if context == nil {
|
||||
return errors.New("\"contexts\" entry is nil")
|
||||
}
|
||||
if !changed {
|
||||
return errors.New("no changes were made")
|
||||
if err := context.PipeE(yaml.SetField("name", yaml.NewScalarRNode(new))); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,52 +1,62 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
func (k *Kubeconfig) contextsNode() (*yaml.Node, error) {
|
||||
contexts := valueOf(k.rootNode, "contexts")
|
||||
func (k *Kubeconfig) contextsNode() (*yaml.RNode, error) {
|
||||
contexts, err := k.config.Pipe(yaml.Get("contexts"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if contexts == nil {
|
||||
return nil, errors.New("\"contexts\" entry is nil")
|
||||
} else if contexts.Kind != yaml.SequenceNode {
|
||||
} else if contexts.YNode().Kind != yaml.SequenceNode {
|
||||
return nil, errors.New("\"contexts\" is not a sequence node")
|
||||
}
|
||||
return contexts, nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) contextNode(name string) (*yaml.Node, error) {
|
||||
func (k *Kubeconfig) contextNode(name string) (*yaml.RNode, error) {
|
||||
contexts, err := k.contextsNode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, contextNode := range contexts.Content {
|
||||
nameNode := valueOf(contextNode, "name")
|
||||
if nameNode.Kind == yaml.ScalarNode && nameNode.Value == name {
|
||||
return contextNode, nil
|
||||
}
|
||||
context, err := contexts.Pipe(yaml.Lookup("[name=" + name + "]"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errors.Errorf("context with name %q not found", name)
|
||||
if context == nil {
|
||||
return nil, errors.Errorf("context with name \"%s\" not found", name)
|
||||
}
|
||||
return context, nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) ContextNames() []string {
|
||||
contexts := valueOf(k.rootNode, "contexts")
|
||||
if contexts == nil {
|
||||
contexts, err := k.config.Pipe(yaml.Get("contexts"))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if contexts.Kind != yaml.SequenceNode {
|
||||
names, err := contexts.ElementValues("name")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ctxNames []string
|
||||
for _, ctx := range contexts.Content {
|
||||
nameVal := valueOf(ctx, "name")
|
||||
if nameVal != nil {
|
||||
ctxNames = append(ctxNames, nameVal.Value)
|
||||
}
|
||||
}
|
||||
return ctxNames
|
||||
return names
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) ContextExists(name string) bool {
|
||||
@@ -58,15 +68,3 @@ func (k *Kubeconfig) ContextExists(name string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func valueOf(mapNode *yaml.Node, key string) *yaml.Node {
|
||||
if mapNode.Kind != yaml.MappingNode {
|
||||
return nil
|
||||
}
|
||||
for i, ch := range mapNode.Content {
|
||||
if i%2 == 0 && ch.Kind == yaml.ScalarNode && ch.Value == key {
|
||||
return mapNode.Content[i+1]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
// GetCurrentContext returns "current-context" value in given
|
||||
// kubeconfig object Node, or returns "" if not found.
|
||||
func (k *Kubeconfig) GetCurrentContext() string {
|
||||
v := valueOf(k.rootNode, "current-context")
|
||||
if v == nil {
|
||||
v, err := k.config.Pipe(yaml.Get("current-context"))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return v.Value
|
||||
return yaml.GetValue(v)
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) UnsetCurrentContext() error {
|
||||
curCtxValNode := valueOf(k.rootNode, "current-context")
|
||||
curCtxValNode.Value = ""
|
||||
return nil
|
||||
return k.config.PipeE(yaml.SetField("current-context", yaml.NewStringRNode("")))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
@@ -16,7 +30,7 @@ func TestKubeconfig_GetCurrentContext(t *testing.T) {
|
||||
|
||||
expected := "foo"
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +44,7 @@ func TestKubeconfig_GetCurrentContext_missingField(t *testing.T) {
|
||||
|
||||
expected := ""
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +64,6 @@ func TestKubeconfig_UnsetCurrentContext(t *testing.T) {
|
||||
out := tl.Output()
|
||||
expected := testutil.KC().WithCurrentCtx("").ToYAML(t)
|
||||
if out != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, out)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, out)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
type ReadWriteResetCloser interface {
|
||||
@@ -21,8 +35,8 @@ type Loader interface {
|
||||
type Kubeconfig struct {
|
||||
loader Loader
|
||||
|
||||
f ReadWriteResetCloser
|
||||
rootNode *yaml.Node
|
||||
f ReadWriteResetCloser
|
||||
config *yaml.RNode
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) WithLoader(l Loader) *Kubeconfig {
|
||||
@@ -51,15 +65,19 @@ func (k *Kubeconfig) Parse() error {
|
||||
if err := yaml.NewDecoder(f).Decode(&v); err != nil {
|
||||
return errors.Wrap(err, "failed to decode")
|
||||
}
|
||||
k.rootNode = v.Content[0]
|
||||
if k.rootNode.Kind != yaml.MappingNode {
|
||||
k.config = yaml.NewRNode(&v)
|
||||
if k.config.YNode().Kind != yaml.MappingNode {
|
||||
return errors.New("kubeconfig file is not a map document")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) Bytes() ([]byte, error) {
|
||||
return yaml.Marshal(k.rootNode)
|
||||
str, err := k.config.String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(str), nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) Save() error {
|
||||
@@ -68,5 +86,5 @@ func (k *Kubeconfig) Save() error {
|
||||
}
|
||||
enc := yaml.NewEncoder(k.f)
|
||||
enc.SetIndent(0)
|
||||
return enc.Encode(k.rootNode)
|
||||
return enc.Encode(k.config.YNode())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultNamespace = "default"
|
||||
@@ -11,53 +27,23 @@ func (k *Kubeconfig) NamespaceOfContext(contextName string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ctxBody := valueOf(ctx, "context")
|
||||
if ctxBody == nil {
|
||||
return defaultNamespace, nil
|
||||
namespace, err := ctx.Pipe(yaml.Lookup("context", "namespace"))
|
||||
if namespace == nil || err != nil {
|
||||
return defaultNamespace, err
|
||||
}
|
||||
ns := valueOf(ctxBody, "namespace")
|
||||
if ns == nil || ns.Value == "" {
|
||||
return defaultNamespace, nil
|
||||
}
|
||||
return ns.Value, nil
|
||||
return yaml.GetValue(namespace), nil
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) SetNamespace(ctxName string, ns string) error {
|
||||
ctxNode, err := k.contextNode(ctxName)
|
||||
ctx, err := k.contextNode(ctxName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ctxBodyNodeWasEmpty bool // actual namespace value is in contexts[index].context.namespace, but .context might not exist
|
||||
ctxBodyNode := valueOf(ctxNode, "context")
|
||||
if ctxBodyNode == nil {
|
||||
ctxBodyNodeWasEmpty = true
|
||||
ctxBodyNode = &yaml.Node{
|
||||
Kind: yaml.MappingNode,
|
||||
}
|
||||
}
|
||||
|
||||
nsNode := valueOf(ctxBodyNode, "namespace")
|
||||
if nsNode != nil {
|
||||
nsNode.Value = ns
|
||||
return nil
|
||||
}
|
||||
|
||||
keyNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "namespace",
|
||||
Tag: "!!str"}
|
||||
valueNode := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: ns,
|
||||
Tag: "!!str"}
|
||||
ctxBodyNode.Content = append(ctxBodyNode.Content, keyNode, valueNode)
|
||||
if ctxBodyNodeWasEmpty {
|
||||
ctxNode.Content = append(ctxNode.Content, &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "context",
|
||||
Tag: "!!str",
|
||||
}, ctxBodyNode)
|
||||
if err := ctx.PipeE(
|
||||
yaml.LookupCreate(yaml.MappingNode, "context"),
|
||||
yaml.SetField("namespace", yaml.NewStringRNode(ns)),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
@@ -35,7 +49,7 @@ func TestKubeconfig_NamespaceOfContext(t *testing.T) {
|
||||
t.Fatal("expected err")
|
||||
}
|
||||
if expected := `default`; v1 != expected {
|
||||
t.Fatalf("c1: expected=%q got=%q", expected, v1)
|
||||
t.Fatalf("c1: expected=\"%s\" got=\"%s\"", expected, v1)
|
||||
}
|
||||
|
||||
v2, err := kc.NamespaceOfContext("c2")
|
||||
@@ -43,7 +57,7 @@ func TestKubeconfig_NamespaceOfContext(t *testing.T) {
|
||||
t.Fatal("expected err")
|
||||
}
|
||||
if expected := `c2n1`; v2 != expected {
|
||||
t.Fatalf("c2: expected=%q got=%q", expected, v2)
|
||||
t.Fatalf("c2: expected=\"%s\" got=\"%s\"", expected, v2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package printer
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package printer
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package printer
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
@@ -32,7 +46,9 @@ func (k *Kubeconfig) WithCtxs(c ...*Context) *Kubeconfig { (*k)["contexts
|
||||
func (k *Kubeconfig) ToYAML(t *testing.T) string {
|
||||
t.Helper()
|
||||
var v strings.Builder
|
||||
if err := yaml.NewEncoder(&v).Encode(*k); err != nil {
|
||||
enc := yaml.NewEncoder(&v)
|
||||
enc.SetIndent(0)
|
||||
if err := enc.Encode(*k); err != nil {
|
||||
t.Fatalf("failed to encode mock kubeconfig: %v", err)
|
||||
}
|
||||
return v.String()
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package testutil
|
||||
|
||||
import "os"
|
||||
|
||||
22
kubectx
22
kubectx
@@ -33,6 +33,8 @@ usage() {
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Manage and switch between kubectl contexts.
|
||||
|
||||
USAGE:
|
||||
$SELF : list the contexts
|
||||
$SELF <NAME> : switch to context <NAME>
|
||||
@@ -46,6 +48,8 @@ USAGE:
|
||||
$SELF -u, --unset : unset the current context
|
||||
|
||||
$SELF -h,--help : show this message
|
||||
|
||||
(This executable is the legacy bash-based implementation, consider upgrading to Go-based implementation.)
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -192,13 +196,15 @@ unset_context() {
|
||||
}
|
||||
|
||||
main() {
|
||||
if hash kubectl 2>/dev/null; then
|
||||
KUBECTL=kubectl
|
||||
elif hash kubectl.exe 2>/dev/null; then
|
||||
KUBECTL=kubectl.exe
|
||||
else
|
||||
echo >&2 "kubectl is not installed"
|
||||
exit 1
|
||||
if [[ -z "${KUBECTL:-}" ]]; then
|
||||
if hash kubectl 2>/dev/null; then
|
||||
KUBECTL=kubectl
|
||||
elif hash kubectl.exe 2>/dev/null; then
|
||||
KUBECTL=kubectl.exe
|
||||
else
|
||||
echo >&2 "kubectl is not installed"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
@@ -225,7 +231,7 @@ main() {
|
||||
# we don't call current_context here for two reasons:
|
||||
# - it does not fail when current-context property is not set
|
||||
# - it does not return a trailing newline
|
||||
kubectl config current-context
|
||||
$KUBECTL config current-context
|
||||
elif [[ "${1}" == '-u' || "${1}" == '--unset' ]]; then
|
||||
unset_context
|
||||
elif [[ "${1}" == '-h' || "${1}" == '--help' ]]; then
|
||||
|
||||
4
kubens
4
kubens
@@ -33,12 +33,16 @@ usage() {
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Switch between Kubernetes namespaces.
|
||||
|
||||
USAGE:
|
||||
$SELF : list the namespaces in the current context
|
||||
$SELF <NAME> : change the active namespace of current context
|
||||
$SELF - : switch to the previous namespace in this context
|
||||
$SELF -c, --current : show the current namespace
|
||||
$SELF -h,--help : show this message
|
||||
|
||||
(This executable is the legacy bash-based implementation, consider upgrading to Go-based implementation.)
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
# bats setup function
|
||||
setup() {
|
||||
export XDG_CACHE_HOME="$(mktemp -d)"
|
||||
export KUBECONFIG="${XDG_CACHE_HOME}/config"
|
||||
TEMP_HOME="$(mktemp -d)"
|
||||
export TEMP_HOME
|
||||
export HOME=$TEMP_HOME
|
||||
export KUBECONFIG="${TEMP_HOME}/config"
|
||||
}
|
||||
|
||||
# bats teardown function
|
||||
teardown() {
|
||||
rm -rf "$XDG_CACHE_HOME"
|
||||
rm -rf "$TEMP_HOME"
|
||||
}
|
||||
|
||||
use_config() {
|
||||
|
||||
Reference in New Issue
Block a user