| 
 | 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