Skip to content

Commit

Permalink
logic but doubts remain
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-pieszka committed Sep 17, 2024
1 parent 8ea3498 commit f5a1044
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/broker/deprovisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewDeprovisioningProcessingQueue(ctx context.Context, workersAmount int, de
step: deprovisioning.NewCheckGardenerClusterDeletedStep(db.Operations(), cli),
},
{
step: deprovisioning.NewRemoveRuntimeStep(db.Operations(), db.Instances(), provisionerClient, cfg.Provisioner.DeprovisioningTimeout, cfg.Broker.KimConfig),
step: deprovisioning.NewRemoveRuntimeStep(db.Operations(), db.Instances(), provisionerClient, cli, cfg.Provisioner.DeprovisioningTimeout),
},
{
step: deprovisioning.NewCheckRuntimeRemovalStep(db.Operations(), db.Instances(), provisionerClient, cfg.Provisioner.DeprovisioningTimeout),
Expand Down
21 changes: 16 additions & 5 deletions internal/process/deprovisioning/remove_runtime.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package deprovisioning

import (
"context"
"fmt"

Check failure on line 5 in internal/process/deprovisioning/remove_runtime.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"

"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr"
Expand All @@ -20,17 +24,17 @@ type RemoveRuntimeStep struct {
operationManager *process.OperationManager
instanceStorage storage.Instances
provisionerClient provisioner.Client
k8sClient client.Client
provisionerTimeout time.Duration
kimConfig broker.KimConfig
}

func NewRemoveRuntimeStep(os storage.Operations, is storage.Instances, cli provisioner.Client, provisionerTimeout time.Duration, kimConfig broker.KimConfig) *RemoveRuntimeStep {
func NewRemoveRuntimeStep(os storage.Operations, is storage.Instances, cli provisioner.Client, k8sClient client.Client, provisionerTimeout time.Duration) *RemoveRuntimeStep {
return &RemoveRuntimeStep{
operationManager: process.NewOperationManager(os),
instanceStorage: is,
provisionerClient: cli,
provisionerTimeout: provisionerTimeout,
kimConfig: kimConfig,
k8sClient: k8sClient,
}
}

Expand All @@ -39,8 +43,15 @@ func (s *RemoveRuntimeStep) Name() string {
}

func (s *RemoveRuntimeStep) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) {
if s.kimConfig.IsDrivenByKimOnly(broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID]) {
log.Infof("Only KIM is driving the process for plan %s, skipping", broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID])

var runtime = imv1.Runtime{}
err := s.k8sClient.Get(context.Background(), client.ObjectKey{Name: operation.GetRuntimeResourceName(), Namespace: operation.GetRuntimeResourceNamespace()}, &runtime)
if err != nil && !errors.IsNotFound(err) {
log.Warnf("Unable to read runtime: %s", err)
return s.operationManager.RetryOperation(operation, err.Error(), err, 5*time.Second, 1*time.Minute, log)
}
if !(errors.IsNotFound(err) || runtime.IsControlledByProvisioner()) {
log.Infof("Skipping the step because the runtime %s/%s is not controlled by the provisioner", operation.GetRuntimeResourceName(), operation.GetRuntimeResourceName())
return operation, 0, nil
}

Expand Down
16 changes: 9 additions & 7 deletions internal/process/deprovisioning/remove_runtime_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package deprovisioning

import (
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"k8s.io/client-go/kubernetes/scheme"

"sigs.k8s.io/controller-runtime/pkg/client/fake"

Check failure on line 7 in internal/process/deprovisioning/remove_runtime_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

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

"github.com/kyma-project/kyma-environment-broker/internal/broker"

"github.com/kyma-project/kyma-environment-broker/internal/fixture"
provisionerAutomock "github.com/kyma-project/kyma-environment-broker/internal/provisioner/automock"
"github.com/kyma-project/kyma-environment-broker/internal/storage"
Expand All @@ -16,16 +18,16 @@ import (
func TestRemoveRuntimeStep_Run(t *testing.T) {
t.Run("Should repeat process when deprovisioning call to provisioner succeeded", func(t *testing.T) {
// given
err := imv1.AddToScheme(scheme.Scheme)
assert.NoError(t, err)
log := logrus.New()
memoryStorage := storage.NewMemoryStorage()
kcpClient := fake.NewClientBuilder().WithRuntimeObjects(fixRuntimeResource("runtime-id", "kcp-system")).Build()

kimConfig := broker.KimConfig{
Enabled: false,
}
operation := fixture.FixDeprovisioningOperation(fixOperationID, fixInstanceID)
operation.GlobalAccountID = fixGlobalAccountID
operation.RuntimeID = fixRuntimeID
err := memoryStorage.Operations().InsertDeprovisioningOperation(operation)
err = memoryStorage.Operations().InsertDeprovisioningOperation(operation)
assert.NoError(t, err)

err = memoryStorage.Instances().Insert(fixInstanceRuntimeStatus())
Expand All @@ -34,7 +36,7 @@ func TestRemoveRuntimeStep_Run(t *testing.T) {
provisionerClient := &provisionerAutomock.Client{}
provisionerClient.On("DeprovisionRuntime", fixGlobalAccountID, fixRuntimeID).Return(fixProvisionerOperationID, nil)

step := NewRemoveRuntimeStep(memoryStorage.Operations(), memoryStorage.Instances(), provisionerClient, time.Minute, kimConfig)
step := NewRemoveRuntimeStep(memoryStorage.Operations(), memoryStorage.Instances(), provisionerClient, kcpClient, time.Minute)

// when
entry := log.WithFields(logrus.Fields{"step": "TEST"})
Expand Down
2 changes: 1 addition & 1 deletion internal/process/update/upgrade_shoot_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *UpgradeShootStep) Run(operation internal.Operation, log logrus.FieldLog
return s.operationManager.RetryOperation(operation, err.Error(), err, 5*time.Second, 1*time.Minute, log)
}
if !runtime.IsControlledByProvisioner() {
log.Infof("Skipping provisioning because the runtime is not controlled by the provisioner")
log.Infof("Skipping because the runtime is not controlled by the provisioner")
return operation, 0, nil
}

Expand Down

0 comments on commit f5a1044

Please sign in to comment.