forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
119 lines (94 loc) · 3.61 KB
/
core.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package steps
import (
"log"
"os/exec"
"path"
"strings"
"github.com/kyma-project/kyma/components/installer/pkg/config"
"github.com/kyma-project/kyma/components/installer/pkg/consts"
"github.com/kyma-project/kyma/components/installer/pkg/overrides"
)
const kymaPath = "/kyma"
//InstallCore .
func (steps InstallationSteps) InstallCore(installationData *config.InstallationData) error {
const stepName string = "Installing core"
steps.PrintInstallationStep(stepName)
steps.statusManager.InProgress(stepName)
chartDir := path.Join(steps.chartDir, consts.CoreComponent)
coreOverrides := steps.getCoreOverrides(installationData, chartDir)
installResp, installErr := steps.helmClient.InstallRelease(
chartDir,
"kyma-system",
consts.CoreComponent,
coreOverrides)
if steps.errorHandlers.CheckError("Install Error: ", installErr) {
steps.statusManager.Error(stepName)
logCore(steps)
return installErr
}
steps.helmClient.PrintRelease(installResp.Release)
log.Println(stepName + "...DONE")
return nil
}
//UpgradeCore .
func (steps InstallationSteps) UpgradeCore(installationData *config.InstallationData) error {
const stepName string = "Upgrading core"
steps.PrintInstallationStep(stepName)
steps.statusManager.InProgress(stepName)
chartDir := path.Join(steps.chartDir, consts.CoreComponent)
coreOverrides := steps.getCoreOverrides(installationData, chartDir)
upgradeResp, upgradeErr := steps.helmClient.UpgradeRelease(
chartDir,
consts.CoreComponent,
coreOverrides)
if steps.errorHandlers.CheckError("Upgrade Error: ", upgradeErr) {
steps.statusManager.Error(stepName)
logCore(steps)
return upgradeErr
}
steps.helmClient.PrintRelease(upgradeResp.Release)
log.Println(stepName + "...DONE")
return nil
}
//Legacy stuff from old build scripts.
//TODO: Provide such logs for every step
func logCore(steps InstallationSteps) {
//Try to display debug data in case of failure
status, statusErr := steps.helmClient.ReleaseStatus("core")
if statusErr != nil {
log.Println("Cannot get release status: ", statusErr)
} else {
log.Println("core status: \n" + status)
}
logFailedResources("kyma-system")
}
func logFailedResources(ns string) {
path := path.Join(kymaPath, "installation/scripts/utils.sh")
log.Println("\nLooking for failed resources in namespace: " + ns)
cmd := exec.Command("/bin/bash", "-c", "source "+path+"; showFailedResources "+ns)
msg, scriptErr := cmd.Output()
if scriptErr != nil {
log.Printf("An error occurred while running script: %s (%s)\n", string(msg[:]), scriptErr)
return
}
log.Println(string(msg[:]))
}
func (steps *InstallationSteps) getCoreOverrides(installationData *config.InstallationData, chartDir string) string {
var allOverrides []string
globalOverrides, err := overrides.GetGlobalOverrides(installationData)
steps.errorHandlers.LogError("Couldn't get global overrides: ", err)
allOverrides = append(allOverrides, globalOverrides)
azureBrokerOverrides, err := overrides.EnableAzureBroker(installationData)
steps.errorHandlers.LogError("Enable azure-broker Error: ", err)
allOverrides = append(allOverrides, azureBrokerOverrides)
coreOverrides, err := overrides.GetCoreOverrides(installationData)
steps.errorHandlers.LogError("Couldn't get Kyma core overrides: ", err)
allOverrides = append(allOverrides, coreOverrides)
fileOverrides := steps.getStaticFileOverrides(installationData, chartDir)
if fileOverrides.HasOverrides() == true {
fileOverridesStr, err := fileOverrides.GetOverrides()
steps.errorHandlers.LogError("Couldn't get additional overrides: ", err)
allOverrides = append(allOverrides, *fileOverridesStr)
}
return strings.Join(allOverrides, "\n")
}