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

ConfigMap as a ValueSource in Param in TaskRuns and PipelineRuns #8642

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mostafaCamel
Copy link

  • Added a new field ValueSource to v1.Param
  • Added validation to v1 CRD for Param and ParamValue based on a new feature flga enable-valuefrom-in-param
  • Added new methods to the reconciler in order to resolve these vallue sources during the first reconcile then upate the k8s resource
  • Added documentation and integration tests for the new feature
  • Fixed preexisting unit tests that were failing before the new validation (the params in the test cases were set up incorrectly)

Changes

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

- Added a new field ValueSource to v1.Param
- Added validation to v1 CRD for Param and ParamValue based on a new feature flga `enable-valuefrom-in-param`
- Added new methods to the reconciler in order to resolve these vallue sources during the first reconcile then upate the k8s resource
- Added documentation and integration tests for the new feature
- Fixed preexisting unit tests that were failing before the new validation (the params in the test cases were set up incorrectly)

Signed-off-by: Mostafa Abdelwahab <[email protected]>
@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesnt merit a release note. labels Mar 12, 2025
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 12, 2025
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign vdemeester after the PR has been reviewed.
You can assign the PR to them by writing /assign @vdemeester in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mostafaCamel
Copy link
Author

Related discussion about the feature #1744
(Unmerged) TEP tektoncd/community#1189

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/config/feature_flags.go 95.2% 95.2% 0.1
pkg/apis/pipeline/v1/param_types.go 98.9% 99.0% 0.1
pkg/apis/pipeline/v1/pipeline_validation.go 99.3% 99.0% -0.2
pkg/apis/pipeline/v1/pipelinerun_types.go 92.5% 93.1% 0.7
pkg/apis/pipeline/v1/pipelinerun_validation.go 94.7% 94.7% 0.1
pkg/apis/pipeline/v1/taskrun_types.go 82.8% 85.1% 2.3
pkg/apis/pipeline/v1/taskrun_validation.go 97.4% 97.5% 0.0
pkg/reconciler/pipelinerun/pipelinerun.go 91.7% 89.8% -2.0
pkg/reconciler/taskrun/resources/apply.go 99.4% 98.9% -0.5
pkg/reconciler/taskrun/taskrun.go 86.1% 83.8% -2.3

@mostafaCamel
Copy link
Author

mostafaCamel commented Mar 12, 2025

Few notes:

  • After I rebased my branch from main, ko apply -R -f config/ started to fail and I had to use ko create -R -f config/ (with the usual caveats/disadvantages of using create and not being able to iterate new changes with apply subsequently)
The CustomResourceDefinition "taskruns.tekton.dev" is invalid: metadata.annotations: Too long: may not be more than 262144 bytes
Error: error executing 'kubectl apply': exit status 1

This is probably due to the recent script change of adding the OpenAPI schema to the CRD yamls

${REPO_ROOT_DIR}/hack/update-schemas.sh

  • While writing integration tests, I realized the new feature is not working for inline parameters. This is due to the following function createParamSpecFromParam which expects a Param to have a Type during validation (which is not the case for parameters with value sources) What I could do is to change the behavior of this function so that it defaults to Type string when populating a ParamSpec from a param with ValueSource
    func createParamSpecFromParam(p Param, paramSpecForValidation map[string]ParamSpec) map[string]ParamSpec {

@mostafaCamel
Copy link
Author

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 12, 2025
@mostafaCamel
Copy link
Author

There are many files in the PR. Here are the "entrypoints" of the code changes

@waveywaves
Copy link
Member

/assign

@waveywaves
Copy link
Member

@mostafaCamel can this PR be broken down into multiple smaller PRs? maybe add this feature initially to taskruns and then in another PR to pipeline runs ? also, I see that the related TEP is not merged and hasn't had any discussion (at least in the comments on github). It would be advisable to discuss this in the community call as well if you would like to move this along faster. Thank you for the early PR though, definitely helps the community to understand the feature from a technical standpoint a lot better.

@waveywaves
Copy link
Member

Just skimmed through #1744 and have better context of this. It would be good to merge the TEP and move it to implementable state before we get back to the PR.

@mostafaCamel
Copy link
Author

mostafaCamel commented Mar 13, 2025

Sounds good. Thanks Vibhav. I can wait until the TEP is merged then will break down the PR. I can also further break it into a pull request for api/ webhook validation (which will also generate the swagger and openapi changes), then a PR for taskrun reconciler (+ integration tests) then a PR for pipelinerun reconciler (+integration tests ) and a final PR for documentation

@@ -690,3 +693,21 @@ type PipelineTaskRunTemplate struct {
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// returns true if the RunSpecs are different in params (by value source resolution only) and deeply eual otherwise
func (baseline *PipelineRunSpec) IsDifferentFromDesiredStateOnlyByValueSourceResolutionInParams(new *PipelineRunSpec) bool {
Copy link
Author

Choose a reason for hiding this comment

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

This is my first PR to this repo so I am not sure if I should create a go interface with DeepCopy() and other methods and fields used here so that I avoid duplicating the code. There is a method that does the same thing for TaskRunSpec https://github.com/tektoncd/pipeline/pull/8642/files#diff-f6f395c4b788e7dad3da4c944d41e8b7e03540f0b49735417423ade04da8462bR532

FeatureFlags: &config.FeatureFlags{EnableValueFromInParam: tc.enableValueFromInParam},
Defaults: &config.Defaults{},
})
err := v1.ValidateParameters(ctx, tc.params)
Copy link
Author

Choose a reason for hiding this comment

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

Ideally I would have tested in this unit test that the method ValidateValueAndValueSourceInEachParam was called but go does not provide mocks (unlike python)

https://github.com/tektoncd/pipeline/pull/8642/files#diff-e6ceebad50db85ba0dae540a07832bc1692e39213e8592a2d9c3099cdd25fbf0R293

if err != nil {
return nil, fmt.Errorf("failed to marshal Params patch bytes: %w", err)
}
return c.PipelineClientSet.TektonV1().PipelineRuns(pr.Namespace).Patch(ctx, pr.Name, types.JSONPatchType, patchParamBytes, metav1.PatchOptions{}, "")
Copy link
Author

Choose a reason for hiding this comment

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

I haven't been able to unit test the reconciler changes because of Patch: the unit test was failing with requeue after: 27969h18m22.144989s . When I tried to use Update instead, the unit test failed with Returned an error {"targetMethod": "ReconcileKind", "error": "Operation cannot be fulfilled on taskruns.tekton.dev \"test-task-param-run-valuesource-patch\": resourceVersion mismatch, got: 00001, wanted: 00003"}

I probably need to fix this testing behavior to add support for patching / non-status Update in

return func(action ktesting.Action) (bool, runtime.Object, error) {

t.Fatalf("Succeeded in creating PipelineRun `%s` with valuesource in params even though the feature flag is turned off", pipelineRun.Name)
}

updateConfigMap(ctx, c.KubeClient, system.Namespace(), config.GetFeatureFlagsConfigName(), map[string]string{
Copy link
Author

Choose a reason for hiding this comment

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

I am assuming that this does not affect other integration tests due to the teardown procedure + there is already a separate namespace per integration test anyways

@@ -20,8 +20,6 @@ metadata:
spec:
params:
- name: message
enum: ["v1", "v2"]
Copy link
Author

Choose a reason for hiding this comment

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

Changed made by mistake. I will undo it in my next amended commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. release-note-none Denotes a PR that doesnt merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants