From 36b751dc3c68742369b8cdad90e513d79da3a83c Mon Sep 17 00:00:00 2001 From: Michael Paesold Date: Fri, 8 Jan 2021 15:53:39 +0100 Subject: [PATCH] Added kubectx installer See https://github.com/ahmetb/kubectx Implementation for #173 Collaborative work of Nico Kerschbaumer and me --- kubectx/README.md | 38 +++++++++++++++++++++++++++++ kubectx/install.ps1 | 58 +++++++++++++++++++++++++++++++++++++++++++++ kubectx/install.sh | 36 ++++++++++++++++++++++++++++ kubectx/releases.js | 28 ++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 kubectx/README.md create mode 100644 kubectx/install.ps1 create mode 100644 kubectx/install.sh create mode 100644 kubectx/releases.js diff --git a/kubectx/README.md b/kubectx/README.md new file mode 100644 index 0000000..2b40f83 --- /dev/null +++ b/kubectx/README.md @@ -0,0 +1,38 @@ +--- +title: Kubectx +homepage: https://github.com/ahmetb/kubectx +tagline: | + kubectx: kubectx is a utility to manage and switch between kubectl contexts. +--- + +### Updating `kubectx` + +`webi kubectx@stable` + +Use the `@beta` tag for pre-releases. + +## Cheat Sheet + +> `kubectx` kubectx helps you switch between Kubernetes clusters back and forth + +To run kubectx: + +```bash +kubectx +``` + +### Command line arguments + +```bash +USAGE: + kubectx : list the contexts + kubectx : switch to context + kubectx - : switch to the previous context + kubectx -c, --current : show the current context name + kubectx = : rename context to + kubectx =. : rename current-context to + kubectx -d : delete context ('.' for current-context) + (this command won't delete the user/cluster entry + that is used by the context) + kubectx -u, --unset : unset the current context +``` diff --git a/kubectx/install.ps1 b/kubectx/install.ps1 new file mode 100644 index 0000000..962c9d5 --- /dev/null +++ b/kubectx/install.ps1 @@ -0,0 +1,58 @@ +#!/usr/bin/env pwsh + +################### +# Install kubectx # +################### + +# Every package should define these variables +$pkg_cmd_name = "kubectx" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\kubectx.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\kubectx-v$Env:WEBI_VERSION\bin\kubectx.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\kubectx-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\kubectx-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading kubectx from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A -L "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing kubectx" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\kubectx-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\kubectx.exe" -Recurse -ErrorAction Ignore + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path "kubectx.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse +Remove-Item -Path "$pkg_src" -Recurse -ErrorAction Ignore diff --git a/kubectx/install.sh b/kubectx/install.sh new file mode 100644 index 0000000..40b1801 --- /dev/null +++ b/kubectx/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +{ + set -e + set -u + + ################### + # Install kubectx # + ################### + + # Every package should define these 6 variables + pkg_cmd_name="kubectx" + + pkg_dst_cmd="$HOME/.local/bin/kubectx" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/kubectx-v$WEBI_VERSION/bin/kubectx" + pkg_src_dir="$HOME/.local/opt/kubectx-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # e.g. ~/.local/opt/kubectx-v0.99.9/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./kubectx-*/kubectx ~/.local/opt/kubectx-v0.99.9/bin/kubectx + mv kubectx "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'kubectx' has no version parameter + echo + } + +} diff --git a/kubectx/releases.js b/kubectx/releases.js new file mode 100644 index 0000000..b94d09b --- /dev/null +++ b/kubectx/releases.js @@ -0,0 +1,28 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'ahmetb'; +var repo = 'kubectx'; + +/******************************************************************************/ +/** Note: Delete this Comment! **/ +/** **/ +/** Need a an example that filters out miscellaneous release files? **/ +/** See `deno`, `gitea`, or `caddy` **/ +/** **/ +/******************************************************************************/ + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); + }); +} -- 2.25.1