commit 8027c13685a804fb4ae3c64db740b37c7e1acac8
parent 3979fd25a332d4d9e363dce3bedaabf91b37c963
Author: Vincent Demeester <vincent@sbr.pm>
Date: Thu, 24 Mar 2022 15:30:00 +0100
nix/packages: add chmouzies.kubernetes…
… and remove duplicate scripts from my.scripts
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
6 files changed, 28 insertions(+), 128 deletions(-)
diff --git a/nix/packages/chmouzies/builder.kubernetes.sh b/nix/packages/chmouzies/builder.kubernetes.sh
@@ -0,0 +1,8 @@
+source $stdenv/setup
+
+BINARIES="tktl ocla kcl kselect expose-openshift-registry-for-ko.sh decode-kubernetes-secrets.py"
+
+mkdir -p $out/bin
+for b in ${BINARIES}; do
+ cp $src/kubernetes/${b} $out/bin/
+done
diff --git a/nix/packages/chmouzies/kubernetes.nix b/nix/packages/chmouzies/kubernetes.nix
@@ -0,0 +1,17 @@
+# https://github.com/chmouel/chmouzies/tree/master/kubernetes
+{ stdenv, fetchFromGitHub, python310 }:
+
+stdenv.mkDerivation rec {
+ name = "chmouzies.kubernetes";
+
+ src = fetchFromGitHub {
+ owner = "chmouel";
+ repo = "chmouzies";
+ rev = "27bda8604ae51d3a4846f382475999f301c33285";
+ sha256 = "sha256-atMxidonT5gjIo9Lt79G/MaA0ixi/i94Ehuw+kOC34E=";
+ };
+
+ propagatedBuildInputs = [ python310 ];
+
+ builder = ./builder.kubernetes.sh;
+}
diff --git a/nix/packages/default.nix b/nix/packages/default.nix
@@ -10,6 +10,8 @@ rec {
bus = pkgs.callPackage ../../tools/bus { };
bekind = pkgs.callPackage ../../tools/bekind { };
+ chmouzies.kubernetes = pkgs.callPackage ./chmouzies/kubernetes.nix { };
+
# Mine
ape = pkgs.callPackage ./ape { };
fhs-std = pkgs.callPackage ./fhs/std.nix { };
diff --git a/nix/packages/my/scripts/bin/decode-kubernetes-secrets.py b/nix/packages/my/scripts/bin/decode-kubernetes-secrets.py
@@ -1,35 +0,0 @@
-#! /usr/bin/env nix-shell
-#! nix-shell -i python3 -p python3 -p python37Packages.pyaml
-# -*- coding: utf-8 -*-
-# Author: Chmouel Boudjnah <chmouel@chmouel.com>
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-import yaml
-import base64
-import sys
-
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
-
-if len(sys.argv[0]):
- stream = sys.stdin
-else:
- stream = open(sys.argv[1])
-data = yaml.load(stream, Loader=Loader)
-for d in data['data'].items():
- if d[1] and d[1].endswith("="):
- print("Key: " + d[0] + " \nValue: \n" + \
- base64.b64decode(d[1]).decode('utf-8'))
- print("\n")
diff --git a/nix/packages/my/scripts/bin/tktl b/nix/packages/my/scripts/bin/tktl
@@ -1,93 +0,0 @@
-#!/usr/bin/env zsh
-set -eu
-local preview pods p follow choose_containers containeri container use_tkn
-local use_kss last
-
-function help {
- cat <<EOF
-tktl [TASK Query] [Container Query]"
-
-Queries are initial queries for selection on fzf, i.e:
-
-tktl buildah push
-
-will autoselect the buildah taskrun (or ask to choose if there is multiple) and
-the push container
-
-Flags:
-
--l select the last taskruns
--f follow logs
--K use kss for previewing the taskruns (need to be installed)
--t use tkn to display the logs
--c choose a specific container (ie step) not supported with -t
-
-EOF
-}
-while getopts 'lhfKtc' arg
-do
- case $arg in
- (l) last="true";;
- (f) follow="-f" ;;
- (K) use_kss=yes ;;
- (t) use_tkn="yes";;
- (c) use_tkn="";choose_containers="yes";; # use kubectl until tkn support limiting to container we should be implicit
- (h) help; exit 0;;
- (\?) help;exit 1;;
- esac
-done
-(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
-
-chooseTaskArg=${1:-""};[[ -n ${chooseTaskArg} ]] && chooseTaskArg="-q ${chooseTaskArg}"
-chooseContainerArg=${2:-""}
-
-if [[ -n ${use_kss} ]];then
- preview='kss `kubectl get -o json tr {}| jq -r .status.podName`'
-else
- preview='tkn taskrun describe {}'
-fi
-
-if [[ -n ${last} ]];then
- task=$(kubectl get tr -o name --sort-by=.metadata.creationTimestamp|sed 's,.*/,,'|tail -1)
-else
- task=$(kubectl get tr -o json --sort-by=.metadata.creationTimestamp| python <(cat <<EOF
-import json,sys
-jeez=json.loads(sys.stdin.read())
-def colit(condition, name):
- if condition=='Succeeded':
- color=32
- elif condition=='Failed':
- color=31
- elif condition=='Running':
- color=34
- else:
- color=30
- return("\033[1;%dm%s\033[0;0m" % (color, name))
-for i in jeez['items']:
- print(colit(i['status']['conditions'][0]['reason'], i['metadata']['name']))
-
-EOF
- ) | fzf --ansi -1 ${chooseTaskArg} --tac \
- --header "Choose a taskrun" \
- --preview ${preview})
-fi
-
-[[ -z ${task} ]] && return
-
-podName=$(kubectl get tr -o json ${task} | jq -r '.status.podName')
-if [[ -n ${choose_containers} ]];then
- [[ -n ${chooseContainerArg} ]] && containeri="-q ${chooseContainerArg}"
- container=$(kubectl get pod ${podName} -o json|sed 's/step-//'|jq -r '.spec.containers[].name'| \
- fzf --header "Choose a container." \
- --tac -1 ${containeri} --preview "kubectl logs ${podName} -c step-{}")
- [[ -n ${container} ]] && container=(-c step-${container})
-else
- container=(--all-containers --max-log-requests=10)
-fi
-
-t=$(basename ${task});
-if [[ -n ${use_tkn} ]];then
- tkn taskrun logs ${follow} ${t}
-else
- kubectl logs ${follow} ${podName} ${container[@]}
-fi
diff --git a/users/vincent/containers/kubernetes.nix b/users/vincent/containers/kubernetes.nix
@@ -22,5 +22,6 @@ in
knd
bekind
stern
+ my.chmouzies.kubernetes
];
}