@@ -2,67 +2,28 @@ package jobs
2
2
3
3
import (
4
4
"context"
5
- crdClient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
6
- "k8s.io/client-go/kubernetes"
7
- metricsClient "k8s.io/metrics/pkg/client/clientset/versioned"
5
+ "github.com/nginxinc/kubectl-kic-supportpkg/internal/data_collector"
8
6
"os"
9
7
"path"
10
8
"time"
11
9
)
12
10
13
11
type Job struct {
14
- Name string
15
- OutputFile string
16
- RetrieveFunction func (* kubernetes. Clientset , context.Context ) []byte
12
+ Name string
13
+ Global bool
14
+ Execute func (dc * data_collector. DataCollector , ctx context.Context ) map [ string ] []byte
17
15
}
18
16
19
- type CustomJob struct {
20
- Name string
21
- OutputFile string
22
- RetrieveFunction func (* crdClient.Clientset , context.Context ) []byte
23
- }
24
-
25
- type MetricsJob struct {
26
- Name string
27
- OutputFile string
28
- RetrieveFunction func (* metricsClient.Clientset , context.Context ) []byte
29
- }
30
-
31
- func (j Job ) Collect (baseFolder string , cs * kubernetes.Clientset ) {
32
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
33
- defer cancel ()
34
- result := j .RetrieveFunction (cs , ctx )
35
-
36
- fullPathFile := path .Join (baseFolder , j .OutputFile )
37
- os .MkdirAll (path .Dir (fullPathFile ), os .ModePerm )
38
-
39
- file , _ := os .Create (fullPathFile )
40
- defer file .Close ()
41
- _ , _ = file .Write (result )
42
- }
43
-
44
- func (j CustomJob ) CustomCollect (baseFolder string , cs * crdClient.Clientset ) {
45
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
46
- defer cancel ()
47
- result := j .RetrieveFunction (cs , ctx )
48
-
49
- fullPathFile := path .Join (baseFolder , j .OutputFile )
50
- os .MkdirAll (path .Dir (fullPathFile ), os .ModePerm )
51
-
52
- file , _ := os .Create (fullPathFile )
53
- defer file .Close ()
54
- _ , _ = file .Write (result )
55
- }
56
-
57
- func (j MetricsJob ) MetricsCollect (baseFolder string , cs * metricsClient.Clientset ) {
17
+ func (j Job ) Collect (dc * data_collector.DataCollector ) {
58
18
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
59
19
defer cancel ()
60
- result := j .RetrieveFunction (cs , ctx )
61
20
62
- fullPathFile := path .Join (baseFolder , j .OutputFile )
63
- os .MkdirAll (path .Dir (fullPathFile ), os .ModePerm )
21
+ jobResults := j .Execute (dc , ctx )
64
22
65
- file , _ := os .Create (fullPathFile )
66
- defer file .Close ()
67
- _ , _ = file .Write (result )
23
+ for fileName , fileValue := range jobResults {
24
+ os .MkdirAll (path .Dir (fileName ), os .ModePerm )
25
+ file , _ := os .Create (fileName )
26
+ _ , _ = file .Write (fileValue )
27
+ file .Close ()
28
+ }
68
29
}
0 commit comments