/
install_kyma.go
75 lines (62 loc) · 2.57 KB
/
install_kyma.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
package provisioning
import (
"errors"
"fmt"
"time"
"github.com/kyma-incubator/compass/components/provisioner/internal/installation"
"github.com/kyma-incubator/compass/components/provisioner/internal/model"
"github.com/kyma-incubator/compass/components/provisioner/internal/operations"
"github.com/kyma-incubator/compass/components/provisioner/internal/util/k8s"
installationSDK "github.com/kyma-incubator/hydroform/install/installation"
"github.com/sirupsen/logrus"
)
type InstallKymaStep struct {
installationClient installation.Service
nextStep model.OperationStage
timeLimit time.Duration
}
func NewInstallKymaStep(installationClient installation.Service, nextStep model.OperationStage, timeLimit time.Duration) *InstallKymaStep {
return &InstallKymaStep{
installationClient: installationClient,
nextStep: nextStep,
timeLimit: timeLimit,
}
}
func (s *InstallKymaStep) Name() model.OperationStage {
return model.StartingInstallation
}
func (s *InstallKymaStep) TimeLimit() time.Duration {
return s.timeLimit
}
func (s *InstallKymaStep) Run(cluster model.Cluster, _ model.Operation, logger logrus.FieldLogger) (operations.StageResult, error) {
if cluster.Kubeconfig == nil {
return operations.StageResult{}, fmt.Errorf("error: kubeconfig is nil")
}
k8sConfig, err := k8s.ParseToK8sConfig([]byte(*cluster.Kubeconfig))
if err != nil {
return operations.StageResult{}, fmt.Errorf("error: failed to create kubernetes config from raw: %s", err.Error())
}
installationState, err := s.installationClient.CheckInstallationState(k8sConfig)
if err != nil {
installErr := installationSDK.InstallationError{}
if errors.As(err, &installErr) {
logger.Warnf("Installation already in progress, proceeding to next step...")
return operations.StageResult{Stage: s.nextStep, Delay: 0}, nil
}
return operations.StageResult{}, fmt.Errorf("error: failed to check installation state: %s", err.Error())
}
if installationState.State != installationSDK.NoInstallationState {
logger.Warnf("Installation already in progress, proceeding to next step...")
return operations.StageResult{Stage: s.nextStep, Delay: 0}, nil
}
err = s.installationClient.TriggerInstallation(
k8sConfig,
cluster.KymaConfig.Release,
cluster.KymaConfig.GlobalConfiguration,
cluster.KymaConfig.Components)
if err != nil {
return operations.StageResult{}, fmt.Errorf("error: failed to start installation: %s", err.Error())
}
logger.Warnf("Installation started, proceeding to next step...")
return operations.StageResult{Stage: s.nextStep, Delay: 30 * time.Second}, nil
}