-
Notifications
You must be signed in to change notification settings - Fork 0
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
add support for reserved default object param #164
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
name: echo-message-pipeline | ||
spec: | ||
params: | ||
- name: hello | ||
properties: | ||
project_id: | ||
type: string | ||
type: object | ||
tasks: | ||
- name: task1 | ||
params: | ||
- name: foo | ||
value: | ||
project_id: $(params.hello.project_id) | ||
taskSpec: | ||
params: | ||
- name: foo | ||
type: object | ||
properties: | ||
project_id: | ||
type: string | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: | | ||
#!/bin/bash | ||
echo $(params.provider.project_id) | ||
echo $(params.foo.project_id) | ||
--- | ||
kind: PipelineRun | ||
apiVersion: tekton.dev/v1 | ||
metadata: | ||
name: test-pipelinerun | ||
spec: | ||
params: | ||
- name: provider | ||
value: | ||
project_id: foo | ||
- name: hello | ||
value: | ||
project_id: foo | ||
pipelineRef: | ||
name: echo-message-pipeline |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
kind: Task | ||
apiVersion: tekton.dev/v1 | ||
metadata: | ||
name: example-task | ||
spec: | ||
params: | ||
- name: foo | ||
type: object | ||
properties: | ||
project_id: | ||
type: string | ||
digest: | ||
type: string | ||
steps: | ||
- image: ubuntu | ||
name: echo | ||
script: | | ||
echo -n $(params.foo.project_id) | ||
echo -n $(params.provider.project_id) | ||
--- | ||
kind: TaskRun | ||
apiVersion: tekton.dev/v1 | ||
metadata: | ||
name: example-tr | ||
spec: | ||
params: | ||
- name: foo | ||
value: | ||
project_id: foo | ||
digest: bar | ||
- name: provider | ||
value: | ||
project_id: foo | ||
digest: bar | ||
taskRef: | ||
name: example-task | ||
kind: task |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,7 @@ func ValidateUsageOfDeclaredParameters(ctx context.Context, steps []Step, params | |
var errs *apis.FieldError | ||
_, _, objectParams := params.SortByType() | ||
allParameterNames := sets.NewString(params.GetNames()...) | ||
allParameterNames.Insert(ReservedParamName) | ||
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. May be here we should check that the 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 check is not done from our side, there will be additional validation out of tekton and we're sure that users cannot declare the param with reserved name. :D 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. (and we cannot do it from out side for some reason... |
||
errs = errs.Also(validateVariables(ctx, steps, "params", allParameterNames)) | ||
errs = errs.Also(validateObjectUsage(ctx, steps, objectParams)) | ||
errs = errs.Also(ValidateObjectParamsHaveProperties(ctx, params)) | ||
|
@@ -762,3 +763,26 @@ func ValidateStepResultsVariables(ctx context.Context, results []StepResult, scr | |
errs = errs.Also(substitution.ValidateNoReferencesToUnknownVariables(script, "results", resultsNames).ViaField("script")) | ||
return errs | ||
} | ||
|
||
// Reserved Param doesn't have properties, so we need to check all the references if they are using a non-existent key from the param | ||
func ValidateReservedParamReferenceMissingKeys(ctx context.Context, steps []Step, params Params) error { | ||
objectKeys := sets.NewString() | ||
// collect all the existent keys from the object reserved param. | ||
for _, p := range params { | ||
if p.Name == ReservedParamName && p.Value.Type == ParamTypeObject { | ||
for key := range p.Value.ObjectVal { | ||
objectKeys.Insert(key) | ||
} | ||
} | ||
} | ||
|
||
// check if the object's key names are referenced correctly i.e. param.objectParam.key1 | ||
if len(objectKeys) > 0 { | ||
err := validateVariables(ctx, steps, fmt.Sprintf("params\\.%s", ReservedParamName), objectKeys) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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.
May be here we should check that the ReservedParamName is not already in the set. If it is then a user also declared it and it should throw an error since it is reserved?