Skip to content

Commit 54f3d25

Browse files
authored
Merge pull request #6 from nginxinc/areste
Add support for multiple products
2 parents 183a8b5 + 3ebb186 commit 54f3d25

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build:
2-
go build -o cmd/kubectl-nic-supportpkg
2+
go build -o cmd/kubectl-nginx_supportpkg
33

44
install: build
5-
sudo cp cmd/kubectl-nic-supportpkg /usr/local/bin
5+
sudo cp cmd/kubectl-nginx_supportpkg /usr/local/bin

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# nginx-supportpkg-for-k8s
22

3-
A kubectl plugin designed to collect NIC diagnostics information on the designated namespaces.
3+
A kubectl plugin designed to collect diagnostics information on any NGINX product running on k8s.
4+
5+
## Supported products
6+
7+
Currently, [NIC](https://github.com/nginxinc/kubernetes-ingress) is the only supported product.
48

59
## Features
610

7-
The plugin collects the following global and namespace-specific information:
11+
Depending on the product, the plugin might collect some or all of the following global and namespace-specific information:
812

913
- k8s version, nodes information and CRDs
1014
- pods logs
1115
- list of pods, events, configmaps, services, deployments, statefulsets, replicasets and leases
1216
- k8s metrics
1317
- helm deployments
14-
- `nginx -T` output from the NIC pods
18+
- `nginx -T` output from NGINX pods
1519

16-
The plugin DOES NOT collect secrets or coredums.
20+
The plugin DOES NOT collect secrets or coredumps.
1721

1822
## Installation
1923

@@ -26,7 +30,7 @@ Verify that the plugin is properly found by `kubectl`:
2630
$ kubectl plugin list
2731
The following compatible plugins are available:
2832
29-
/usr/local/bin/kubectl-nic-supportpkg
33+
/usr/local/bin/kubectl-nginx_supportpkg
3034
```
3135

3236
### Downloading the binary
@@ -39,15 +43,19 @@ Decompress the tarball and copy the binary somewhere in your `$PATH`. Make sure
3943
$ kubectl plugin list
4044
The following compatible plugins are available:
4145
42-
/path/to/plugin/kubectl-nic-supportpkg
46+
/path/to/plugin/kubectl-nginx_supportpkg
4347
```
4448

4549
## Usage
4650

47-
The plugin is invoked via `kubectl nic supportpkg` and has only one required flag, `-n` or `--namespace`:
51+
The plugin is invoked via `kubectl nginx-supportpkg` and has two required flags:
52+
53+
* `-n` or `--namespace` indicates the namespace(s) where the product is running.
54+
* `-p` or `--product` indicates the product to collect information from.
55+
4856

4957
```
50-
$ kubectl nic supportpkg -n default -n nginx-ingress-0
58+
$ kubectl nginx-supportpkg -n default -n nginx-ingress-0 -p nic
5159
Running job pod-list... OK
5260
Running job collect-pods-logs... OK
5361
Running job events-list... OK

cmd/nic-supportpkg.go renamed to cmd/nginx-supportpkg.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import (
3030
func Execute() {
3131

3232
var namespaces []string
33+
var product string
34+
var jobList []jobs.Job
3335

3436
var rootCmd = &cobra.Command{
35-
Use: "nic-supportpkg",
36-
Short: "nic-supportpkg - a tool to create Ingress Controller diagnostics package",
37-
Long: `nic-supportpkg - a tool to create Ingress Controller diagnostics package`,
37+
Use: "nginx-supportpkg",
38+
Short: "nginx-supportpkg - a tool to create Ingress Controller diagnostics package",
39+
Long: `nginx-supportpkg - a tool to create Ingress Controller diagnostics package`,
3840
Run: func(cmd *cobra.Command, args []string) {
3941

4042
collector, err := data_collector.NewDataCollector(namespaces...)
@@ -43,10 +45,18 @@ func Execute() {
4345
os.Exit(1)
4446
}
4547

46-
collector.Logger.Printf("Starting kubectl-nic-suportpkg - version: %s - build: %s", version.Version, version.Build)
48+
collector.Logger.Printf("Starting kubectl-nginx-suportpkg - version: %s - build: %s", version.Version, version.Build)
4749

48-
if collector.AllNamespacesExist() == true {
49-
for _, job := range jobs.JobList() {
50+
switch product {
51+
case "nic":
52+
jobList = jobs.NICJobList()
53+
default:
54+
fmt.Printf("Error: product must be in the following list: [nic]\n")
55+
os.Exit(1)
56+
}
57+
58+
if collector.AllNamespacesExist() {
59+
for _, job := range jobList {
5060
fmt.Printf("Running job %s...", job.Name)
5161
err = job.Collect(collector)
5262
if err != nil {
@@ -56,7 +66,7 @@ func Execute() {
5666
}
5767
}
5868

59-
tarFile, err := collector.WrapUp()
69+
tarFile, err := collector.WrapUp(product)
6070
if err != nil {
6171
fmt.Println(fmt.Errorf("error when wrapping up: %s", err))
6272
os.Exit(1)
@@ -74,7 +84,14 @@ func Execute() {
7484
fmt.Println(err)
7585
os.Exit(1)
7686
}
77-
rootCmd.SetUsageTemplate("Usage: \n nic supportpkg [-n|--namespace] ns1 [-n|--namespace] ns2 ...\n nic supportpkg [-n|--namespace] ns1,ns2 ...\n")
87+
88+
rootCmd.Flags().StringVarP(&product, "product", "p", "", "products to collect information from")
89+
if err := rootCmd.MarkFlagRequired("product"); err != nil {
90+
fmt.Println(err)
91+
os.Exit(1)
92+
}
93+
94+
rootCmd.SetUsageTemplate("Usage: \n nginx-supportpkg [-n|--namespace] ns1 [-n|--namespace] ns2 [-p|--product] nic...\n nginx-supportpkg [-n|--namespace] ns1,ns2 [-p|--product] nic...\n")
7895

7996
if err := rootCmd.Execute(); err != nil {
8097
fmt.Println(err)

pkg/data_collector/data_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ func NewDataCollector(namespaces ...string) (*DataCollector, error) {
103103
return &dc, nil
104104
}
105105

106-
func (c *DataCollector) WrapUp() (string, error) {
106+
func (c *DataCollector) WrapUp(product string) (string, error) {
107107

108108
unixTime := time.Now().Unix()
109109
unixTimeString := strconv.FormatInt(unixTime, 10)
110-
tarballName := fmt.Sprintf("nic-supportpkg-%s.tar.gz", unixTimeString)
110+
tarballName := fmt.Sprintf("%s-supportpkg-%s.tar.gz", product, unixTimeString)
111111
tarballRootDirName := fmt.Sprintf("nic-supportpkg-%s", unixTimeString)
112112

113113
err := c.LogFile.Close()

pkg/jobs/job_list.go renamed to pkg/jobs/nic_job_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"time"
3434
)
3535

36-
func JobList() []Job {
36+
func NICJobList() []Job {
3737
jobList := []Job{
3838
{
3939
Name: "pod-list",

0 commit comments

Comments
 (0)