forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepsfactory.go
72 lines (61 loc) · 1.97 KB
/
stepsfactory.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
package kymainstallation
import (
"errors"
"log"
"github.com/kyma-project/kyma/components/installer/pkg/apis/installer/v1alpha1"
"github.com/kyma-project/kyma/components/installer/pkg/kymahelm"
"github.com/kyma-project/kyma/components/installer/pkg/kymasources"
"github.com/kyma-project/kyma/components/installer/pkg/overrides"
rls "k8s.io/helm/pkg/proto/hapi/release"
)
// StepFactory defines contract for installation steps factory
type StepFactory interface {
NewStep(component v1alpha1.KymaComponent) Step
}
type stepFactory struct {
kymaPackage kymasources.KymaPackage
helmClient kymahelm.ClientInterface
installedReleases map[string]bool
overrideData overrides.OverrideData
}
// NewStep method returns instance of the step based on component details
func (sf stepFactory) NewStep(component v1alpha1.KymaComponent) Step {
step := step{
kymaPackage: sf.kymaPackage,
helmClient: sf.helmClient,
overrideData: sf.overrideData,
component: component,
}
if sf.installedReleases[component.GetReleaseName()] {
return upgradeStep{
step: step,
}
}
return installStep{
step: step,
}
}
// NewStepFactory returns implementation of StepFactory implementation
func NewStepFactory(kymaPackage kymasources.KymaPackage, helmClient kymahelm.ClientInterface, overrideData overrides.OverrideData) (StepFactory, error) {
installedReleases := make(map[string]bool)
relesesRes, err := helmClient.ListReleases()
if err != nil {
return nil, errors.New("Helm error: " + err.Error())
}
if relesesRes != nil {
log.Println("Helm releases list:")
for _, release := range relesesRes.Releases {
statusCode := release.Info.Status.Code
log.Printf("%s status: %s", release.Name, statusCode)
if statusCode == rls.Status_DEPLOYED {
installedReleases[release.Name] = true
}
}
}
return stepFactory{
kymaPackage: kymaPackage,
helmClient: helmClient,
installedReleases: installedReleases,
overrideData: overrideData,
}, nil
}