/
infraexporter.go
43 lines (37 loc) · 1.5 KB
/
infraexporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package infra
import (
"github.com/RHEcosystemAppEng/SaaSi/exporter/exporter-lib/config"
"github.com/RHEcosystemAppEng/SaaSi/exporter/exporter-lib/connect"
"github.com/RHEcosystemAppEng/SaaSi/exporter/exporter-lib/export/utils"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
type InfraExporter struct {
infraContext *InfraContext
}
type InfraExporterOutput struct {
Uid string `json:"uid"`
ClusterId string `json:"clusterId"`
Status string `json:"status"`
ErrorMessage string `json:"errorMessage"`
Location string `json:"location"`
}
func NewInfraExporterFromConfig(config *config.Config, clusterConfig *config.ClusterConfig, connectionStatus *connect.ConnectionStatus, logger *logrus.Logger) *InfraExporter {
exporter := InfraExporter{infraContext: NewInfraContextFromConfig(config, clusterConfig, connectionStatus, logger)}
return &exporter
}
func (e *InfraExporter) Export() InfraExporterOutput {
output := InfraExporterOutput{ClusterId: e.infraContext.clusterConfig.ClusterId}
output.Uid = uuid.New().String()
e.infraContext.InitClusterFolderForUid(output.Uid)
err := utils.RunCommandAndLog(e.infraContext.Logger(), e.infraContext.ExportScript, "-k", e.infraContext.KubeConfigPath(),
"-i", e.infraContext.clusterConfig.ClusterId, "-r", e.infraContext.ClusterFolder)
if err != nil {
output.ErrorMessage = err.Error()
output.Status = utils.Failed.String()
} else {
output.Status = utils.Ok.String()
output.Location = e.infraContext.ClusterFolder
}
return output
}