Skip to content

Commit

Permalink
Skipping get kubeconfig step for KIM driven plans
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-pieszka committed Aug 22, 2024
1 parent eda7925 commit bb4fb96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/broker/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func NewProvisioningProcessingQueue(ctx context.Context, provisionManager *proce
},
{ // TODO: this step must be removed when kubeconfig is created by IM only
stage: createRuntimeStageName,
step: provisioning.NewGetKubeconfigStep(db.Operations(), provisionerClient),
step: provisioning.NewGetKubeconfigStep(db.Operations(), provisionerClient, cfg.Broker.KimConfig),
},
{ // TODO: this step must be removed when kubeconfig is created by IM and own_cluster plan is permanently removed
disabled: cfg.LifecycleManagerIntegrationDisabled,
Expand Down
11 changes: 10 additions & 1 deletion internal/process/provisioning/get_kubeconfig_step.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provisioning

import (
"github.com/kyma-project/kyma-environment-broker/internal/kim"

Check failure on line 4 in internal/process/provisioning/get_kubeconfig_step.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
"time"

"github.com/kyma-project/kyma-environment-broker/internal/broker"
Expand All @@ -16,13 +17,16 @@ type GetKubeconfigStep struct {
provisionerClient provisioner.Client
operationManager *process.OperationManager
provisioningTimeout time.Duration
kimConfig kim.Config
}

func NewGetKubeconfigStep(os storage.Operations,
provisionerClient provisioner.Client) *GetKubeconfigStep {
provisionerClient provisioner.Client,
kimConfig kim.Config) *GetKubeconfigStep {
return &GetKubeconfigStep{
provisionerClient: provisionerClient,
operationManager: process.NewOperationManager(os),
kimConfig: kimConfig,
}
}

Expand All @@ -34,6 +38,11 @@ func (s *GetKubeconfigStep) Name() string {

func (s *GetKubeconfigStep) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) {

if s.kimConfig.IsDrivenByKimOnly(broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID]) {
log.Infof("KIM is driving the process for plan %s, skipping", broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID])
return operation, 0, nil
}

if operation.Kubeconfig == "" {
if broker.IsOwnClusterPlan(operation.ProvisioningParameters.PlanID) {
operation.Kubeconfig = operation.ProvisioningParameters.Parameters.Kubeconfig
Expand Down
14 changes: 10 additions & 4 deletions internal/process/provisioning/get_kubeconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provisioning

import (
"github.com/kyma-project/kyma-environment-broker/internal/kim"

Check failure on line 4 in internal/process/provisioning/get_kubeconfig_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
"testing"

"github.com/kyma-project/kyma-environment-broker/internal"
Expand All @@ -21,6 +22,11 @@ const (
)

func TestGetKubeconfigStep(t *testing.T) {

kimConfig := kim.Config{
Enabled: false,
}

t.Run("should create k8s client using kubeconfig from RuntimeStatus", func(t *testing.T) {
// given
st := storage.NewMemoryStorage()
Expand All @@ -29,7 +35,7 @@ func TestGetKubeconfigStep(t *testing.T) {
scheme := internal.NewSchemeForTests(t)
err := apiextensionsv1.AddToScheme(scheme)

step := NewGetKubeconfigStep(st.Operations(), provisionerClient)
step := NewGetKubeconfigStep(st.Operations(), provisionerClient, kimConfig)
operation := fixture.FixProvisioningOperation("operation-id", "inst-id")
operation.Kubeconfig = ""
err = st.Operations().InsertOperation(operation)
Expand All @@ -56,7 +62,7 @@ func TestGetKubeconfigStep(t *testing.T) {
scheme := internal.NewSchemeForTests(t)
err := apiextensionsv1.AddToScheme(scheme)

step := NewGetKubeconfigStep(st.Operations(), nil)
step := NewGetKubeconfigStep(st.Operations(), nil, kimConfig)
operation := fixture.FixProvisioningOperation("operation-id", "inst-id")
operation.Kubeconfig = ""
operation.ProvisioningParameters.Parameters.Kubeconfig = kubeconfigContentsFromParameters
Expand All @@ -79,7 +85,7 @@ func TestGetKubeconfigStep(t *testing.T) {
scheme := internal.NewSchemeForTests(t)
err := apiextensionsv1.AddToScheme(scheme)

step := NewGetKubeconfigStep(st.Operations(), nil)
step := NewGetKubeconfigStep(st.Operations(), nil, kimConfig)
operation := fixture.FixProvisioningOperation("operation-id", "inst-id")
operation.Kubeconfig = kubeconfigFromPreviousOperation
operation.ProvisioningParameters.Parameters.Kubeconfig = ""
Expand All @@ -102,7 +108,7 @@ func TestGetKubeconfigStep(t *testing.T) {
scheme := internal.NewSchemeForTests(t)
err := apiextensionsv1.AddToScheme(scheme)

step := NewGetKubeconfigStep(st.Operations(), provisionerClient)
step := NewGetKubeconfigStep(st.Operations(), provisionerClient, kimConfig)
operation := fixture.FixProvisioningOperation("operation-id", "inst-id")
operation.Kubeconfig = ""
operation.RuntimeID = ""
Expand Down

0 comments on commit bb4fb96

Please sign in to comment.