Skip to content

Commit 30698a9

Browse files
authored
Merge pull request #44 from nginxinc/mrajagopal-nginx-support
Issue 41: Add support for NGINX containers in k8s
2 parents 48a7660 + 7ee7268 commit 30698a9

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A kubectl plugin designed to collect diagnostics information on any NGINX produc
44

55
## Supported products
66

7-
Currently, [NIC](https://github.com/nginxinc/kubernetes-ingress) is the only supported product.
7+
Currently, [NIC](https://github.com/nginxinc/kubernetes-ingress), [NGF](https://github.com/nginxinc/nginx-gateway-fabric) and [NGINX (OSS/NPLUS) in containers](https://github.com/nginx/nginx) are the supported products.
88

99
## Features
1010

cmd/nginx-supportpkg.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ package cmd
2020

2121
import (
2222
"fmt"
23+
"os"
24+
"slices"
25+
2326
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/data_collector"
2427
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/jobs"
2528
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/version"
2629
"github.com/spf13/cobra"
27-
"os"
28-
"slices"
2930
)
3031

3132
func Execute() {
@@ -54,8 +55,10 @@ func Execute() {
5455
jobList = slices.Concat(jobs.CommonJobList(), jobs.NICJobList())
5556
case "ngf":
5657
jobList = slices.Concat(jobs.CommonJobList(), jobs.NGFJobList())
58+
case "ngx":
59+
jobList = slices.Concat(jobs.CommonJobList(), jobs.NGXJobList())
5760
default:
58-
fmt.Printf("Error: product must be in the following list: [nic, ngf]\n")
61+
fmt.Printf("Error: product must be in the following list: [nic, ngf, ngx]\n")
5962
os.Exit(1)
6063
}
6164

@@ -112,8 +115,8 @@ func Execute() {
112115
"Usage:" +
113116
"\n nginx-supportpkg -h|--help" +
114117
"\n nginx-supportpkg -v|--version" +
115-
"\n nginx-supportpkg [-n|--namespace] ns1 [-n|--namespace] ns2 [-p|--product] [nic,ngf]" +
116-
"\n nginx-supportpkg [-n|--namespace] ns1,ns2 [-p|--product] [nic,ngf] \n")
118+
"\n nginx-supportpkg [-n|--namespace] ns1 [-n|--namespace] ns2 [-p|--product] [nic,ngf,ngx]" +
119+
"\n nginx-supportpkg [-n|--namespace] ns1,ns2 [-p|--product] [nic,ngf,ngx] \n")
117120

118121
if err := rootCmd.Execute(); err != nil {
119122
fmt.Println(err)

pkg/jobs/ngx_job_list.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
3+
Copyright 2024 F5, Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
**/
18+
19+
package jobs
20+
21+
import (
22+
"context"
23+
"path/filepath"
24+
"strings"
25+
"time"
26+
27+
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/data_collector"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
)
30+
31+
func NGXJobList() []Job {
32+
jobList := []Job{
33+
{
34+
Name: "exec-nginx-t",
35+
Timeout: time.Second * 10,
36+
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
37+
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
38+
command := []string{"/usr/sbin/nginx", "-T"}
39+
for _, namespace := range dc.Namespaces {
40+
pods, err := dc.K8sCoreClientSet.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
41+
if err != nil {
42+
dc.Logger.Printf("\tCould not retrieve pod list for namespace %s: %v\n", namespace, err)
43+
} else {
44+
for _, pod := range pods.Items {
45+
if strings.Contains(pod.Name, "nginx") {
46+
res, err := dc.PodExecutor(namespace, pod.Name, "nginx", command, ctx)
47+
if err != nil {
48+
jobResult.Error = err
49+
dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err)
50+
} else {
51+
jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, pod.Name+"__nginx-t.txt")] = res
52+
}
53+
}
54+
}
55+
}
56+
}
57+
ch <- jobResult
58+
},
59+
},
60+
}
61+
return jobList
62+
}

0 commit comments

Comments
 (0)