/
connect_agent.go
56 lines (47 loc) · 1.7 KB
/
connect_agent.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
package provisioning
import (
"time"
"github.com/kyma-project/control-plane/components/provisioner/internal/model"
"github.com/kyma-project/control-plane/components/provisioner/internal/operations"
"github.com/kyma-project/control-plane/components/provisioner/internal/runtime"
"github.com/sirupsen/logrus"
)
type ConnectAgentStep struct {
runtimeConfigurator runtime.Configurator
dynamicKubeconfigProvider DynamicKubeconfigProvider
nextStage model.OperationStage
timeLimit time.Duration
}
func NewConnectAgentStep(
configurator runtime.Configurator,
dynamicKubeconfigProvider DynamicKubeconfigProvider,
nextStage model.OperationStage,
timeLimit time.Duration) *ConnectAgentStep {
return &ConnectAgentStep{
runtimeConfigurator: configurator,
dynamicKubeconfigProvider: dynamicKubeconfigProvider,
nextStage: nextStage,
timeLimit: timeLimit,
}
}
func (s *ConnectAgentStep) Name() model.OperationStage {
return model.ConnectRuntimeAgent
}
func (s *ConnectAgentStep) TimeLimit() time.Duration {
return s.timeLimit
}
func (s *ConnectAgentStep) Run(cluster model.Cluster, _ model.Operation, _ logrus.FieldLogger) (operations.StageResult, error) {
var kubeconfig []byte
{
var err error
kubeconfig, err = s.dynamicKubeconfigProvider.FetchFromRequest(cluster.ClusterConfig.Name)
if err != nil {
return operations.StageResult{Stage: s.Name(), Delay: 20 * time.Second}, nil
}
}
err := s.runtimeConfigurator.ConfigureRuntime(cluster, string(kubeconfig))
if err != nil {
return operations.StageResult{}, err.Append("failed to configure Runtime Agent")
}
return operations.StageResult{Stage: s.nextStage, Delay: 0}, nil
}