Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting valid Kyma Resource Name in a new step #937

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/broker/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func NewProvisioningProcessingQueue(ctx context.Context, provisionManager *proce
stage: createRuntimeStageName,
step: provisioning.NewGenerateRuntimeIDStep(db.Operations(), db.RuntimeStates(), db.Instances()),
},
// postcondition: operation.RuntimeID is set
{
condition: provisioning.SkipForOwnClusterPlan,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not need this condition, it should wokr also for own cluster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next commit.

Copy link
Contributor Author

@jaroslaw-pieszka jaroslaw-pieszka Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then tests for OwnCluster fail.
Need to investigate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed no longer needed step.

stage: createRuntimeStageName,
step: provisioning.NewCreateKymaNameStep(db.Operations()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this steps going to do anything else? For now it feels like it is just doing one assignment? I do not think that it is necessary to create a new step for such assignment. Maybe we could put that in initialisation step or somewhere else?

Copy link
Contributor Author

@jaroslaw-pieszka jaroslaw-pieszka Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we decided to proceed after discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this approach is justified, if you have doubts we can arrange a meeting tomorrow.
Some pros:

  • simple logic,
  • postcondition guaranteed,
  • easy to manage in the process of migration from Provisioner to KIM - we will remove some steps gradually
  • easy to extend
  • easy to test

Currently we have a lot of quite complex steps, and it is hard to grasp what is set where, could we remove step, could we add a new one, and where to put it, to have all required data i to provide all required data for subsequent steps.

Copy link
Member

@piotrmiskiewicz piotrmiskiewicz Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the question is where we should put this assignment. What are hard requirements? Such assignment (logic, which calculates the Kyma resoruce name) must:

  1. be executed after runtime ID gathering/generation (after interaction with Provisioner)
  2. be before Runtime CR creation which must be before ApplyKyma step (currently the logic is in the apply kyma step)

@ralikio - I know this logic is very simple, but we can't put it into initialisation step or something like this (it is too early).
We can't put it into a provisioner interaction step (we gather runtime ID there), because this step will be removed soon or even sometimes the provisioner interaction is not executed (own cluster plan)

},
// postcondition: operation.KymaResourceName is set
{
condition: provisioning.SkipForOwnClusterPlan,
stage: createRuntimeStageName,
Expand Down
46 changes: 46 additions & 0 deletions internal/process/provisioning/create_kyma_name_step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package provisioning

import (
"fmt"
"time"

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

"github.com/kyma-project/kyma-environment-broker/internal"
"github.com/kyma-project/kyma-environment-broker/internal/process"
"github.com/kyma-project/kyma-environment-broker/internal/storage"
"github.com/sirupsen/logrus"
)

type CreateKymaNameStep struct {
operationManager *process.OperationManager
}

func NewCreateKymaNameStep(os storage.Operations) *CreateKymaNameStep {
return &CreateKymaNameStep{
operationManager: process.NewOperationManager(os),
}
}

func (s *CreateKymaNameStep) Name() string {
return "Create_Kyma_Name"
}

func (s *CreateKymaNameStep) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) {
if time.Since(operation.UpdatedAt) > CreateRuntimeTimeout {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we do not need to check any timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in the next commit.

log.Infof("operation has reached the time limit: updated operation time: %s", operation.UpdatedAt)
return s.operationManager.OperationFailed(operation, fmt.Sprintf("operation has reached the time limit: %s", CreateRuntimeTimeout), nil, log)
}

if operation.RuntimeID == "" {
return s.operationManager.OperationFailed(operation, fmt.Sprint("RuntimeID not set, cannot create Kyma name"), nil, log)
}

// could be simplified but this provides single source of truth for Kyma name
operation.KymaResourceName = ""
operation.KymaResourceName = steps.KymaName(operation)
Copy link
Member

@ralikio ralikio Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that duplicated assignment intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is what comment is about.

Copy link
Contributor Author

@jaroslaw-pieszka jaroslaw-pieszka Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In effect this makes this simple assignment:
operation.KymaResourceName=strings.ToLower(operation.RuntimeID)
But using always steps.KymaName we ensure consistence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why line 40 is required. I guess it is just to force KymaResourceName to be empty so that steps.KymaName for sure sets it to RuntimeId. Is that correct? It seems confusing because we need to get into details of invoked method when analysing what the empty assignment is all about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same feeling. It seems awkward. I need to reconsider this with @piotrmiskiewicz if this is what we wanted and if we have to pay such a price for this single point of truth.
I would prefer to change steps.KymaName() semantics and avoid emptying the operation.KymaResourceName.
But this function is already used exactly in this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it slightly in the next commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to eat a cake and have a cake. Please take a look.


return s.operationManager.UpdateOperation(operation, func(op *internal.Operation) {
op.RuntimeID = operation.RuntimeID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not need to update RuntimeID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next commit

}, log)
}
65 changes: 65 additions & 0 deletions internal/process/provisioning/create_kyma_name_step_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package provisioning

import (
"testing"

"github.com/kyma-project/kyma-environment-broker/internal/fixture"
"github.com/kyma-project/kyma-environment-broker/internal/storage"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestCreateKymaNameStep_HappyPath(t *testing.T) {
// given
log := logrus.New()
memoryStorage := storage.NewMemoryStorage()

preOperation := fixture.FixProvisioningOperation(operationID, instanceID)
err := memoryStorage.Operations().InsertOperation(preOperation)
assert.NoError(t, err)

err = memoryStorage.Instances().Insert(fixInstance())
assert.NoError(t, err)

step := NewCreateKymaNameStep(memoryStorage.Operations())

// when
entry := log.WithFields(logrus.Fields{"step": "TEST"})
postOperation, backoff, err := step.Run(preOperation, entry)

// then
assert.NoError(t, err)
assert.Zero(t, backoff)
assert.Equal(t, preOperation.RuntimeID, postOperation.RuntimeID)
assert.Equal(t, postOperation.KymaResourceName, preOperation.RuntimeID)
assert.Equal(t, postOperation.KymaResourceNamespace, "kyma-system")
_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
assert.NoError(t, err)

}

func TestCreateKymaNameStep_NoRuntimeID(t *testing.T) {
// given
log := logrus.New()
memoryStorage := storage.NewMemoryStorage()

preOperation := fixture.FixProvisioningOperation(operationID, instanceID)

preOperation.RuntimeID = ""

err := memoryStorage.Operations().InsertOperation(preOperation)
assert.NoError(t, err)

err = memoryStorage.Instances().Insert(fixInstance())
assert.NoError(t, err)

step := NewCreateKymaNameStep(memoryStorage.Operations())

// when
entry := log.WithFields(logrus.Fields{"step": "TEST"})
_, backoff, err := step.Run(preOperation, entry)

// then
assert.ErrorContains(t, err, "RuntimeID not set, cannot create Kyma name")
assert.Zero(t, backoff)
}
4 changes: 4 additions & 0 deletions internal/process/steps/lifecycle_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func KymaName(operation internal.Operation) string {
return strings.ToLower(operation.RuntimeID)
}

func KymaRuntimeResourceName(operation internal.Operation) string {
Copy link
Member

@ralikio ralikio Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this method used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to create single point of truth for Runtime Resource as well. I will add invocation in next commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to add invocation in separate PR, but it is more consistent if I add it here.

return strings.ToLower(operation.RuntimeID)
}

func KymaNameFromInstance(instance *internal.Instance) string {
return strings.ToLower(instance.RuntimeID)
}
Expand Down
Loading