-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from lalyos/master
make it a kubectl cli plugin
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tgz: | ||
@find . -regex './[A-Z][a-z].*\.yaml' -type f -print0 \ | ||
| tar --null --files-from - -cf examples.tar | ||
@tar -uf examples.tar kubectl-examples | ||
gzip examples.tar | ||
|
||
sha = $(shell shasum -a 256 < examples.tar.gz|cut -d" " -f1) | ||
|
||
update: | ||
@sed -i 's/sha256: .*$$/sha256: $(sha)/' plugins/examples.yaml | ||
|
||
install: clean tgz update | ||
kubectl krew install --manifest=plugins/examples.yaml --archive=examples.tar.gz | ||
|
||
clean: | ||
@rm -f examples.tar.gz | ||
@kubectl krew uninstall examples || : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
debug() { | ||
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2 | ||
} | ||
|
||
print-example() { | ||
declare res=$1 pattern=$2 | ||
|
||
dir=$(dirname $(readlink $BASH_SOURCE)) | ||
debug "dir=${dir}" | ||
|
||
if [[ $res == "" ]]; then | ||
PS3="Resource Type: " | ||
select res in $(ls -1 $dir|grep -v kubectl-examples); do | ||
debug "res type choosen: ${res}" | ||
break | ||
done | ||
fi | ||
|
||
# resorce names can be abreviated | ||
[[ -d ${dir}/${res} ]] || res="${res}*" | ||
|
||
match=0 | ||
for f in ${dir}/${res}/**/*${pattern}*.yaml; do | ||
[[ -e ${f} ]] && : $(( match++ )) | ||
done | ||
|
||
case ${match} in | ||
0) | ||
debug "no match ..." | ||
return | ||
;; | ||
1) | ||
debug "exact match" | ||
yaml=${dir}/${res}*/**/*${pattern}*.yaml | ||
;; | ||
*) | ||
debug "multiple choice" | ||
PS3="Yaml example: " | ||
select yaml in ${dir}/${res}/**/*${pattern}*.yaml; do | ||
debug "YAML selected: ${yaml}" | ||
break | ||
done | ||
;; | ||
esac | ||
|
||
cat ${yaml} | ||
} | ||
|
||
main() { | ||
: ${DEBUG:=1} | ||
shopt -s globstar | ||
print-example "$@" | ||
} | ||
|
||
[[ "$0" == "$BASH_SOURCE" ]] && main "$@" || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
apiVersion: krew.googlecontainertools.github.com/v1alpha2 | ||
kind: Plugin | ||
metadata: | ||
name: examples | ||
spec: | ||
version: "v0.0.1" | ||
homepage: https://github.com/ContainerSolutions/kubernetes-examples | ||
shortDescription: "Prints sample manifests" | ||
description: | | ||
A reference repository of YAML with canonical | ||
and as-simple-as-possible demonstrations of | ||
kubernetes functionality and features. | ||
platforms: | ||
- selector: | ||
matchExpressions: | ||
- key: "os" | ||
operator: "In" | ||
values: | ||
- darwin | ||
- linux | ||
uri: https://github.com/lalyos/kubernetes-examples/releases/download/v0.0.1/examples.tar.gz | ||
sha256: f6e5cab7e4a94f322f0521b3384c0470ac7f0d8136af115e44423d2533885b5e | ||
files: | ||
- from: "*" | ||
to: "." | ||
bin: kubectl-examples |