github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/upgrade_kyma/get_kubeconfig_step.go (about) 1 package upgrade_kyma 2 3 import ( 4 "time" 5 6 "github.com/sirupsen/logrus" 7 8 "github.com/kyma-project/kyma-environment-broker/internal" 9 "github.com/kyma-project/kyma-environment-broker/internal/process" 10 "github.com/kyma-project/kyma-environment-broker/internal/provisioner" 11 "github.com/kyma-project/kyma-environment-broker/internal/storage" 12 ) 13 14 type GetKubeconfigStep struct { 15 provisionerClient provisioner.Client 16 operationManager *process.UpgradeKymaOperationManager 17 provisioningTimeout time.Duration 18 } 19 20 func NewGetKubeconfigStep(os storage.Operations, 21 provisionerClient provisioner.Client) *GetKubeconfigStep { 22 return &GetKubeconfigStep{ 23 provisionerClient: provisionerClient, 24 operationManager: process.NewUpgradeKymaOperationManager(os), 25 } 26 } 27 28 var _ Step = (*GetKubeconfigStep)(nil) 29 30 func (s *GetKubeconfigStep) Name() string { 31 return "Get_Kubeconfig" 32 } 33 34 func (s *GetKubeconfigStep) Run(operation internal.UpgradeKymaOperation, log logrus.FieldLogger) (internal.UpgradeKymaOperation, time.Duration, error) { 35 if operation.Kubeconfig != "" { 36 operation.InputCreator.SetKubeconfig(operation.Kubeconfig) 37 return operation, 0, nil 38 } 39 if operation.Runtime.RuntimeID == "" { 40 log.Errorf("Runtime ID is empty") 41 return s.operationManager.OperationFailed(operation, "Runtime ID is empty", nil, log) 42 } 43 44 status, err := s.provisionerClient.RuntimeStatus(operation.ProvisioningParameters.ErsContext.GlobalAccountID, operation.Runtime.RuntimeID) 45 if err != nil { 46 log.Errorf("call to provisioner RuntimeStatus failed: %s", err.Error()) 47 return operation, 1 * time.Minute, nil 48 } 49 50 if status.RuntimeConfiguration.Kubeconfig == nil || *status.RuntimeConfiguration.Kubeconfig == "" { 51 log.Errorf("kubeconfig is not provided") 52 return operation, 1 * time.Minute, nil 53 } 54 operation.Kubeconfig = *status.RuntimeConfiguration.Kubeconfig 55 k := *status.RuntimeConfiguration.Kubeconfig 56 log.Infof("kubeconfig details length: %v", len(k)) 57 if len(k) < 10 { 58 log.Errorf("kubeconfig suspiciously small, requeueing after 30s") 59 return operation, 30 * time.Second, nil 60 } 61 62 newOperation, retry, _ := s.operationManager.UpdateOperation(operation, func(operation *internal.UpgradeKymaOperation) { 63 operation.Kubeconfig = *status.RuntimeConfiguration.Kubeconfig 64 }, log) 65 if retry > 0 { 66 log.Errorf("unable to update operation") 67 return operation, time.Second, nil 68 } 69 70 newOperation.InputCreator.SetKubeconfig(newOperation.Kubeconfig) 71 72 return newOperation, 0, nil 73 }