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

Conversation

jaroslaw-pieszka
Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka commented Jul 17, 2024

Description

Changes proposed in this pull request:

  • Step calculating Kyma Resource name using step.KymaName method as a single point of truth, the value is used to update the operation
  • removal of no longer needed CreateKymaForOwnCluster step

Related issue(s)

#791
#905

@jaroslaw-pieszka jaroslaw-pieszka requested a review from a team as a code owner July 17, 2024 11:26
@jaroslaw-pieszka jaroslaw-pieszka self-assigned this Jul 17, 2024
@kyma-bot kyma-bot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 17, 2024
@jaroslaw-pieszka jaroslaw-pieszka added kind/enhancement Categorizes issue or PR as related to modifying or improving an existing feature and removed cla: yes Indicates the PR's author has signed the CLA. labels Jul 17, 2024
Copy link

Add one of following labels

- kind/feature -> Use it when you want to submit a new feature

- kind/enhancement -> Use it when you modify or improve an existing feature

- kind/bug -> Use it when you fix a bug

@kyma-bot kyma-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cla: yes Indicates the PR's author has signed the CLA. labels Jul 17, 2024

// 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.

{
condition: provisioning.SkipForOwnClusterPlan,
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)

@@ -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 s.operationManager.OperationFailed(operation, fmt.Sprint("RuntimeID not set, cannot create Kyma name"), nil, log)
}

operation.KymaResourceName = steps.CreateKymaNameFromOperation(operation)
Copy link
Member

Choose a reason for hiding this comment

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

this line should be inside the inline function in the UpdateOperation

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

operation.KymaResourceName = steps.CreateKymaNameFromOperation(operation)

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

}

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.

@@ -58,7 +58,8 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log logrus
return operation, 0, nil
}

kymaResourceName, kymaResourceNamespace := getKymaNames(operation)
kymaResourceName := steps.KymaRuntimeResourceName(operation)
Copy link
Member

@piotrmiskiewicz piotrmiskiewicz Jul 18, 2024

Choose a reason for hiding this comment

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

once, we set the KymaName in the previous step, we can just rely on an operation field, like namespace (one line below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in the next commit.

@@ -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.

@kyma-bot kyma-bot added the lgtm Looks good to me! label Jul 18, 2024
@kyma-bot kyma-bot added the lgtm Looks good to me! label Jul 18, 2024
@kyma-bot kyma-bot merged commit 9461f9b into kyma-project:main Jul 18, 2024
24 of 28 checks passed
@jaroslaw-pieszka jaroslaw-pieszka deleted the valid-kyma-name-and-namespace branch July 18, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. kind/enhancement Categorizes issue or PR as related to modifying or improving an existing feature lgtm Looks good to me! size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants