@@ -60,16 +60,16 @@ type DataCollector struct {
60
60
ExcludeTimeSeriesData bool
61
61
}
62
62
63
- func NewDataCollector (namespaces ... string ) ( * DataCollector , error ) {
63
+ func NewDataCollector (collector * DataCollector ) error {
64
64
65
65
tmpDir , err := os .MkdirTemp ("" , "-pkg-diag" )
66
66
if err != nil {
67
- return nil , fmt .Errorf ("unable to create temp directory: %s" , err )
67
+ return fmt .Errorf ("unable to create temp directory: %s" , err )
68
68
}
69
69
70
70
logFile , err := os .OpenFile (filepath .Join (tmpDir , "supportpkg.log" ), os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
71
71
if err != nil {
72
- return nil , fmt .Errorf ("unable to create log file: %s" , err )
72
+ return fmt .Errorf ("unable to create log file: %s" , err )
73
73
}
74
74
75
75
// Find config
@@ -80,30 +80,27 @@ func NewDataCollector(namespaces ...string) (*DataCollector, error) {
80
80
config , err := clientcmd .BuildConfigFromFlags ("" , kubeConfig )
81
81
82
82
if err != nil {
83
- return nil , fmt .Errorf ("unable to connect to k8s using file %s: %s" , kubeConfig , err )
84
- }
85
-
86
- dc := DataCollector {
87
- BaseDir : tmpDir ,
88
- Namespaces : namespaces ,
89
- LogFile : logFile ,
90
- Logger : log .New (logFile , "" , log .LstdFlags | log .LUTC | log .Lmicroseconds | log .Lshortfile ),
91
- K8sHelmClientSet : make (map [string ]helmClient.Client ),
83
+ return fmt .Errorf ("unable to connect to k8s using file %s: %s" , kubeConfig , err )
92
84
}
85
+ // Set up the DataCollector options
86
+ collector .BaseDir = tmpDir
87
+ collector .LogFile = logFile
88
+ collector .Logger = log .New (logFile , "" , log .LstdFlags | log .LUTC | log .Lmicroseconds | log .Lshortfile )
89
+ collector .K8sHelmClientSet = make (map [string ]helmClient.Client )
93
90
94
91
//Initialize clients
95
- dc .K8sRestConfig = config
96
- dc .K8sCoreClientSet , _ = kubernetes .NewForConfig (config )
97
- dc .K8sCrdClientSet , _ = crdClient .NewForConfig (config )
98
- dc .K8sMetricsClientSet , _ = metricsClient .NewForConfig (config )
99
- for _ , namespace := range dc .Namespaces {
100
- dc .K8sHelmClientSet [namespace ], _ = helmClient .NewClientFromRestConf (& helmClient.RestConfClientOptions {
92
+ collector .K8sRestConfig = config
93
+ collector .K8sCoreClientSet , _ = kubernetes .NewForConfig (config )
94
+ collector .K8sCrdClientSet , _ = crdClient .NewForConfig (config )
95
+ collector .K8sMetricsClientSet , _ = metricsClient .NewForConfig (config )
96
+ for _ , namespace := range collector .Namespaces {
97
+ collector .K8sHelmClientSet [namespace ], _ = helmClient .NewClientFromRestConf (& helmClient.RestConfClientOptions {
101
98
Options : & helmClient.Options {Namespace : namespace },
102
99
RestConfig : config ,
103
100
})
104
101
}
105
102
106
- return & dc , nil
103
+ return nil
107
104
}
108
105
109
106
func (c * DataCollector ) WrapUp (product string ) (string , error ) {
0 commit comments