Skip to content

Commit

Permalink
Release: v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx committed Jul 13, 2022
1 parent d452e56 commit 2e48cd1
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 143 deletions.
73 changes: 67 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<em>🕸 Show container images used in the cluster.</em>
</p>

kubectl-images makes use of the `kubectl` command. It first calls `kubectl get pods` to retrieve pods details and filters out the container image information of each pod, then prints out the final result in a table view.
kubectl-images makes use of the `kubectl` command. It first calls `kubectl get pods` to retrieve pods details and
filters out the container image information of each pod, then prints out the final result in a table view.

### 🔰 Installation

Krew

```shell
$ kubectl krew install images
Updated the local copy of plugin index.
Expand All @@ -22,13 +24,15 @@ Installed plugin: images
```

Build from source code

```shell
$ git clone https://github.com/chenjiandongx/kubectl-images.git
$ cd kubectl-images && go build -ldflags="-s -w" -o kubectl-images . && mv ./kubectl-images /usr/local/bin
$ kubectl images --help
```

Download the binary

```shell
# Refer to the link: https://github.com/chenjiandongx/kubectl-images/releases
# Download the binary and then...
Expand All @@ -49,24 +53,81 @@ Examples:
# display a table of all images in current namespace using podName/containerName/containerImage as columns.
kubectl images

# display images info in yaml format
kubectl images -oy

# display a table of images that match 'nginx' podname regex in 'dev' namespace using podName/containerImage as columns.
kubectl images -n dev nginx -c 1,2

Flags:
-A, --all-namespaces if present, list images in all namespaces.
-c, --columns string specify the columns to display, separated by comma. [0:Namespace, 1:PodName, 2:ContainerName, 3:ContainerImage] (default "1,2,3")
--context string The name of the kubeconfig context to use.
-c, --columns string specify the columns to display, separated by comma. [0:Namespace, 1:PodName, 2:ContainerName, 3:ContainerImage, 4:ImagePullPolicy] (default "1,2,3")
-C, --context string The name of the kubeconfig context to use.
-h, --help help for kubectl-images
-k, --kubeconfig string path to the kubeconfig file to use for CLI requests.
-n, --namespace string if present, list images in the specified namespace only. Use current namespace as fallback.
-o, --output-format string output format. [json|table] (default "table")
-o, --output-format string output format. [json(j)|table(t)|yaml(y)] (default "table")
--version version for kubectl-images
```
### 🔖 Glances
![image](https://user-images.githubusercontent.com/19553554/74729593-a9201e00-527f-11ea-8325-a4c332dde783.png)
![image](https://user-images.githubusercontent.com/19553554/74729607-ade4d200-527f-11ea-938d-892158d7560f.png)
```shell
~ 🐶 kubectl images -n kube-system -oy dns
- pod: coredns-78fcd69978-9pbjh
container: coredns
image: kube-system
- pod: coredns-78fcd69978-jh7m2
container: coredns
image: kube-system

~ 🐶 kubectl images -A -c 0,1,3
[Summary]: 2 namespaces, 11 pods, 11 containers and 9 different images
+-------------+----------------------------------------+--------------------------------------------+
| Namespace | Pod | Image |
+-------------+----------------------------------------+--------------------------------------------+
| kube-system | coredns-78fcd69978-9pbjh | k8s.gcr.io/coredns/coredns:v1.8.4 |
+ +----------------------------------------+ +
| | coredns-78fcd69978-jh7m2 | |
+ +----------------------------------------+--------------------------------------------+
| | etcd-docker-desktop | k8s.gcr.io/etcd:3.5.0-0 |
+ +----------------------------------------+--------------------------------------------+
| | kube-apiserver-docker-desktop | k8s.gcr.io/kube-apiserver:v1.22.5 |
+ +----------------------------------------+--------------------------------------------+
| | kube-controller-manager-docker-desktop | k8s.gcr.io/kube-controller-manager:v1.22.5 |
+ +----------------------------------------+--------------------------------------------+
| | kube-proxy-vc7fv | k8s.gcr.io/kube-proxy:v1.22.5 |
+ +----------------------------------------+--------------------------------------------+
| | kube-scheduler-docker-desktop | k8s.gcr.io/kube-scheduler:v1.22.5 |
+ +----------------------------------------+--------------------------------------------+
| | storage-provisioner | docker/desktop-storage-provisioner:v2.0 |
+ +----------------------------------------+--------------------------------------------+
| | vpnkit-controller | docker/desktop-vpnkit-controller:v2.0 |
+-------------+----------------------------------------+--------------------------------------------+
| nginx | nginx-deployment-66b6c48dd5-s9wv5 | nginx:1.14.2 |
+ +----------------------------------------+ +
| | nginx-deployment-66b6c48dd5-wmn9x | |
+-------------+----------------------------------------+--------------------------------------------+

~ 🐶 kubectl images -c 0,1,2,3,4 -n nginx -oj
[Summary]: 1 namespaces, 2 pods, 2 containers and 1 different images
[
{
"namespace": "nginx",
"pod": "nginx-deployment-66b6c48dd5-s9wv5",
"container": "nginx",
"image": "nginx",
"imagePullPolicy": "IfNotPresent"
},
{
"namespace": "nginx",
"pod": "nginx-deployment-66b6c48dd5-wmn9x",
"container": "nginx",
"image": "nginx",
"imagePullPolicy": "IfNotPresent"
}
]
```
### 📃 License
Expand Down
18 changes: 11 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"fmt"
"os"
"regexp"

kubeimage "github.com/chenjiandongx/kubectl-images"
kubeimages "github.com/chenjiandongx/kubectl-images"
"github.com/spf13/cobra"
)

const version = "0.3.7"
const version = "0.4.0"

var rootCmd *cobra.Command

Expand All @@ -19,6 +20,9 @@ func init() {
Example: ` # display a table of all images in current namespace using podName/containerName/containerImage as columns.
kubectl images
# display images info in yaml format
kubectl images -oy
# display a table of images that match 'nginx' podname regex in 'dev' namespace using podName/containerImage as columns.
kubectl images -n dev nginx -c 1,2`,
Version: version,
Expand All @@ -27,7 +31,7 @@ func init() {
var err error
if len(args) > 0 {
if regx, err = regexp.Compile(args[0]); err != nil {
fmt.Println("[Oh...] Invalid regex pattern.")
fmt.Fprintf(os.Stderr, "[Oh...] Invalid regex pattern (%q)", args[0])
return
}
}
Expand All @@ -37,20 +41,20 @@ func init() {
allNamespace, _ := cmd.Flags().GetBool("all-namespaces")
kubeConfig, _ := cmd.Flags().GetString("kubeConfig")
context, _ := cmd.Flags().GetString("context")
kubeImage := kubeimage.NewKubeImage(regx, allNamespace, namespace, columns, kubeConfig, context)
kubeImage := kubeimages.NewKubeImage(regx, allNamespace, namespace, columns, kubeConfig, context)
kubeImage.Render(format)
},
}
rootCmd.Flags().BoolP("all-namespaces", "A", false, "if present, list images in all namespaces.")
rootCmd.Flags().StringP("namespace", "n", "", "if present, list images in the specified namespace only. Use current namespace as fallback.")
rootCmd.Flags().StringP("columns", "c", "1,2,3", "specify the columns to display, separated by comma. [0:Namespace, 1:PodName, 2:ContainerName, 3:ContainerImage, 4:ImagePullPolicy]")
rootCmd.Flags().StringP("kubeconfig", "k", "", "path to the kubeconfig file to use for CLI requests.")
rootCmd.Flags().StringP("output-format", "o", "table", "output format. [json|table]")
rootCmd.Flags().String("context", "", "The name of the kubeconfig context to use.")
rootCmd.Flags().StringP("output-format", "o", "table", "output format. [json(j)|table(t)|yaml(y)]")
rootCmd.Flags().StringP("context", "C", "", "The name of the kubeconfig context to use.")
}

func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
fmt.Fprintf(os.Stderr, "[Oh...] Failed to exec command: %v", err)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.13
require (
github.com/olekukonko/tablewriter v0.0.4
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.2.2
)
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand All @@ -18,7 +17,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand All @@ -29,12 +27,13 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Loading

0 comments on commit 2e48cd1

Please sign in to comment.