-
Notifications
You must be signed in to change notification settings - Fork 22
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
Changes from 5 commits
92934c6
8bd3393
37963af
c93a42b
99423be
71e85b0
508f5b0
5442579
77960ee
4f23965
13649a3
73b33b3
fa5c691
541fede
55163d9
86042a2
f097617
ded3ac2
2f2a8bf
5aa5de7
4c71e45
09a5318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
stage: createRuntimeStageName, | ||
step: provisioning.NewCreateKymaNameStep(db.Operations()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how we decided to proceed after discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #905 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
@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). |
||
}, | ||
// postcondition: operation.KymaResourceName is set | ||
{ | ||
condition: provisioning.SkipForOwnClusterPlan, | ||
stage: createRuntimeStageName, | ||
|
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, we do not need to check any timeout There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that duplicated assignment intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is what comment is about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In effect this makes this simple assignment: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it slightly in the next commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not need to update RuntimeID There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the next commit |
||
}, log) | ||
} |
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) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,10 @@ func KymaName(operation internal.Operation) string { | |
return strings.ToLower(operation.RuntimeID) | ||
} | ||
|
||
func KymaRuntimeResourceName(operation internal.Operation) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this method used? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next commit.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.