File k8senv-1.1.1.obscpio of Package k8senv
07070100000000000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001500000000k8senv-1.1.1/.github07070100000001000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001F00000000k8senv-1.1.1/.github/workflows07070100000002000081A40000000000000000000000016726190A0000020D000000000000000000000000000000000000002600000000k8senv-1.1.1/.github/workflows/ci.ymlname: "CI"
on:
push:
pull_request:
workflow_dispatch:
jobs:
test:
name: CI/CD Test
# https://github.com/actions/virtual-environments/
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: 🔧 Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# Test
- name: 🌡️ Test
run: |
go run main.go -h && go run main.go version
chmod +x test.sh
./test.sh07070100000003000081A40000000000000000000000016726190A0000166A000000000000000000000000000000000000002B00000000k8senv-1.1.1/.github/workflows/release.ymlname: Release
on:
push:
tags:
- "v*.*.*"
jobs:
build:
name: Build
# https://github.com/actions/virtual-environments/
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
# https://github.com/marketplace/actions/setup-go-environment
- name: 🔧 Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: 🍳 Build
run: bash build.sh
# Test binary
- name: 🌡️ Test
run: chmod +x k8senv-linux-amd64 && ./k8senv-linux-amd64 -h
# K8senv version and Tag name must match
- name: Test K8senv version
run: |
#!/usr/bin/env bash
chmod +x k8senv-linux-amd64
version=$(./k8senv-linux-amd64 version | cut -d " " -f 2 | jq .K8senv | tr -d "\"")
tag=$(echo "${{ github.ref }}" | rev | cut -d "/" -f 1 | rev)
if [ "$tag" != "$version" ]; then
echo "Tag version and release doesnot match"
exit 1
fi
# Upload binaries
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: 📤 Upload
uses: actions/upload-artifact@v3
with:
name: k8senv
path: k8senv*
retention-days: 1
test-linux:
name: Test Linux
needs: build
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
# Download binaries
# https://github.com/marketplace/actions/download-a-build-artifact
- name: 📥 Download
uses: actions/download-artifact@v3
with:
name: k8senv
# Test binary
- name: 🌡️ Test
run: |
chmod +x k8senv-linux-amd64 && ./k8senv-linux-amd64 -h
chmod +x test.sh
./test.sh
# test-macos:
# name: Test macOS
# needs: build
# runs-on: macos-latest
# steps:
# - name: 🛎️ Checkout
# uses: actions/checkout@v3
# - name: 📥 Download
# uses: actions/download-artifact@v3
# with:
# name: k8senv
# # Test binary
# - name: 🌡️ Test
# run: chmod +x k8senv-macos-x86_64 && ./k8senv-macos-x86_64 -h
# test-version:
# name: Test version
# needs: build
# runs-on: ubuntu-latest
# steps:
# # Download binaries
# # https://github.com/marketplace/actions/download-a-build-artifact
# - name: 📥 Download
# uses: actions/download-artifact@v3
# with:
# name: k8senv
# - run: |
# #!/usr/bin/env bash
# chmod +x k8senv-linux-amd64
# version=$(./k8senv-linux-amd64 version | cut -d " " -f 2 | jq .K8senv | tr -d "\"")
# tag=$(echo "${{ github.ref }}" | rev | cut -d "/" -f 1 | rev)
# if [ "$tag" != "$version" ]; then
# echo "Tag version and release doesnot match"
# exit 1
# fi
pre-release:
if: startsWith(github.ref, 'refs/tags/v0.') || endsWith(github.ref, '-beta') || endsWith(github.ref, '-alpha')
name: Pre-release
needs: [test-linux]
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: 📥 Download
uses: actions/download-artifact@v3
with:
name: k8senv
- name: Generate checksums
run: |
sha256sum k8senv-linux-amd64 > CHECKSUM
sha256sum k8senv-linux-arm64 >> CHECKSUM
# Release, upload files
# https://github.com/marketplace/actions/gh-release
- name: ✨ Release
uses: softprops/action-gh-release@v1
with:
files: |
k8senv-linux-amd64
k8senv-linux-arm64
CHECKSUM
generate_release_notes: true
prerelease: true
release:
if: false == (startsWith(github.ref, 'refs/tags/v0.') || endsWith(github.ref, '-beta') || endsWith(github.ref, '-alpha'))
name: Release
needs: [test-linux]
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: 📥 Download
uses: actions/download-artifact@v3
with:
name: k8senv
- name: Generate checksums
run: |
sha256sum k8senv-linux-amd64 > CHECKSUM
sha256sum k8senv-linux-arm64 >> CHECKSUM
# Release, upload files
# https://github.com/marketplace/actions/gh-release
- name: ✨ Release
uses: softprops/action-gh-release@v1
with:
files: |
k8senv-linux-amd64
k8senv-linux-arm64
CHECKSUM
generate_release_notes: true
docker-push:
name: docker-push
needs: [test-linux]
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Genarate Tag
run: |
#!/usr/bin/env bash
tag=$(echo "${{ github.ref }}" | rev | cut -d "/" -f 1 | rev)
echo "TAGID=$tag" >> "$GITHUB_OUTPUT"
id: generate-tag
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/k8senv:latest,${{ secrets.DOCKERHUB_USERNAME }}/k8senv:${{ steps.generate-tag.outputs.TAGID }}07070100000004000081A40000000000000000000000016726190A00000121000000000000000000000000000000000000001800000000k8senv-1.1.1/.gitignore# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# NOTES.txt
k8senv-*07070100000005000081A40000000000000000000000016726190A0000027F000000000000000000000000000000000000001800000000k8senv-1.1.1/DockerfileFROM golang:1.23.2-alpine3.20 as build
ARG OS
ARG ARCH
WORKDIR /build
COPY . .
RUN apk add git
RUN go mod download && \
CGO_ENABLED=0 go build -o k8senv
FROM alpine:3.20
ARG VERSION
ARG user=k8senv
ARG group=k8senv
ARG uid=1000
ARG gid=1000
USER root
WORKDIR /app
COPY --from=build /build/k8senv /app/.k8senv/bin/k8senv
RUN apk update && apk --no-cache add bash vim && addgroup -g ${gid} ${group} && adduser -h /app -u ${uid} -G ${group} -s /bin/bash -D ${user}
RUN chown -R k8senv:k8senv /app/.k8senv && chmod -R u+rx /app/.k8senv
USER k8senv
ENV PATH="/app/.k8senv/bin:$PATH"
VOLUME /app/.k8senv/
ENTRYPOINT [ "k8senv"]
CMD ["help"]07070100000006000081A40000000000000000000000016726190A00000433000000000000000000000000000000000000001500000000k8senv-1.1.1/LICENSEMIT License
Copyright (c) 2023 Navratan Lal Gupta
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
07070100000007000081A40000000000000000000000016726190A000002A3000000000000000000000000000000000000001700000000k8senv-1.1.1/NOTES.txtCommands variant:
k8senv install kubectl - DONE
k8senv install velero
k8senv install helm
k8senv use kubectl - DONE
k8senv use velero
k8senv use helm
k8senv list kubectl - DONE
k8senv list velero
k8senv list helm
k8senv remove kubectl - DONE
k8senv remove velero
k8senv remove helm
k8senv kubectl install - DONE
k8senv kubectl use - DONE
k8senv kubectl list - DONE
k8senv kubectl remove - DONE
k8senv velero install
k8senv velero use
k8senv velero list
k8senv velero remove
k8senv helm install
k8senv helm use
k8senv helm list
k8senv helm remove
07070100000008000081A40000000000000000000000016726190A0000143D000000000000000000000000000000000000001700000000k8senv-1.1.1/README.md# k8senv
[Kubernetes](https://kubernetes.io) client's version manager inspired by [tfenv](https://github.com/tfutils/tfenv)
Kubernetes clients supported at this moments are `kubectl`, or, `helm`, or, `velero` on Linux servers/machines.
Manytimes we need to manage many Kubernetes clusters from same jumpbox or machine or bastion server. Those many cluster may have different versions of Kubernetes. In that case, It becomes difficult to use multiple versions of Kubernetes clients to communicate with those different versions of clusters.
This small tool is to help manage different versions of Kubernetes clients. Kubernetes clients `kubectl`, `helm` and `velero` are supported at this stage.
- [How to install/setup](https://github.com/navilg/k8senv#how-to-installsetup)
- [Usage](https://github.com/navilg/k8senv#usage)
- [Demo](https://github.com/navilg/k8senv#demo)
## How to install/setup
1. Create a directory .k8senv/bin in home directory
```
mkdir -p ~/.k8senv/bin
```
2. Download `k8senv` tool into `.k8senv/bin` directory
[amd64](https://github.com/navilg/k8senv/releases/latest/download/k8senv-linux-amd64) Intel or AMD 64-Bit CPU
Download latest `k8senv` tool:
```
cd ~/.k8senv/bin
curl -L https://github.com/navilg/k8senv/releases/latest/download/k8senv-linux-amd64 -o k8senv
chmod +x k8senv
```
Download specific version of `k8senv`. For e.g. To download version `v1.0.2`:
```
cd ~/.k8senv/bin
curl -L https://github.com/navilg/k8senv/releases/download/v1.0.2/k8senv-linux-amd64 -o k8senv
chmod +x k8senv
```
[arm64](https://github.com/navilg/k8senv/releases/latest/download/k8senv-linux-arm64) Arm-based 64-Bit CPU (i.e. in Raspberry Pi)
Download latest `k8senv` tool:
```
cd ~/.k8senv/bin
curl -L https://github.com/navilg/k8senv/releases/latest/download/k8senv-linux-arm64 -o k8senv
chmod +x k8senv
```
Download specific version of `k8senv`. For e.g. To download version `v1.0.2`:
```
cd ~/.k8senv/bin
curl -L https://github.com/navilg/k8senv/releases/download/v1.0.2/k8senv-linux-arm64 -o k8senv
chmod +x k8senv
```
3. Add `~/.k8senv/bin` directory to your `PATH` environment variable
```
export PATH="$HOME/.k8senv/bin:$PATH"
echo 'export PATH="$HOME/.k8senv/bin:$PATH"' >> ~/.bashrc
hash -r
```
```
which k8senv
# OR
type k8senv
```
## Usage
```bash
k8senv [VERB] [CLIENT] [VERSION]
# [VERB] can be install, use, list or remove
# [CLIENT] can be kubectl, velero or helm
# [VERSION] can be any client's version in format v*.*.* or latest or auto (auto is only supported for kubectl and velero client for install and use subcommands)
examples:
k8senv use kubectl v1.23.2
k8senv install velero v1.8.1
k8senv use velero auto # Automatically detects Velero server version from current context and use same velero client version
k8senv install kubectl latest # To install latest available kubectl
k8senv install kubectl auto # Automatically detects Kubernetes version from current context and downloads same kubectl version
```
Examples:
**Install a kubectl version**
Any of below commands can be used to download 1.26.2 version of kubectl
```
k8senv install kubectl v1.26.2
k8senv install kubectl 1.26.2
k8senv kubectl install v1.26.2
k8senv install kubectl 1.26.2 --overwrite # Installs even if it already exists
k8senv install kubectl latest # Installs latest stable version of kubectl
k8s install kubectl v1.19.2 --timeout=300 # Install 1.19.2 with timeout of 300 seconds. Default timeout is 120 seconds.
k8senv install kubectl auto # Get Kubernetes version from current context and Install same version of kubectl
```
**List all installed version of kubectl**
Any of below commandds can be used to list all kubectl client's version installed by k8senv.
```
k8senv list kubectl
k8senv kubectl list
```
**Switch to a version of kubectl**
Any of below commands can be used to switch kubectl version to 1.26.2. If version is not available, It will install it automatically.
```
k8senv use kubectl v1.26.2
k8senv use kubectl 1.26.2
k8senv kubectl use v1.26.2
k8senv use kubectl auto
```
If you were using system installed version of `kubectl` in same shell session, you will need to clear the cached path of the kubectl using below command.
```
hash -d kubectl
```
**Unuse/Disable k8senv managed kubectl**
Any of the below command can be used to unuse or disable k8senv managed kubectl without uninstalling it. This will reset the system to use system installed kubectl, if present.
```
k8senv unuse kubectl
k8senv kubectl unuse
```
To clear the cached k8senv path of kubectl, you will need to clear it using below command before you can use system installed version of the tool.
```
hash -d kubectl
```
**Remove an existing version of kubectl**
Any of below commands can be used to remove kubectl version 1.26.2.
```
k8senv remove kubectl v1.26.2
k8senv remove kubectl 1.26.2
k8senv kubectl remove v1.26.2
```
**Similar command can be used to install, use, list and remove velero and helm clients.**
For e.g.
```
k8senv install helm v3.10.2
k8senv remove velero 1.10.1
```
## Demo
[](https://asciinema.org/a/dSPtu0bAPvPFxjhqtJR3LNC89)
07070100000009000081ED0000000000000000000000016726190A00000400000000000000000000000000000000000000001600000000k8senv-1.1.1/build.sh#!/usr/bin/env bash
go version || exit 1
commitId=$(git log --format="%H" -n 1)
sed -i "s|var gitCommit string = \"###GitCommitPlaceholder###\"|var gitCommit string = \"${commitId}\"|g" internal/config/config.go
# Linux
echo "Building for Linux OS with AMD64 Arch"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o k8senv-linux-amd64 main.go && echo "✅ DONE" || echo "❌ FAILED"
echo "Building for Linux OS with ARM64 Arch"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o k8senv-linux-arm64 main.go && echo "✅ DONE" || echo "❌ FAILED"
sed -i "s|var gitCommit string = \"${commitId}\"|var gitCommit string = \"###GitCommitPlaceholder###\"|g" internal/config/config.go
# macOS
# echo "Building for MacOS with AMD64 Arch"
# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o k8senv-macos-x86_64 main.go && echo "✅ DONE" || echo "❌ FAILED"
# echo "Building for MacOS with ARM64 Arch"
# CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o k8senv-macos-arm64 main.go && echo "✅ DONE" || echo "❌ FAILED"0707010000000A000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001100000000k8senv-1.1.1/cmd0707010000000B000081A40000000000000000000000016726190A000012D3000000000000000000000000000000000000001900000000k8senv-1.1.1/cmd/helm.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/install"
"github.com/navilg/k8senv/internal/list"
"github.com/navilg/k8senv/internal/remove"
"github.com/navilg/k8senv/internal/unuse"
"github.com/navilg/k8senv/internal/use"
"github.com/spf13/cobra"
)
// helmCmd represents the helm command
var helmCmd = &cobra.Command{
Use: "helm",
Short: "Install, Use or List versions of helm",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
//
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("helm called")
// },
}
var installHelmCmd = &cobra.Command{
Use: "helm VERSION",
Short: "Install a version of helm",
Long: `Install a version of helm
Examples:
# Install helm version 3.10.2
k8senv install helm v3.10.2
# Install latest available stable version of helm
k8senv install helm latest
# Install helm version 3.8.0 and overwrite it if it already exists
k8senv install helm 3.8.0 --overwrite
# Install helm version 1.8.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv install helm 3.8.0 --timeout=300
Supported version formats:
v3.10.2
3.10.2 # Defaults to v3.10.2
3.10 # Defaults to v3.10.0
3 # Defaults to v3.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to install e.g. v3.10.2")
os.Exit(1)
}
err := install.InstallVersion("helm", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
var useHelmCmd = &cobra.Command{
Use: "helm VERSION",
Short: "Switch to a version of helm",
Long: `Switch to a version of helm
Examples:
# Switch to helm version 3.10.2
k8senv use helm v3.10.2
k8senv use helm 3.10.2
Supported version formats:
v3.10.2
3.10.2 # Defaults to v3.10.2
3.10 # Defaults to v3.10.0
3 # Defaults to v3.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to use e.g. v3.10.2")
os.Exit(1)
}
err := use.UseVersion("helm", args[0])
if err != nil {
os.Exit(1)
}
},
}
var listHelmCmd = &cobra.Command{
Use: "helm",
Short: "List all installed versions of helm",
Long: `List all installed versions of helm
Examples:
k8senv list helm`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("helm")
if err != nil {
os.Exit(1)
}
},
}
var removeHelmCmd = &cobra.Command{
Use: "helm VERSION",
Short: "Remove an installed versions of helm",
Long: `Remove an installed versions of helm
Examples:
k8senv remove helm v3.10.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to remove e.g. v3.10.2")
os.Exit(1)
}
err := remove.RemoveVersion("helm", args[0])
if err != nil {
os.Exit(1)
}
},
}
var unuseHelmCmd = &cobra.Command{
Use: "helm",
Short: "Stop using k8senv managed helm",
Long: `Stop using k8senv managed helm.
This will reset your system to use system installed client of helm if present.
Examples:
k8senv unuse helm`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing helm")
os.Exit(1)
}
err := unuse.UnuseVersions("helm")
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(helmCmd)
installCmd.AddCommand(installHelmCmd)
useCmd.AddCommand(useHelmCmd)
listCmd.AddCommand(listHelmCmd)
removeCmd.AddCommand(removeHelmCmd)
unuseCmd.AddCommand(unuseHelmCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// helmCmd.PersistentFlags().String("foo", "", "A help for foo")
helmInstallCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
helmInstallCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
helmInstallCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// helmCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
0707010000000C000081A40000000000000000000000016726190A00001551000000000000000000000000000000000000001C00000000k8senv-1.1.1/cmd/install.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/install"
"github.com/spf13/cobra"
)
var overwriteInstall bool
var timeout int
var proxy string
// installCmd represents the install command
var installCmd = &cobra.Command{
Use: "install",
Short: "Install a version of kubectl, helm or velero client",
// Long: ``,
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("install called")
// },
}
// installCmd represents the install command
var kubectlInstallCmd = &cobra.Command{
Use: "install VERSION",
Short: "Install a version of kubectl",
Long: `Install a version of kubectl client
Examples:
# Install kubectl version 1.26.2
k8senv kubectl install v1.26.2
# Install latest available stable version of kubectl
k8senv kubectl install latest
# Install kubectl version 1.20.0 and overwrite it if it already exists
k8senv kubectl install 1.20.0 --overwrite
# Install kubectl version 1.20.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv kubectl install 1.20.0 --timeout=300
Supported version formats:
v1.20.3
1.20.3 # Defaults to v1.20.3
1.20 # Defaults to v1.20.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to install e.g. v1.20.3")
os.Exit(1)
}
err := install.InstallVersion("kubectl", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
var veleroInstallCmd = &cobra.Command{
Use: "install VERSION",
Short: "Install a version of velero",
Long: `Install a version of velero client
Examples:
# Install velero client version 1.10.2
k8senv velero install v1.10.2
# Install latest available stable version of velero client
k8senv velero install latest
# Install velero client version 1.8.0 and overwrite it if it already exists
k8senv velero install 1.8.0 --overwrite
# Install velero client version 1.8.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv velero install 1.8.0 --timeout=300
Supported version formats:
v1.10.2
1.10.2 # Defaults to v1.10.2
1.10 # Defaults to v1.10.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero version to install e.g. v1.20.3")
os.Exit(1)
}
err := install.InstallVersion("velero", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
var helmInstallCmd = &cobra.Command{
Use: "install VERSION",
Short: "Install a version of helm",
Long: `Install a version of helm
Examples:
# Install helm version 3.10.2
k8senv helm install v3.10.2
# Install latest available stable version of helm
k8senv helm install latest
# Install helm version 3.8.0 and overwrite it if it already exists
k8senv helm install 3.8.0 --overwrite
# Install helm version 3.8.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv helm install 3.8.0 --timeout=300
Supported version formats:
v3.10.2
3.10.2 # Defaults to v3.10.2
1.10 # Defaults to v1.10.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to install e.g. v3.10.2")
os.Exit(1)
}
err := install.InstallVersion("helm", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(installCmd)
kubectlCmd.AddCommand(kubectlInstallCmd)
veleroCmd.AddCommand(veleroInstallCmd)
helmCmd.AddCommand(helmInstallCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// installCmd.PersistentFlags().String("foo", "", "A help for foo")
// installKubectlCmd.PersistentFlags().BoolP("overwrite", "f", false, "Overwrite or re-install existing version")
installKubectlCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
installKubectlCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
installKubectlCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
installVeleroCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
installVeleroCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
installVeleroCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
installHelmCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
installHelmCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
installHelmCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// installCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
0707010000000D000081A40000000000000000000000016726190A00001275000000000000000000000000000000000000001C00000000k8senv-1.1.1/cmd/kubectl.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/install"
"github.com/navilg/k8senv/internal/list"
"github.com/navilg/k8senv/internal/remove"
"github.com/navilg/k8senv/internal/unuse"
"github.com/navilg/k8senv/internal/use"
"github.com/spf13/cobra"
)
var kubectlCmd = &cobra.Command{
Use: "kubectl",
Short: "Install, Use or List versions of kubectl",
// Long: ``,
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("kubectl called")
// },
}
// kubectlCmd represents the kubectl command
var installKubectlCmd = &cobra.Command{
Use: "kubectl VERSION",
Short: "Install a version of kubectl",
Long: `Install a version of kubectl client
Examples:
# Install kubectl version 1.26.2
k8senv install kubectl v1.26.2
# Install latest available stable version of kubectl
k8senv install kubectl latest
# Install kubectl version 1.20.0 and overwrite it if it already exists
k8senv install kubectl 1.20.0 --overwrite
# Install kubectl version 1.20.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv install kubectl 1.20.0 --timeout=300
Supported version formats:
v1.20.3
1.20.3 # Defaults to v1.20.3
1.20 # Defaults to v1.20.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to install e.g. v1.20.3")
os.Exit(1)
}
err := install.InstallVersion("kubectl", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
var useKubectlCmd = &cobra.Command{
Use: "kubectl VERSION",
Short: "Switch to a version of kubectl",
Long: `Switch to a version of kubectl client
Examples:
# Switch to kubectl version 1.26.2
k8senv use kubectl v1.26.2
k8senv use kubectl 1.26.2
Supported version formats:
v1.20.3
1.20.3 # Defaults to v1.20.3
1.20 # Defaults to v1.20.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to use e.g. v1.20.3")
os.Exit(1)
}
err := use.UseVersion("kubectl", args[0])
if err != nil {
os.Exit(1)
}
},
}
var listKubectlCmd = &cobra.Command{
Use: "kubectl",
Short: "List all installed versions of kubectl",
Long: `List all installed versions of kubectl
Examples:
k8senv list kubectl`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("kubectl")
if err != nil {
os.Exit(1)
}
},
}
var removeKubectlCmd = &cobra.Command{
Use: "kubectl VERSION",
Short: "Remove an installed versions of kubectl",
Long: `Remove an installed versions of kubectl
Examples:
k8senv remove kubectl v1.19.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to remove e.g. v1.20.3")
os.Exit(1)
}
err := remove.RemoveVersion("kubectl", args[0])
if err != nil {
os.Exit(1)
}
},
}
var unuseKubectlCmd = &cobra.Command{
Use: "kubectl",
Short: "Stop using k8senv managed kubectl",
Long: `Stop using k8senv managed kubectl.
This will reset your system to use system installed client of kubectl if present.
Examples:
k8senv unuse kubectl`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing kubectl")
os.Exit(1)
}
err := unuse.UnuseVersions("kubectl")
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(kubectlCmd)
installCmd.AddCommand(installKubectlCmd)
useCmd.AddCommand(useKubectlCmd)
listCmd.AddCommand(listKubectlCmd)
removeCmd.AddCommand(removeKubectlCmd)
unuseCmd.AddCommand(unuseKubectlCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// kubectlCmd.PersistentFlags().String("foo", "", "A help for foo")
kubectlInstallCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
kubectlInstallCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
kubectlInstallCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// kubectlCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
0707010000000E000081A40000000000000000000000016726190A000009C7000000000000000000000000000000000000001900000000k8senv-1.1.1/cmd/list.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/list"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all installed versions of kubectl, helm or velero",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
//
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("list called")
// },
}
var kubectlListCmd = &cobra.Command{
Use: "list",
Short: "List all installed versions of kubectl",
Long: `List all installed versions of kubectl
Examples:
k8senv kubectl list`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("kubectl")
if err != nil {
os.Exit(1)
}
},
}
var veleroListCmd = &cobra.Command{
Use: "list",
Short: "List all installed versions of velero",
Long: `List all installed versions of velero
Examples:
k8senv velero list`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("velero")
if err != nil {
os.Exit(1)
}
},
}
var helmListCmd = &cobra.Command{
Use: "list",
Short: "List all installed versions of helm",
Long: `List all installed versions of helm
Examples:
k8senv helm list`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("helm")
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(listCmd)
kubectlCmd.AddCommand(kubectlListCmd)
veleroCmd.AddCommand(veleroListCmd)
helmCmd.AddCommand(helmListCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
0707010000000F000081A40000000000000000000000016726190A00000AAB000000000000000000000000000000000000001B00000000k8senv-1.1.1/cmd/remove.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/remove"
"github.com/spf13/cobra"
)
// removeCmd represents the remove command
var removeCmd = &cobra.Command{
Use: "remove",
Short: "Remove a version of kubectl, helm or velero",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
//
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("remove called")
// },
}
var kubectlRemoveCmd = &cobra.Command{
Use: "remove VERSION",
Short: "Remove an installed versions of kubectl",
Long: `Remove an installed versions of kubectl
Examples:
k8senv kubectl remove v1.19.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to remove e.g. v1.20.3")
os.Exit(1)
}
err := remove.RemoveVersion("kubectl", args[0])
if err != nil {
os.Exit(1)
}
},
}
var veleroRemoveCmd = &cobra.Command{
Use: "remove VERSION",
Short: "Remove an installed versions of velero",
Long: `Remove an installed versions of velero
Examples:
k8senv velero remove v1.10.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero version to remove e.g. v1.10.2")
os.Exit(1)
}
err := remove.RemoveVersion("velero", args[0])
if err != nil {
os.Exit(1)
}
},
}
var helmRemoveCmd = &cobra.Command{
Use: "remove VERSION",
Short: "Remove an installed versions of helm",
Long: `Remove an installed versions of helm
Examples:
k8senv helm remove v3.10.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to remove e.g. v3.10.2")
os.Exit(1)
}
err := remove.RemoveVersion("helm", args[0])
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(removeCmd)
kubectlCmd.AddCommand(kubectlRemoveCmd)
veleroCmd.AddCommand(veleroRemoveCmd)
helmCmd.AddCommand(helmRemoveCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// removeCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// removeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000010000081A40000000000000000000000016726190A000005FD000000000000000000000000000000000000001900000000k8senv-1.1.1/cmd/root.go/*
Copyright © 2023 Navratan Lal Gupta <navilg0409@gmail.com>
*/
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "k8senv",
Short: "Kubernetes client's version manager",
Long: `Kubernetes clients supported at this moments are kubectl, or, helm, or, velero on Linux servers/machines.
Manage number of Kubernetes clusters of different versions from same jumpbox or machine or bastion server.
This small tool is to help manage different versions of Kubernetes clients. Kubernetes clients kubectl, helm and velero are supported at this stage.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k8senv.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000011000081A40000000000000000000000016726190A00000AB0000000000000000000000000000000000000001A00000000k8senv-1.1.1/cmd/unuse.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/unuse"
"github.com/spf13/cobra"
)
// unuseCmd represents the unuse command
var unuseCmd = &cobra.Command{
Use: "unuse",
Short: "Stop using k8senv managed kubectl, helm or velero",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
//
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("unuse called")
// },
}
var kubectlUnuseCmd = &cobra.Command{
Use: "unuse",
Short: "Stop using k8senv managed kubectl",
Long: `Stop using k8senv managed kubectl.
This will reset your system to use system installed client of kubectl if present.
Examples:
k8senv kubectl unuse`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing kubectl")
os.Exit(1)
}
err := unuse.UnuseVersions("kubectl")
if err != nil {
os.Exit(1)
}
},
}
var veleroUnuseCmd = &cobra.Command{
Use: "unuse",
Short: "Stop using k8senv managed velero",
Long: `Stop using k8senv managed velero.
This will reset your system to use system installed client of velero if present.
Examples:
k8senv velero unuse`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing velero")
os.Exit(1)
}
err := unuse.UnuseVersions("velero")
if err != nil {
os.Exit(1)
}
},
}
var helmUnuseCmd = &cobra.Command{
Use: "unuse",
Short: "Stop using k8senv managed helm",
Long: `Stop using k8senv managed helm.
This will reset your system to use system installed client of helm if present.
Examples:
k8senv helm unuse`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing helm")
os.Exit(1)
}
err := unuse.UnuseVersions("helm")
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(unuseCmd)
kubectlCmd.AddCommand(kubectlUnuseCmd)
veleroCmd.AddCommand(veleroUnuseCmd)
helmCmd.AddCommand(helmUnuseCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// unuseCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// unuseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000012000081A40000000000000000000000016726190A00000C57000000000000000000000000000000000000001800000000k8senv-1.1.1/cmd/use.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/use"
"github.com/spf13/cobra"
)
// useCmd represents the use command
var useCmd = &cobra.Command{
Use: "use",
Short: "Switch to a version of kubectl, helm or velero",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("use called")
// },
}
var kubectUseCmd = &cobra.Command{
Use: "use VERSION",
Short: "Switch to a version of kubectl client",
Long: `Switch to a version of kubectl client
Examples:
# Switch to kubectl version 1.26.2
k8senv kubectl use v1.26.2
k8senv kubectl use 1.26.2
Supported version formats:
v1.20.3
1.20.3 # Defaults to v1.20.3
1.20 # Defaults to v1.20.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide kubectl version to use e.g. v1.20.3")
os.Exit(1)
}
err := use.UseVersion("kubectl", args[0])
if err != nil {
os.Exit(1)
}
},
}
var veleroUseCmd = &cobra.Command{
Use: "use VERSION",
Short: "Switch to a version of velero client",
Long: `Switch to a version of velero client
Examples:
# Switch to velero version 1.10.2
k8senv velero use v1.10.2
k8senv velero use 1.10.2
Supported version formats:
v1.10.2
1.10.2 # Defaults to v1.10.2
1.10 # Defaults to v1.10.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero version to use e.g. v1.10.2")
os.Exit(1)
}
err := use.UseVersion("velero", args[0])
if err != nil {
os.Exit(1)
}
},
}
var helmUseCmd = &cobra.Command{
Use: "use VERSION",
Short: "Switch to a version of helm",
Long: `Switch to a version of helm
Examples:
# Switch to helm version 3.10.2
k8senv use helm v3.10.2
k8senv use helm 3.10.2
Supported version formats:
v3.10.2
3.10.2 # Defaults to v3.10.2
3.10 # Defaults to v3.10.0
3 # Defaults to v3.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide helm version to use e.g. v3.10.2")
os.Exit(1)
}
err := use.UseVersion("helm", args[0])
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(useCmd)
kubectlCmd.AddCommand(kubectUseCmd)
veleroCmd.AddCommand(veleroUseCmd)
helmCmd.AddCommand(helmUseCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// useCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// useCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000013000081A40000000000000000000000016726190A000013B9000000000000000000000000000000000000001B00000000k8senv-1.1.1/cmd/velero.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/navilg/k8senv/internal/install"
"github.com/navilg/k8senv/internal/list"
"github.com/navilg/k8senv/internal/remove"
"github.com/navilg/k8senv/internal/unuse"
"github.com/navilg/k8senv/internal/use"
"github.com/spf13/cobra"
)
// veleroCmd represents the velero command
var veleroCmd = &cobra.Command{
Use: "velero",
Short: "Install, Use or List versions of velero client",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("velero called")
// },
}
var installVeleroCmd = &cobra.Command{
Use: "velero VERSION",
Short: "Install a version of velero client",
Long: `Install a version of velero client
Examples:
# Install velero client version 1.10.2
k8senv install velero v1.10.2
# Install latest available stable version of velero client
k8senv install velero latest
# Install velero client version 1.8.0 and overwrite it if it already exists
k8senv install velero 1.8.0 --overwrite
# Install velero client version 1.8.0 aand set timeout to 300 seconds (If internet is slow), Default: 120 seconds
k8senv install velero 1.8.0 --timeout=300
Supported version formats:
v1.10.2
1.10.2 # Defaults to v1.10.2
1.10 # Defaults to v1.10.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero client version to install e.g. v1.10.2")
os.Exit(1)
}
err := install.InstallVersion("velero", args[0], overwriteInstall, timeout, proxy)
if err != nil {
os.Exit(1)
}
},
}
var useVeleroCmd = &cobra.Command{
Use: "velero VERSION",
Short: "Switch to a version of velero client",
Long: `Switch to a version of velero client
Examples:
# Switch to velero version 1.10.2
k8senv use velero v1.10.2
k8senv use velero 1.10.2
Supported version formats:
v1.10.2
1.10.2 # Defaults to v1.10.2
1.10 # Defaults to v1.10.0
1 # Defaults to v1.0.0`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero client version to use e.g. v1.10.2")
os.Exit(1)
}
err := use.UseVersion("velero", args[0])
if err != nil {
os.Exit(1)
}
},
}
var listVeleroCmd = &cobra.Command{
Use: "velero",
Short: "List all installed versions of velero client",
Long: `List all installed versions of velero client
Examples:
k8senv list velero`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for listing versions")
os.Exit(1)
}
err := list.ListVersions("velero")
if err != nil {
os.Exit(1)
}
},
}
var removeVeleroCmd = &cobra.Command{
Use: "velero VERSION",
Short: "Remove an installed versions of velero client",
Long: `Remove an installed versions of velero client
Examples:
k8senv remove velero v1.10.2`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Exactly one argumanet is required. Provide velero client version to remove e.g. v1.10.2")
os.Exit(1)
}
err := remove.RemoveVersion("velero", args[0])
if err != nil {
os.Exit(1)
}
},
}
var unuseVeleroCmd = &cobra.Command{
Use: "velero",
Short: "Stop using k8senv managed velero",
Long: `Stop using k8senv managed velero.
This will reset your system to use system installed client of velero if present.
Examples:
k8senv unuse velero`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Println("No argument is required for unusing velero")
os.Exit(1)
}
err := unuse.UnuseVersions("velero")
if err != nil {
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(veleroCmd)
installCmd.AddCommand(installVeleroCmd)
useCmd.AddCommand(useVeleroCmd)
listCmd.AddCommand(listVeleroCmd)
removeCmd.AddCommand(removeVeleroCmd)
unuseCmd.AddCommand(unuseVeleroCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// veleroCmd.PersistentFlags().String("foo", "", "A help for foo")
veleroInstallCmd.PersistentFlags().BoolVarP(&overwriteInstall, "overwrite", "f", false, "Overwrite or re-install existing version")
veleroInstallCmd.PersistentFlags().IntVarP(&timeout, "timeout", "t", 120, "Timeout in seconds [DEFAULT: 120 seconds]")
veleroInstallCmd.PersistentFlags().StringVarP(&proxy, "proxy", "p", "", "HTTP/HTTPS proxy to use for downloading clients from its source")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// veleroCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000014000081A40000000000000000000000016726190A000004F9000000000000000000000000000000000000001C00000000k8senv-1.1.1/cmd/version.go/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"encoding/json"
"fmt"
"os"
"github.com/navilg/k8senv/internal/config"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version of K8senv",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
data, err := json.Marshal(config.Version)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("VersionInfo", string(data))
},
}
func init() {
rootCmd.AddCommand(versionCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
07070100000015000081ED0000000000000000000000016726190A0000027D000000000000000000000000000000000000002600000000k8senv-1.1.1/container_image_build.sh#!/usr/bin/env bash
# Docker image
version=$(go run main.go version | cut -d " " -f 2 | jq .K8senv | tr -d "\"")
docker buildx create --name dockerxbuilder --use --bootstrap
if [ "$1" == "push" ]; then
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv:$version .
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv .
else
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv:$version .
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv .
fi
07070100000016000081A40000000000000000000000016726190A00000865000000000000000000000000000000000000001400000000k8senv-1.1.1/go.modmodule github.com/navilg/k8senv
go 1.23
require (
github.com/spf13/cobra v1.8.1
k8s.io/apimachinery v0.31.2
k8s.io/client-go v0.31.2
)
require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // 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.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // 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/onsi/gomega v1.33.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/protobuf v1.34.2 // 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.31.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
07070100000017000081A40000000000000000000000016726190A00003940000000000000000000000000000000000000001400000000k8senv-1.1.1/go.sumgithub.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-openapi/jsonpointer v0.19.6 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/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
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.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
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-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 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.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
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/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.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.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/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-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.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
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=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/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/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
07070100000018000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001600000000k8senv-1.1.1/internal07070100000019000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001F00000000k8senv-1.1.1/internal/checksum0707010000001A000081A40000000000000000000000016726190A000001CE000000000000000000000000000000000000002B00000000k8senv-1.1.1/internal/checksum/checksum.gopackage checksum
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io/ioutil"
)
func ValidateSHA256Sum(checksum string, filename string) bool {
data, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("Failed to read file")
fmt.Println(err)
return false
}
sha256sum := sha256.Sum256(data)
bytesha256sum := sha256sum[:]
fileChecksum := hex.EncodeToString(bytesha256sum)
if fileChecksum != checksum {
return false
}
return true
}
0707010000001B000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001D00000000k8senv-1.1.1/internal/config0707010000001C000081A40000000000000000000000016726190A00000355000000000000000000000000000000000000002700000000k8senv-1.1.1/internal/config/config.gopackage config
import (
"os"
"runtime"
"strings"
)
var version string = "v1.1.1"
var gitCommit string = "###GitCommitPlaceholder###"
func getGitCommit() string {
if gitCommit == "###GitCommitPlaceholder###" || gitCommit == "" {
return "NA"
}
return gitCommit
}
type VersionInfo struct {
GoVersion string `json:"GoVersion"`
K8senv string `json:"K8senv"`
OS string `json:"OS"`
Arch string `json:"ARCH"`
GitCommit string `json:"GitCommit"`
}
var Version = VersionInfo{
GoVersion: runtime.Version(),
K8senv: version,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GitCommit: getGitCommit(),
}
func GetDotK8senvPath() *string {
pathenv := os.Getenv("PATH")
paths := strings.Split(pathenv, ":")
for _, path := range paths {
if strings.Contains(path, ".k8senv/bin") {
return &path
}
}
return nil
}
0707010000001D000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001F00000000k8senv-1.1.1/internal/download0707010000001E000081A40000000000000000000000016726190A000003D7000000000000000000000000000000000000002B00000000k8senv-1.1.1/internal/download/download.gopackage download
import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"time"
)
func Download(downloadurl string, timeout time.Duration, proxy string) ([]byte, error) {
client := http.Client{
Timeout: timeout * time.Second,
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}
if proxy != "" {
proxy, err := url.Parse(proxy)
if err != nil {
fmt.Println("Download failed")
fmt.Println(err)
return nil, err
}
client.Transport = &http.Transport{Proxy: http.ProxyURL(proxy)}
}
resp, err := client.Get(downloadurl)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode/100 != 2 {
fmt.Println("Download failed")
fmt.Println(resp.Status)
return nil, errors.New(resp.Status)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Failed to read received response")
fmt.Println(err)
return nil, err
}
return data, nil
}
0707010000001F000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000002200000000k8senv-1.1.1/internal/ikubernetes07070100000020000081A40000000000000000000000016726190A00000AE6000000000000000000000000000000000000002D00000000k8senv-1.1.1/internal/ikubernetes/version.gopackage ikubernetes
import (
"context"
"errors"
"os"
"path/filepath"
"regexp"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func GetK8sVersion() (*string, error) {
var kubeconfig *rest.Config
homeDir, _ := os.UserHomeDir()
var err error = nil
if kubeconfigEnv := os.Getenv("KUBECONFIG"); kubeconfigEnv != "" {
kubeconfig, err = clientcmd.BuildConfigFromFlags("", kubeconfigEnv)
if err != nil {
return nil, err
}
} else if _, err := os.Stat(filepath.Join(homeDir, ".kube", "config")); err == nil {
kubeconfig, err = clientcmd.BuildConfigFromFlags("", filepath.Join(homeDir, ".kube", "config"))
if err != nil {
return nil, err
}
} else {
return nil, errors.New("KUBECONFIG file not found")
}
clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
return nil, err
}
k8sVersion, err := clientset.ServerVersion()
if err != nil {
return nil, err
}
k8sSemversionSplit := strings.Split(k8sVersion.String(), ".")
re := regexp.MustCompile(`[^0-9]`)
result := re.ReplaceAllString(k8sSemversionSplit[2], "/")
resultSplit := strings.Split(result, "/")
k8sSemversionPatch := resultSplit[0]
k8sSemversion := k8sSemversionSplit[0] + "." + k8sSemversionSplit[1] + "." + k8sSemversionPatch
return &k8sSemversion, nil
}
func GetVeleroVersion() (*string, error) {
var kubeconfig *rest.Config
homeDir, _ := os.UserHomeDir()
var err error = nil
if kubeconfigEnv := os.Getenv("KUBECONFIG"); kubeconfigEnv != "" {
kubeconfig, err = clientcmd.BuildConfigFromFlags("", kubeconfigEnv)
if err != nil {
return nil, err
}
} else if _, err := os.Stat(filepath.Join(homeDir, ".kube", "config")); err == nil {
kubeconfig, err = clientcmd.BuildConfigFromFlags("", filepath.Join(homeDir, ".kube", "config"))
if err != nil {
return nil, err
}
} else {
return nil, errors.New("KUBECONFIG file not found")
}
clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
return nil, err
}
namespace := "velero"
deploymentName := "velero"
deployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
if err != nil {
return nil, errors.New("error retrieving velero deployment from velero namespace")
}
veleroImageName := deployment.Spec.Template.Spec.Containers[0].Image
veleroVersion := strings.Split(veleroImageName, ":")[1]
semVersionRegex := regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$`)
if !semVersionRegex.MatchString(veleroVersion) {
return nil, errors.New("velero image used in velero deployment is not semantic version: " + veleroVersion)
}
return &veleroVersion, nil
}
07070100000021000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001E00000000k8senv-1.1.1/internal/install07070100000022000081A40000000000000000000000016726190A00003C69000000000000000000000000000000000000002900000000k8senv-1.1.1/internal/install/install.gopackage install
import (
"archive/tar"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/navilg/k8senv/internal/checksum"
"github.com/navilg/k8senv/internal/config"
"github.com/navilg/k8senv/internal/download"
"github.com/navilg/k8senv/internal/ikubernetes"
)
func InstallVersion(toolname, version string, overwrite bool, timeout int, proxy string) error {
if toolname == "kubectl" {
err := InstallKubectl(version, overwrite, timeout, proxy)
if err != nil {
return err
}
} else if toolname == "velero" {
err := InstallVelero(version, overwrite, timeout, proxy)
if err != nil {
return err
}
} else if toolname == "helm" {
err := InstallHelm(version, overwrite, timeout, proxy)
if err != nil {
return err
}
} else {
fmt.Println(toolname, "is not a valid tool supported by k8senv.")
return errors.New(toolname + " is not a valid tool supported by k8senv.")
}
return nil
}
func InstallKubectl(version string, overwrite bool, timeout int, proxy string) error {
latestVersionUrl := "https://storage.googleapis.com/kubernetes-release/release/stable.txt"
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
if version == "latest" {
// version value is latest
fmt.Println("Fetching latest stable version")
data, err := download.Download(latestVersionUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to fetch latest kubectl version")
return err
}
version = string(data)
fmt.Println("Latest available stable version of kubectl is", version)
}
if version == "auto" {
fmt.Println("Fetching Kubernetes server version")
k8sVersion, err := ikubernetes.GetK8sVersion()
if err != nil {
fmt.Println("Error getting Kubernetes server version. Error:", err.Error())
return err
}
version = *k8sVersion
fmt.Println("Kubernetes server version is", version)
}
major_minor_patch_vers := strings.Split(version, ".")
if !strings.HasPrefix(major_minor_patch_vers[0], "v") {
version = "v" + version
}
if len(major_minor_patch_vers) == 2 {
version = version + ".0"
} else if len(major_minor_patch_vers) == 1 {
version = version + ".0.0"
}
goos := config.Version.OS
goarch := config.Version.Arch
downloadUrl := "https://dl.k8s.io/release/" + version + "/bin/" + goos + "/" + goarch + "/kubectl"
checksumUrl := "https://dl.k8s.io/" + version + "/bin/" + goos + "/" + goarch + "/kubectl.sha256"
binaryFileName := *dotK8sEnvPath + "/kubectl." + version
if _, err := os.Stat(binaryFileName); err == nil && !overwrite {
fmt.Println("kubectl version", version, "is already installed. Use command `k8senv use kubectl", version+"` to use it.")
fmt.Println("If existing client doesnot work properly or is corrupted, Use --overwrite flag to overwrite/re-install the existing one.")
return nil
}
fmt.Println("Downloading kubectl version", version)
fmt.Println("Download in progress... It may take time depending on internet speed. Default timeout:", timeout, "seconds.")
data, err := download.Download(downloadUrl, time.Duration(timeout), proxy)
if err != nil {
fmt.Println("Failed to install kubectl version", version)
return err
}
err = ioutil.WriteFile(binaryFileName, data, 0750)
if err != nil {
fmt.Println("Failed to install kubectl version", version)
fmt.Println(err)
return err
}
fmt.Println("Downloaded kubectl version", version)
fmt.Println("Validating checksum")
checksumdata, err := download.Download(checksumUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to validate checksum")
return err
}
if isValid := checksum.ValidateSHA256Sum(strings.TrimSuffix(string(checksumdata), "\n"), binaryFileName); isValid {
fmt.Println("Checksum validated.")
} else {
fmt.Println("Failed to validate checksum. Deleting the installed client.")
_ = os.Remove(binaryFileName)
return errors.New("Failed to validate checksum of installed file")
}
return nil
}
func InstallVelero(version string, overwrite bool, timeout int, proxy string) error {
latestVersionUrl := "https://api.github.com/repos/vmware-tanzu/velero/releases/latest"
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
if version == "latest" {
// version value is latest
fmt.Println("Fetching latest stable version")
data, err := download.Download(latestVersionUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to fetch latest velero client version")
return err
}
type latestVeleroVersionInfo struct {
TagName string `json:"tag_name"`
}
var latestVeleroVersion latestVeleroVersionInfo
err = json.Unmarshal(data, &latestVeleroVersion)
if err != nil {
fmt.Println("Failed to fetch latest velero client version")
return err
}
version = string(latestVeleroVersion.TagName)
fmt.Println("Latest available stable version of velero client is", version)
}
if version == "auto" {
fmt.Println("Fetching Velero server version")
veleroVersion, err := ikubernetes.GetVeleroVersion()
if err != nil {
fmt.Println("Error getting Velero server version")
return err
}
version = *veleroVersion
fmt.Println("Velero server version is", version)
}
major_minor_patch_vers := strings.Split(version, ".")
if !strings.HasPrefix(major_minor_patch_vers[0], "v") {
version = "v" + version
}
if len(major_minor_patch_vers) == 2 {
version = version + ".0"
} else if len(major_minor_patch_vers) == 1 {
version = version + ".0.0"
}
fullVersion := version + "-" + config.Version.OS + "-" + config.Version.Arch
downloadUrl := "https://github.com/vmware-tanzu/velero/releases/download/" + version + "/velero-" + fullVersion + ".tar.gz"
checksumUrl := "https://github.com/vmware-tanzu/velero/releases/download/" + version + "/CHECKSUM"
binaryFileName := *dotK8sEnvPath + "/velero." + version
if _, err := os.Stat(binaryFileName); err == nil && !overwrite {
fmt.Println("velero client version", version, "is already installed. Use command `k8senv use velero", version+"` to use it.")
fmt.Println("If existing client doesnot work properly or is corrupted, Use --overwrite flag to overwrite/re-install the existing one.")
return nil
}
fmt.Println("Downloading velero package version", version)
tempDir, err := ioutil.TempDir("/tmp", "velero"+version+"*")
if err != nil {
fmt.Println("Failed to create temporary directory")
fmt.Println(err)
}
fmt.Println("Download in progress... It may take time depending on internet speed. Default timeout:", timeout, "seconds.")
data, err := download.Download(downloadUrl, time.Duration(timeout), proxy)
if err != nil {
fmt.Println("Failed to install velero client version", version)
return err
}
err = ioutil.WriteFile(tempDir+"/velero-"+fullVersion+".tar.gz", data, 0750)
if err != nil {
fmt.Println("Failed to install velero client version", version)
fmt.Println(err)
return err
}
fmt.Println("Installation package downloaded for velero client version", version)
fmt.Println("Validating checksum")
checksumdata, err := download.Download(checksumUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to validate checksum")
return err
}
var isChecksumValidated bool = false
for _, line := range strings.Split(string(checksumdata), "\n") {
words := strings.Fields(line)
if len(words) < 2 {
continue
}
if words[1] == "velero-"+fullVersion+".tar.gz" {
if checksum.ValidateSHA256Sum(strings.TrimSuffix(string(words[0]), "\n"), tempDir+"/velero-"+fullVersion+".tar.gz") {
isChecksumValidated = true
}
break
}
}
if isChecksumValidated {
fmt.Println("Checksum validated.")
} else {
fmt.Println("Failed to validate checksum. Deleting the downloaded package.")
_ = os.Remove(tempDir + "/velero-" + fullVersion + ".tar.gz")
return errors.New("Failed to validate checksum of downloaded file")
}
// Gun-Unzipping
fmt.Println("Unzipping the package")
reader, err := os.Open(tempDir + "/velero-" + fullVersion + ".tar.gz")
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer reader.Close()
archive, err := gzip.NewReader(reader)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer archive.Close()
target := filepath.Join(tempDir+"/velero-"+fullVersion+".tar", archive.Name)
writer, err := os.Create(target)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer writer.Close()
_, err = io.Copy(writer, archive)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
// Untaring file
fmt.Println("Getting the velero client")
reader, err = os.Open(tempDir + "/velero-" + fullVersion + ".tar")
if err != nil {
fmt.Println(err)
return err
}
defer reader.Close()
tarReader := tar.NewReader(reader)
for {
header, err := tarReader.Next()
if err == io.EOF {
fmt.Println("Failed to get velero client")
fmt.Println("Binary file not present in package")
break
} else if err != nil {
fmt.Println("Failed to get velero client")
fmt.Println(err)
return err
}
if header.FileInfo().IsDir() {
continue
}
if filepath.Base(header.Name) != "velero" {
continue
}
file, err := os.OpenFile(binaryFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0750)
if err != nil {
fmt.Println("Failed to install velero client")
fmt.Println(err)
return err
}
defer file.Close()
_, err = io.Copy(file, tarReader)
if err != nil {
fmt.Println("Failed to install velero client")
fmt.Println(err)
return err
}
break
}
fmt.Println("Installed velero client version", version)
return nil
}
func InstallHelm(version string, overwrite bool, timeout int, proxy string) error {
latestVersionUrl := "https://api.github.com/repos/helm/helm/releases/latest"
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
if version == "latest" {
// version value is latest
fmt.Println("Fetching latest stable version")
data, err := download.Download(latestVersionUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to fetch latest helm version")
return err
}
type latestHelmVersionInfo struct {
TagName string `json:"tag_name"`
}
var latestHelmVersion latestHelmVersionInfo
err = json.Unmarshal(data, &latestHelmVersion)
if err != nil {
fmt.Println("Failed to fetch latest helm version")
return err
}
version = string(latestHelmVersion.TagName)
fmt.Println("Latest available stable version of helm is", version)
}
major_minor_patch_vers := strings.Split(version, ".")
if !strings.HasPrefix(major_minor_patch_vers[0], "v") {
version = "v" + version
}
if len(major_minor_patch_vers) == 2 {
version = version + ".0"
} else if len(major_minor_patch_vers) == 1 {
version = version + ".0.0"
}
fullVersion := version + "-" + config.Version.OS + "-" + config.Version.Arch // Full version vM.m.p-os-arch e.g. v1.10.2-linux-amd64
downloadUrl := "https://get.helm.sh/helm-" + fullVersion + ".tar.gz"
checksumUrl := "https://get.helm.sh/helm-" + fullVersion + ".tar.gz.sha256sum"
binaryFileName := *dotK8sEnvPath + "/helm." + version
if _, err := os.Stat(binaryFileName); err == nil && !overwrite {
fmt.Println("helm version", version, "is already installed. Use command `k8senv use helm", version+"` to use it.")
fmt.Println("If existing client doesnot work properly or is corrupted, Use --overwrite flag to overwrite/re-install the existing one.")
return nil
}
fmt.Println("Downloading helm package version", version)
tempDir, err := ioutil.TempDir("/tmp", "helm"+version+"*")
if err != nil {
fmt.Println("Failed to create temporary directory")
fmt.Println(err)
}
fmt.Println("Download in progress... It may take time depending on internet speed. Default timeout:", timeout, "seconds.")
data, err := download.Download(downloadUrl, time.Duration(timeout), proxy)
if err != nil {
fmt.Println("Failed to install helm version", version)
return err
}
err = ioutil.WriteFile(tempDir+"/helm-"+fullVersion+".tar.gz", data, 0750)
if err != nil {
fmt.Println("Failed to install helm version", version)
fmt.Println(err)
return err
}
fmt.Println("Installation package downloaded for helm version", version)
fmt.Println("Validating checksum")
checksumdata, err := download.Download(checksumUrl, 30, proxy)
if err != nil {
fmt.Println("Failed to validate checksum")
return err
}
var isChecksumValidated bool = false
for _, line := range strings.Split(string(checksumdata), "\n") {
words := strings.Fields(line)
if len(words) < 2 {
continue
}
if words[1] == "helm-"+fullVersion+".tar.gz" {
if checksum.ValidateSHA256Sum(strings.TrimSuffix(string(words[0]), "\n"), tempDir+"/helm-"+fullVersion+".tar.gz") {
isChecksumValidated = true
}
break
}
}
if isChecksumValidated {
fmt.Println("Checksum validated.")
} else {
fmt.Println("Failed to validate checksum. Deleting the downloaded package.")
_ = os.Remove(tempDir + "/helm-" + fullVersion + ".tar.gz")
return errors.New("Failed to validate checksum of downloaded file")
}
// Gun-Unzipping
fmt.Println("Unzipping the package")
reader, err := os.Open(tempDir + "/helm-" + fullVersion + ".tar.gz")
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer reader.Close()
archive, err := gzip.NewReader(reader)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer archive.Close()
target := filepath.Join(tempDir+"/helm-"+fullVersion+".tar", archive.Name)
writer, err := os.Create(target)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
defer writer.Close()
_, err = io.Copy(writer, archive)
if err != nil {
fmt.Println("Failed to unzip the package")
fmt.Println(err)
return err
}
// Untaring file
fmt.Println("Getting the helm")
reader, err = os.Open(tempDir + "/helm-" + fullVersion + ".tar")
if err != nil {
fmt.Println(err)
return err
}
defer reader.Close()
tarReader := tar.NewReader(reader)
for {
header, err := tarReader.Next()
if err == io.EOF {
fmt.Println("Failed to get helm")
fmt.Println("Binary file not present in package")
break
} else if err != nil {
fmt.Println("Failed to get helm")
fmt.Println(err)
return err
}
if header.FileInfo().IsDir() {
continue
}
if filepath.Base(header.Name) != "helm" {
continue
}
file, err := os.OpenFile(binaryFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0750)
if err != nil {
fmt.Println("Failed to install helm")
fmt.Println(err)
return err
}
defer file.Close()
_, err = io.Copy(file, tarReader)
if err != nil {
fmt.Println("Failed to install helm")
fmt.Println(err)
return err
}
break
}
fmt.Println("Installed helm version", version)
return nil
}
07070100000023000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001B00000000k8senv-1.1.1/internal/list07070100000024000081A40000000000000000000000016726190A00000562000000000000000000000000000000000000002300000000k8senv-1.1.1/internal/list/list.gopackage list
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/navilg/k8senv/internal/config"
)
func ListVersions(toolname string) error {
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
fileinfo, err := ioutil.ReadDir(*dotK8sEnvPath)
if err != nil {
fmt.Println("Failed to list installed versions")
fmt.Println(err)
return (err)
}
binaryPath := *dotK8sEnvPath + "/" + toolname
var versionInUse string
if _, err := os.Lstat(binaryPath); err == nil {
currentToolPathInUse, err := os.Readlink(binaryPath)
if err != nil {
fmt.Println("Failed to list installed versions")
fmt.Println(err)
return (err)
}
versionInUse = strings.TrimPrefix(filepath.Base(currentToolPathInUse), toolname+".")
}
count := 0
for _, file := range fileinfo {
if !file.IsDir() {
if strings.HasPrefix(file.Name(), toolname+".") {
version := strings.TrimPrefix(file.Name(), toolname+".")
if versionInUse == version {
fmt.Println("*", version)
} else {
fmt.Println(" ", version)
}
count = count + 1
}
}
}
if count == 0 {
fmt.Println("No version of", toolname, "is installed by k8senv.")
}
return nil
}
07070100000025000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001D00000000k8senv-1.1.1/internal/remove07070100000026000081A40000000000000000000000016726190A0000064D000000000000000000000000000000000000002700000000k8senv-1.1.1/internal/remove/remove.gopackage remove
import (
"errors"
"fmt"
"os"
"strings"
"github.com/navilg/k8senv/internal/config"
)
func RemoveVersion(toolname, version string) error {
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
major_minor_patch_vers := strings.Split(version, ".")
if !strings.HasPrefix(major_minor_patch_vers[0], "v") {
version = "v" + version
}
if len(major_minor_patch_vers) == 2 {
version = version + ".0"
} else if len(major_minor_patch_vers) == 1 {
version = version + ".0.0"
}
binaryFileName := *dotK8sEnvPath + "/" + toolname + "." + version
binaryPath := *dotK8sEnvPath + "/" + toolname
if _, err := os.Stat(binaryFileName); os.IsNotExist(err) {
fmt.Println(toolname, "version", version, "is not installed.")
return nil
}
if _, err := os.Lstat(binaryPath); err == nil {
currentPathInUse, err := os.Readlink(binaryPath)
if err != nil {
fmt.Println("Failed to unset", toolname, "version", version, "as default")
fmt.Println(err)
}
if currentPathInUse == binaryFileName {
err = os.Remove(binaryPath)
if err != nil {
fmt.Println("Failed to unset", toolname, "version", version, "as default")
fmt.Println("Due to,", err)
}
}
}
err := os.Remove(binaryFileName)
if err != nil {
fmt.Println("Failed to", toolname, "version", version)
fmt.Println("Due to,", err)
return err
}
fmt.Println("Successfully removed", toolname, "version", version)
return nil
}
07070100000027000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001C00000000k8senv-1.1.1/internal/unuse07070100000028000081A40000000000000000000000016726190A00000361000000000000000000000000000000000000002500000000k8senv-1.1.1/internal/unuse/unuse.gopackage unuse
import (
"errors"
"fmt"
"os"
"runtime"
"github.com/navilg/k8senv/internal/config"
)
func UnuseVersions(toolname string) error {
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
binaryPath := *dotK8sEnvPath + "/" + toolname
if _, err := os.Lstat(binaryPath); err == nil {
err = os.Remove(binaryPath)
if err != nil {
fmt.Println("Failed to unuse", toolname)
fmt.Println("Due to,", err)
return err
}
fmt.Println(toolname, "successfully set to unuse.")
if runtime.GOOS == "linux" {
fmt.Println("Bash shell caches the program location. You might need to run 'hash -d " + toolname + "' to clear it for this to work.")
}
}
return nil
}
07070100000029000041ED0000000000000000000000026726190A00000000000000000000000000000000000000000000001A00000000k8senv-1.1.1/internal/use0707010000002A000081A40000000000000000000000016726190A000008E0000000000000000000000000000000000000002100000000k8senv-1.1.1/internal/use/use.gopackage use
import (
"errors"
"fmt"
"os"
"runtime"
"strings"
"github.com/navilg/k8senv/internal/config"
"github.com/navilg/k8senv/internal/ikubernetes"
"github.com/navilg/k8senv/internal/install"
)
func UseVersion(toolname, version string) error {
dotK8sEnvPath := config.GetDotK8senvPath()
if dotK8sEnvPath == nil {
fmt.Println(".k8senv/bin directory is not added in PATH environment variable")
return errors.New(".k8senv/bin is not added in PATH environment variable")
}
if toolname == "kubectl" && version == "auto" {
fmt.Println("Fetching Kubernetes server version")
k8sVersion, err := ikubernetes.GetK8sVersion()
if err != nil {
fmt.Println("Error getting Kubernetes server version. Error:", err.Error())
return err
}
version = *k8sVersion
fmt.Println("Kubernetes server version is", version)
}
if toolname == "velero" && version == "auto" {
fmt.Println("Fetching Velero server version")
veleroVersion, err := ikubernetes.GetVeleroVersion()
if err != nil {
fmt.Println("Error getting Velero server version")
return err
}
version = *veleroVersion
fmt.Println("Velero server version is", version)
}
major_minor_patch_vers := strings.Split(version, ".")
if !strings.HasPrefix(major_minor_patch_vers[0], "v") {
version = "v" + version
}
if len(major_minor_patch_vers) == 2 {
version = version + ".0"
} else if len(major_minor_patch_vers) == 1 {
version = version + ".0.0"
}
binaryFileName := *dotK8sEnvPath + "/" + toolname + "." + version
binaryPath := *dotK8sEnvPath + "/" + toolname
if _, err := os.Stat(binaryFileName); os.IsNotExist(err) {
fmt.Println(toolname, "version", version, "is not installed.")
fmt.Println("Installing")
install.InstallVersion(toolname, version, false, 120, "")
}
if _, err := os.Lstat(binaryPath); err == nil {
os.Remove(binaryPath)
}
err := os.Symlink(binaryFileName, binaryPath)
if err != nil {
fmt.Println("Failed to setup", toolname, version, "as default.")
fmt.Println(err)
return (err)
}
fmt.Println("Using", toolname, version, "as default.")
if runtime.GOOS == "linux" {
fmt.Println("Bash shell caches the program location. You might need to run 'hash -d " + toolname + "' to clear it for this to work.")
}
return nil
}
0707010000002B000081A40000000000000000000000016726190A00000096000000000000000000000000000000000000001500000000k8senv-1.1.1/main.go/*
Copyright © 2023 Navratan Lal Gupta <navilg0409@gmail.com>
*/
package main
import "github.com/navilg/k8senv/cmd"
func main() {
cmd.Execute()
}
0707010000002C000081ED0000000000000000000000016726190A00000B56000000000000000000000000000000000000001500000000k8senv-1.1.1/test.sh#!/usr/bin/env bash
set -e
# Build
bash build.sh
chmod +x ./k8senv-linux-amd64
echo
mkdir -p $HOME/.k8senv/bin
export PATH=$HOME/.k8senv/bin:$PATH
cp -f ./k8senv-linux-amd64 $HOME/.k8senv/bin/k8senv
echo "Testing 'k8senv version'"
k8senv version
echo "✅"
echo
# Test kubectl
echo "Testing 'k8senv install kubectl'"
k8senv install kubectl v1.29.1 --timeout 300 --overwrite
echo "Testing 'k8senv kubectl install'"
k8senv kubectl install 1.30.0 --timeout 300 --overwrite
echo "✅"
echo
echo "Testing 'k8senv use kubectl'"
k8senv use kubectl v1.29.1
kubectl version --client
echo "Testing 'k8senv kubectl use'"
k8senv kubectl use 1.30.0
kubectl version --client
echo "✅"
echo
echo "Testing 'k8senv kubectl list'"
k8senv kubectl list
echo "Testing 'k8senv list kubectl'"
k8senv list kubectl
echo "✅"
echo
echo "Testing 'k8senv kubectl unuse'"
k8senv kubectl unuse
k8senv list kubectl
echo "Testing 'k8senv unuse kubectl'"
k8senv unuse kubectl
k8senv list kubectl
echo "✅"
echo
echo "Testing 'k8senv kubectl remove'"
k8senv kubectl remove v1.30.0
k8senv list kubectl
echo "Testing 'k8senv remove kubectl'"
k8senv remove kubectl 1.29.1
k8senv list kubectl
echo "✅"
echo
# Test velero
echo "Testing 'k8senv install velero'"
k8senv install velero v1.14.1 --timeout 300 --overwrite
echo "Testing 'k8senv velero install'"
k8senv velero install 1.12.3 --timeout 300 --overwrite
echo "✅"
echo
echo "Testing 'k8senv use velero'"
k8senv use velero v1.14.1
velero version --client-only
echo "Testing 'k8senv velero use'"
k8senv velero use 1.12.3
velero version --client-only
echo "✅"
echo
echo "Testing 'k8senv velero list'"
k8senv velero list
echo "Testing 'k8senv list velero'"
k8senv list velero
echo "✅"
echo
echo "Testing 'k8senv velero unuse'"
k8senv velero unuse
k8senv list velero
echo "Testing 'k8senv unuse velero'"
k8senv unuse velero
k8senv list velero
echo "✅"
echo
echo "Testing 'k8senv velero remove'"
k8senv velero remove v1.12.3
k8senv list velero
echo "Testing 'k8senv remove velero'"
k8senv remove velero 1.14.1
k8senv list velero
echo "✅"
echo
# Test helm
echo "Testing 'k8senv install helm'"
k8senv install helm v3.10.2 --timeout 300 --overwrite
echo "Testing 'k8senv helm install'"
k8senv helm install 3.8.1 --timeout 300 --overwrite
echo "✅"
echo
echo "Testing 'k8senv use helm'"
k8senv use helm v3.8.1
helm version
echo "Testing 'k8senv helm use'"
k8senv helm use 3.10.2
helm version
echo "✅"
echo
echo "Testing 'k8senv helm list'"
k8senv helm list
echo "Testing 'k8senv list helm'"
k8senv list helm
echo "✅"
echo
echo "Testing 'k8senv helm unuse'"
k8senv helm unuse
k8senv list helm
echo "Testing 'k8senv unuse helm'"
k8senv unuse helm
k8senv list helm
echo "✅"
echo
echo "Testing 'k8senv helm remove'"
k8senv helm remove v3.10.2
k8senv list helm
echo "Testing 'k8senv remove helm'"
k8senv remove helm 3.8.1
k8senv list helm
echo "✅"
echo07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!201 blocks