Repository navigation
fix(api): prevent unnecessary default values in options field - #4158
Pranaysaha2 wants to merge 1 commit into
Conversation
Replace strongly-typed Kubernetes objects in AdditionalOptions with runtime.RawExtension to preserve only user-specified fields. This prevents automatic population of zero values (creationTimestamp, maxReplicas:0, etc.) that users never intended. Changes: - Modified AdditionalOptions struct to use runtime.RawExtension - Updated transformer functions to unmarshal RawExtension - Updated test files to use toRawExtension() helper - Temporarily disabled transformer_additional_options_test.go (will be re-enabled in follow-up PR after full conversion) Fixes tektoncd#2001
|
@Pranaysaha2: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
@divyansh42 @enarha can you please review my pull request? |
|
@Pranaysaha2 before we review further, we need clearer human verification on this PR. This looks like a large API/behavior change (RawExtension migration, tests disabled, size/XXL), and we are seeing a lot of agent-authored PRs where the submitter cannot explain or own the change. Please reply in your own words (not a paste of the issue/PR template) with:
Until that is answered, please do not ping reviewers for approval. |
|
/hold |
|
@jkhelil, I have added my response.
Specifically, when a user provides partial YAML like: When user submits the YAML to API server, YAML converts to JSON. Kubernetes API server receives this JSON and need to validate this against CRD scheme. And Unmarshal it into the Go struct defined in additional_options.go During unmarshal, Go allocates memory for the entire struct, initializing ALL fields.
Earlier, the API server unmarshal into HorizontalPodAutoscaler struct, after that API server marshal for storage. In the transformer code transformer_additional_options.go, hpaOptions has zero values, but we NEVER write this back to the CR, it only use it to update the manifest resources.
|
Summary
Fixes #2001 by replacing strongly-typed Kubernetes objects in
AdditionalOptionswithruntime.RawExtension, which preserves only user-specified fields.Problem
When users create a TektonConfig CR with
options, the system auto-generates unnecessary default values for unspecified fields (e.g.,metadata.creationTimestamp: null,maxReplicas: 0, emptyscaleTargetRef).Solution
AdditionalOptionsfield types from typed K8s objects toruntime.RawExtensionRawExtensionwhen processingChanges
pkg/apis/operator/v1alpha1/additional_options.go- Useruntime.RawExtensionpkg/reconciler/common/transformer_additional_options.go- Unmarshal logictoRawExtension()helper and updated 6 test filestransformer_additional_options_test.gotemporarily disabled during migrationTesting
Example
Before: