bc42097900e296a20f979b4ab836d4fd07670778

Author
Jérémy <PixiBixi@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(kubectl): show labels in aliases `kgpsl` (get pod) and `kgnosl` (get node) (#12612)

Co-authored-by: Marc Cornellà <marc@mcornella.com>

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/kubectl/README.md b/plugins/kubectl/README.md
  2index 579a90b3b8f10a442281ba090320ed448d85e921..28a502d111cf376b1b5b4dab0fc0602dcbd7922f 100644
  3--- a/plugins/kubectl/README.md
  4+++ b/plugins/kubectl/README.md
  5@@ -11,122 +11,124 @@ plugins=(... kubectl)
  6 
  7 ## Aliases
  8 
  9-| Alias   | Command                             | Description                                                                                      |
 10-|:--------|:------------------------------------|:-------------------------------------------------------------------------------------------------|
 11-| k       | `kubectl`                           | The kubectl command                                                                              |
 12-| kca     | `kubectl --all-namespaces`          | The kubectl command targeting all namespaces                                                     |
 13-| kaf     | `kubectl apply -f`                  | Apply a YML file                                                                                 |
 14-| keti    | `kubectl exec -ti`                  | Drop into an interactive terminal on a container                                                 |
 15-|         |                                     | **Manage configuration quickly to switch contexts between local, dev and staging**               |
 16-| kcuc    | `kubectl config use-context`        | Set the current-context in a kubeconfig file                                                     |
 17-| kcsc    | `kubectl config set-context`        | Set a context entry in kubeconfig                                                                |
 18-| kcdc    | `kubectl config delete-context`     | Delete the specified context from the kubeconfig                                                 |
 19-| kccc    | `kubectl config current-context`    | Display the current-context                                                                      |
 20-| kcgc    | `kubectl config get-contexts`       | List of contexts available                                                                       |
 21-|         |                                     | **General aliases**                                                                              |
 22-| kdel    | `kubectl delete`                    | Delete resources by filenames, stdin, resources and names, or by resources and label selector    |
 23-| kdelf   | `kubectl delete -f`                 | Delete a pod using the type and name specified in -f argument                                    |
 24-|         |                                     | **Pod management**                                                                               |
 25-| kgp     | `kubectl get pods`                  | List all pods in ps output format                                                                |
 26-| kgpw    | `kgp --watch`                       | After listing/getting the requested object, watch for changes                                    |
 27-| kgpwide | `kgp -o wide`                       | Output in plain-text format with any additional information. For pods, the node name is included |
 28-| kep     | `kubectl edit pods`                 | Edit pods from the default editor                                                                |
 29-| kdp     | `kubectl describe pods`             | Describe all pods                                                                                |
 30-| kdelp   | `kubectl delete pods`               | Delete all pods matching passed arguments                                                        |
 31-| kgpl    | `kgp -l`                            | Get pods by label. Example: `kgpl "app=myapp" -n myns`                                           |
 32-| kgpn    | `kgp -n`                            | Get pods by namespace. Example: `kgpn kube-system`                                               |
 33-|         |                                     | **Service management**                                                                           |
 34-| kgs     | `kubectl get svc`                   | List all services in ps output format                                                            |
 35-| kgsw    | `kgs --watch`                       | After listing all services, watch for changes                                                    |
 36-| kgswide | `kgs -o wide`                       | After listing all services, output in plain-text format with any additional information          |
 37-| kes     | `kubectl edit svc`                  | Edit services(svc) from the default editor                                                       |
 38-| kds     | `kubectl describe svc`              | Describe all services in detail                                                                  |
 39-| kdels   | `kubectl delete svc`                | Delete all services matching passed argument                                                     |
 40-|         |                                     | **Ingress management**                                                                           |
 41-| kgi     | `kubectl get ingress`               | List ingress resources in ps output format                                                       |
 42-| kei     | `kubectl edit ingress`              | Edit ingress resource from the default editor                                                    |
 43-| kdi     | `kubectl describe ingress`          | Describe ingress resource in detail                                                              |
 44-| kdeli   | `kubectl delete ingress`            | Delete ingress resources matching passed argument                                                |
 45-|         |                                     | **Namespace management**                                                                         |
 46-| kgns    | `kubectl get namespaces`            | List the current namespaces in a cluster                                                         |
 47-| kcn     | `kubectl config set-context --current --namespace` | Change current namespace |
 48-| kens    | `kubectl edit namespace`            | Edit namespace resource from the default editor                                                  |
 49-| kdns    | `kubectl describe namespace`        | Describe namespace resource in detail                                                            |
 50-| kdelns  | `kubectl delete namespace`          | Delete the namespace. WARNING! This deletes everything in the namespace                          |
 51-|         |                                     | **ConfigMap management**                                                                         |
 52-| kgcm    | `kubectl get configmaps`            | List the configmaps in ps output format                                                          |
 53-| kecm    | `kubectl edit configmap`            | Edit configmap resource from the default editor                                                  |
 54-| kdcm    | `kubectl describe configmap`        | Describe configmap resource in detail                                                            |
 55-| kdelcm  | `kubectl delete configmap`          | Delete the configmap                                                                             |
 56-|         |                                     | **Secret management**                                                                            |
 57-| kgsec   | `kubectl get secret`                | Get secret for decoding                                                                          |
 58-| kdsec   | `kubectl describe secret`           | Describe secret resource in detail                                                               |
 59-| kdelsec | `kubectl delete secret`             | Delete the secret                                                                                |
 60-|         |                                     | **Deployment management**                                                                        |
 61-| kgd     | `kubectl get deployment`            | Get the deployment                                                                               |
 62-| kgdw    | `kgd --watch`                       | After getting the deployment, watch for changes                                                  |
 63-| kgdwide | `kgd -o wide`                       | After getting the deployment, output in plain-text format with any additional information        |
 64-| ked     | `kubectl edit deployment`           | Edit deployment resource from the default editor                                                 |
 65-| kdd     | `kubectl describe deployment`       | Describe deployment resource in detail                                                           |
 66-| kdeld   | `kubectl delete deployment`         | Delete the deployment                                                                            |
 67-| ksd     | `kubectl scale deployment`          | Scale a deployment                                                                               |
 68-| krsd    | `kubectl rollout status deployment` | Check the rollout status of a deployment                                                         |
 69-| kres    | `kubectl set env $@ REFRESHED_AT=...` | Recreate all pods in deployment with zero-downtime                                             |
 70-|         |                                     | **Rollout management**                                                                           |
 71-| kgrs    | `kubectl get replicaset`            | List all ReplicaSets `rs` created by the deployment                                              |
 72-| kdrs    | `kubectl describe replicaset`       | Describe ReplicaSet in detail                                                                    |
 73-| kers    | `kubectl edit replicaset`           | Edit ReplicaSet from the default editor                                                          |
 74-| krh     | `kubectl rollout history`           | Check the revisions of this deployment                                                           |
 75-| kru     | `kubectl rollout undo`              | Rollback to the previous revision                                                                |
 76-|         |                                     | **Port forwarding**                                                                              |
 77-| kpf     | `kubectl port-forward`              | Forward one or more local ports to a pod                                                         |
 78-|         |                                     | **Tools for accessing all information**                                                          |
 79-| kga     | `kubectl get all`                   | List all resources in ps format                                                                  |
 80-| kgaa    | `kubectl get all --all-namespaces`  | List the requested object(s) across all namespaces                                               |
 81-|         |                                     | **Logs**                                                                                         |
 82-| kl      | `kubectl logs`                      | Print the logs for a container or resource                                                       |
 83-| klf     | `kubectl logs -f`                   | Stream the logs for a container or resource (follow)                                             |
 84-|         |                                     | **File copy**                                                                                    |
 85-| kcp     | `kubectl cp`                        | Copy files and directories to and from containers                                                |
 86-|         |                                     | **Node management**                                                                              |
 87-| kgno    | `kubectl get nodes`                 | List the nodes in ps output format                                                               |
 88-| keno    | `kubectl edit node`                 | Edit nodes resource from the default editor                                                      |
 89-| kdno    | `kubectl describe node`             | Describe node resource in detail                                                                 |
 90-| kdelno  | `kubectl delete node`               | Delete the node                                                                                  |
 91-|         |                                     | **Persistent Volume Claim management**                                                           |
 92-| kgpvc   | `kubectl get pvc`                   | List all PVCs                                                                                    |
 93-| kgpvcw  | `kgpvc --watch`                     | After listing/getting the requested object, watch for changes                                    |
 94-| kepvc   | `kubectl edit pvc`                  | Edit pvcs from the default editor                                                                |
 95-| kdpvc   | `kubectl describe pvc`              | Describe all pvcs                                                                                |
 96-| kdelpvc | `kubectl delete pvc`                | Delete all pvcs matching passed arguments                                                        |
 97-|         |                                     | **StatefulSets management**                                                                      |
 98-| kgss    | `kubectl get statefulset`           | List the statefulsets in ps format                                                               |
 99-| kgssw   | `kgss --watch`                      | After getting the list of statefulsets, watch for changes                                        |
100-| kgsswide| `kgss -o wide`                      | After getting the statefulsets, output in plain-text format with any additional information      |
101-| kess    | `kubectl edit statefulset`          | Edit statefulset resource from the default editor                                                |
102-| kdss    | `kubectl describe statefulset`      | Describe statefulset resource in detail                                                          |
103-| kdelss  | `kubectl delete statefulset`        | Delete the statefulset                                                                           |
104-| ksss    | `kubectl scale statefulset`         | Scale a statefulset                                                                              |
105diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh
106index ad78fedeb9f1c413a49265aec7449e86454f6ff5..33699bdf9db6a6bbd45cd012648cc7ad94b25227 100644
107--- a/plugins/kubectl/kubectl.plugin.zsh
108+++ b/plugins/kubectl/kubectl.plugin.zsh
109@@ -39,6 +39,9 @@ alias kdelf='kubectl delete -f'
110 
111 # Pod management.
112 alias kgp='kubectl get pods'
113+alias kgpl='kgp -l'
114+alias kgpn='kgp -n'
115+alias kgpsl='kubectl get pods --show-labels'
116 alias kgpa='kubectl get pods --all-namespaces'
117 alias kgpw='kgp --watch'
118 alias kgpwide='kgp -o wide'
119@@ -47,12 +50,6 @@ alias kdp='kubectl describe pods'
120 alias kdelp='kubectl delete pods'
121 alias kgpall='kubectl get pods --all-namespaces -o wide'
122 
123-# get pod by label: kgpl "app=myapp" -n myns
124-alias kgpl='kgp -l'
125-
126-# get pod by namespace: kgpn kube-system"
127-alias kgpn='kgp -n'
128-
129 # Service management.
130 alias kgs='kubectl get svc'
131 alias kgsa='kubectl get svc --all-namespaces'
132@@ -144,6 +141,7 @@ alias kcp='kubectl cp'
133 
134 # Node Management
135 alias kgno='kubectl get nodes'
136+alias kgnosl='kubectl get nodes --show-labels'
137 alias keno='kubectl edit node'
138 alias kdno='kubectl describe node'
139 alias kdelno='kubectl delete node'