-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix ValidateStepResultsVariables to validate stepResults only #8264
Open
jkhelil
wants to merge
1
commit into
tektoncd:main
Choose a base branch
from
jkhelil:fix_validateTaskResultsVariables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: StepAction | ||
metadata: | ||
name: step-action | ||
spec: | ||
params: | ||
- name: message | ||
type: string | ||
env: | ||
- name: message | ||
value: $(params.message) | ||
image: mirror.gcr.io/bash | ||
script: | | ||
#!/usr/bin/env bash | ||
echo ${message} | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: reference-step-result-in-step- | ||
spec: | ||
taskSpec: | ||
description: | | ||
A simple task to demonstrate how to reference a step result in another step when used alongside with task result | ||
results: | ||
- name: resultsDir | ||
type: string | ||
steps: | ||
- name: collect | ||
image: mirror.gcr.io/bash | ||
results: | ||
- name: message | ||
type: string | ||
script: | | ||
#!/usr/bin/env sh | ||
set -x | ||
message="scott" | ||
|
||
echo -n "${message}" > $(step.results.message.path) | ||
echo -n "tom" > $(results.resultsDir.path) | ||
- name: reduce | ||
params: | ||
- name: message | ||
value: $(steps.collect.results.message) | ||
ref: | ||
name: step-action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The fact that you have to remove this test here highlights another problem in the current codebase.
You want to fix an issue in how we validate an inline step in a
Task
definition, and this has a side effect on the validation of aStepAction
, which should not happen.In the
task-stepaction-results.yaml
example that you provided, an inline step references to aTask
result, which is valid and should work, and doesn't work today, which is the problem that needs to be fixed.This stems from the fact that
ValidateStepResultsVariables
does not have enough context to validateTask
level references, which are validated instead byValidateTaskResultsVariables
as you mentioned.The change you proposed, however, modifies code used for validation of
StepActions
, which is not ok, as exemplified by the test you removed, which should continue to pass. The author of aStepAction
has no knowledge about theTasks
that may use it, and should not reference any variable outside of the known context.A correct fix for the issue should include, on top of the fix already done, a change in the
stepaction_validation
code, which, instead of usingValidateStepResultsVariables
from the task validation, should define its ownValidateStepActionResultsVariables
, which should look like whatValidateStepResultsVariables
looks today.Unit tests should not be removed and we should make sure we have a unit tests that validates
ValidateTaskResultsVariables
(which we most likely already have).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.
@afrittoli I think you're right to add ValidateStepActionResultsVariables that validates step results only because it has only the step results context and hence i removed the snippet of tests there (we dont have the task result context when using stepAction.Validate)
I am also fixing ValidateStepResultsVariables to add task results in the function args so we can validate the step script against both step and task result because we have them in context as this method is now only called in task validation context
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.
@afrittoli Can you have a look to my comment pleae
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.
@jkhelil Sorry about the late reply.
The proposed fix is not ok. Quoting my previous comment:
The validation of
StepActions
should remain the same and its tests should also remain the same as they are correct. The problem stems from the fact that theTasks
validation function is also used to validateStepActions
and it enforces validation that is only required forStepActions
.A correct fix would be to have two different validation functions:
ValidateStepActionResultsVariables
, which should look like whatValidateStepResultsVariables
looks today (before this PR)ValidateStepResultsVariables
, which should be fixed, like you have done in this PR, to enforce validation that is appropriate for TasksIf you did that, then you would not need to remove any unit tests.