File tree Expand file tree Collapse file tree 2 files changed +98
-1
lines changed Expand file tree Collapse file tree 2 files changed +98
-1
lines changed Original file line number Diff line number Diff line change 1
1
# kubectl-all
2
- kubectl plugin to list all resources in given namespace
2
+
3
+ ## Motivation
4
+
5
+ * Kubectl get all - list's a subset of all the resources available, wanted to make all the resources visible.
6
+
7
+ ## Installation
8
+
9
+ ### Dependencies
10
+
11
+ * bash
12
+
13
+ ### With [ krew] ( https://github.com/GoogleContainerTools/krew ) (recommended)
14
+
15
+ ``` sh
16
+ kubectl krew install all
17
+ kubectl all
18
+ ```
19
+
20
+ ### Without krew
21
+
22
+ * Copy ` all.sh ` to a file called ` kubectl-all `
23
+ * Run ` chmod +x kubectl-all `
24
+ * Add the path to directory in your $PATH. eg ` export PATH="/path/to/dir:$PATH" `
25
+ * Test ` kubectl all `
26
+
27
+ ## Features
28
+
29
+ * list all resources in the default namespace
30
+ * list all resources within a specific namespace
31
+
32
+ ## Usage
33
+
34
+ ``` sh
35
+ kubectl all resources : list all resources in the default namespace
36
+
37
+ kubectl all -h | --help : Usage of this command line
38
+
39
+ kubectl all resources < namespace> : list all namespaced resources
40
+
41
+ ```
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # Usage:
4
+ # kubectl all resources
5
+ # kubectl all resources [namespace]
6
+
7
+ # Requires:
8
+ # - kubectl
9
+
10
+ set -eo pipefail
11
+
12
+ function usage() {
13
+ echo " USAGE"
14
+ echo " -----"
15
+ echo " kubectl all resources"
16
+ echo " "
17
+ echo " kubectl all resources namespace"
18
+ echo " "
19
+ echo " kubectl all -h | --help : Usage of this command line" ;
20
+ echo " "
21
+ }
22
+
23
+ # Add any resources that need to be ignored
24
+ list=(bindings localsubjectaccessreviews.authorization.k8s.io pods.metrics.k8s.io events.events.k8s.io)
25
+
26
+ elementIn () {
27
+ local e
28
+ for e in " ${@: 2} " ; do [[ " $e " == " $1 " ]] && return 0; done
29
+ return 1
30
+ }
31
+
32
+ function get_resources() {
33
+ if [ -z " $1 " ]; then namespace=' default' ; else namespace=" $1 " ; fi
34
+ resources=$( kubectl api-resources --namespaced=true --output=name)
35
+ for resource in $resources ; do
36
+ if elementIn " $resource " " ${list[@]} " ; then
37
+ continue
38
+ else
39
+ data=$( kubectl get $resource -n $namespace --ignore-not-found=true)
40
+ if [[ ! -z $data ]]; then
41
+ echo $resource ' :'
42
+ echo -e " $data "
43
+ printf ' \n'
44
+ fi
45
+ fi
46
+ done
47
+
48
+
49
+ }
50
+
51
+ if [ -z " $1 " ]; then usage && exit ; fi
52
+ while [ -n " $1 " ]; do
53
+ case " $1 " in
54
+ resources) shift ; get_resources " $@ " ; exit ;;
55
+ -h|--help) usage; exit ;; # quit and show usage
56
+ * ) echo " $1 not recognized" ; exit 1;; # if no match, add it to the positional args
57
+ esac
58
+ done
You can’t perform that action at this time.
0 commit comments