Skip to content

Fix #6663: skip auto-inferred trait defaults in .status.traits - #6667

Merged
squakez merged 3 commits into
apache:mainfrom
thedavidweng:fix/6663-status-traits-defaults
Jun 11, 2026
Merged

squakez merged 3 commits into
apache:mainfrom
thedavidweng:fix/6663-status-traits-defaults

Conversation

@thedavidweng

@thedavidweng thedavidweng commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6663

Summary

Previous approach (stopping executed traits from being written to Status.Traits) was incorrect — it broke the feat(api): store executed traits in status contract used by GitOps export and platform/profile propagation.

This revision keeps executed traits in status but stops auto-inferred defaults from leaking into serialized API trait fields (Option B):

  • service trait: auto-detected enabled is carried in a local variable instead of mutating t.Enabled
  • container trait: auto-detected expose is stored in an unexported field; inferred OpenShift RunAsUser is applied to the container security context without writing back to t.RunAsUser
  • trait.Apply: restored merge of executed traits into Status.Traits

Scope

This PR covers the traits called out in #6663 (container, service). Similar auto-writeback patterns exist in knative-service, knative, cron, and master traits and can be addressed in follow-up PRs.

Testing

  • TestAutoInferredServiceTraitsDoNotLeakIntoStatus — HTTP integration creates a Service but Status.Traits stays empty
  • TestUserSpecifiedTraitValuesStillAppearInStatus — user-set container.port is still recorded in status
  • Updated existing tests that previously expected auto-inferred RunAsUser / service.enabled in serialized traits
  • go test ./pkg/trait/... and make lint pass

@thedavidweng
thedavidweng marked this pull request as ready for review June 8, 2026 08:59
Fixes #6663

The integration status was including auto-inferred trait values such as
container.expose and service.enabled that the user never explicitly set.
This happened because executedTraitCondition() serialized all non-zero
fields from the in-memory trait structs (including values set by
auto-detection in Configure()), and the subsequent Merge() with
mergo.WithOverride propagated them into Status.Traits.

Change the Apply() function to only copy Spec.Traits into Status.Traits
without merging the executed traits. This ensures the status only
reflects what the user explicitly configured.
@thedavidweng
thedavidweng force-pushed the fix/6663-status-traits-defaults branch from 4227d7d to d240fb3 Compare June 8, 2026 09:34

@squakez squakez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. However this is completely wrong. Please, make sure to understand the entire logic before applying this again. In theory we should only skip the defaults values not recording them in the API trait type.

@thedavidweng

Copy link
Copy Markdown
Contributor Author

Thanks for the PR. However this is completely wrong. Please, make sure to understand the entire logic before applying this again. In theory we should only skip the defaults values not recording them in the API trait type.

Yeah sorry you're right, my bad for blindly trusting Codex too much.
Now after examining again, I see two ways to implement.
A, compare each executed trait against its default baseline and drop fields equal to the default in executedTraitCondition, before writing them into Status.Traits.
B, carry the auto-inferred state in unexported fields/locals so the exported fields stay nil unless the user set them.

I think option B would be a more thorough approach, but it involves wider changes. What do you think?

@squakez

squakez commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Hello, no problem. Yeah, option B would be the right choice. I think it just affects a couple of fields, at least in the case reported in the issue.

Keep storing executed traits in Integration status, but stop writing
auto-detected defaults back into serialized API trait fields.

- service: use a local enabled flag instead of mutating t.Enabled
- container: store auto expose in an unexported field and stop writing
  inferred RunAsUser into t.RunAsUser during Apply
- restore Status.Traits merge with executed traits in trait.Apply

Fixes #6663
@thedavidweng thedavidweng changed the title fix(trait): stop auto-inferred defaults from leaking into .status.traits Fix #6663: skip auto-inferred trait defaults in .status.traits Jun 9, 2026
@thedavidweng
thedavidweng requested a review from squakez June 9, 2026 23:04

@squakez squakez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some minor changes in one test, the rest is good, thanks!

Comment thread pkg/trait/service_test.go Resolved
Comment thread pkg/trait/service_test.go Resolved
- capture traits return value and assert Service is nil in
  TestServiceWithKnativeServiceDisabledInIntegrationPlatform
- replace conditional check with direct nil assertion in
  TestServiceAutoConfiguration
@thedavidweng

Copy link
Copy Markdown
Contributor Author

Some minor changes in one test, the rest is good, thanks!

Thank you for reviewing, done.

@squakez
squakez merged commit 25479a7 into apache:main Jun 11, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default container and service flags should not appear in .status.traits

3 participants