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

fix: workload rollout spec is invalid template is not empty #1224

Merged
merged 2 commits into from
Jun 3, 2021

Conversation

huikang
Copy link
Member

@huikang huikang commented May 27, 2021

Signed-off-by: Hui Kang [email protected]

close #1222

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
  • The title of the PR is (a) conventional, (b) states what changed, and (c) suffixes the related issues number. E.g. "fix(controller): Updates such and such. Fixes #1234".
  • I've signed my commits with DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My builds are green. Try syncing with master if they are not.
  • My organization is added to USERS.md.

@huikang
Copy link
Member Author

huikang commented May 27, 2021

@jessesuen , after some investigation, I found that

func (c *rolloutContext) getRolloutValidationErrors() error {
does not return any error in this scenario.

The check could be placed during resolving the workload ref for the first time. Is there any corner case the fix does not cover?

@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #1224 (5427383) into master (ff65b39) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1224   +/-   ##
=======================================
  Coverage   81.29%   81.30%           
=======================================
  Files         106      106           
  Lines        9522     9527    +5     
=======================================
+ Hits         7741     7746    +5     
  Misses       1256     1256           
  Partials      525      525           
Impacted Files Coverage Δ
pkg/apis/rollouts/validation/validation.go 90.44% <100.00%> (+0.18%) ⬆️
rollout/temlateref.go 88.18% <100.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff65b39...5427383. Read the comment docs.

@huikang huikang force-pushed the 1222-fix-invalid-ref-spec branch 5 times, most recently from 0eb921f to 67ce1b0 Compare May 27, 2021 15:49
@jessesuen
Copy link
Member

@huikang - the original problem was that it was possible for a user to make a mistake in the spec (using my example) without that error surfacing into a condition (there was no update to status). And so the user did not know why the rollout was stuck. Will this fix solve that?

@huikang
Copy link
Member Author

huikang commented May 28, 2021

@huikang - the original problem was that it was possible for a user to make a mistake in the spec (using my example) without that error surfacing into a condition (there was no update to status). And so the user did not know why the rollout was stuck. Will this fix solve that?

I am not sure if I understand your question.

With the PR, if the uses submits a rollout like your example, the get rollout will show the following error

Name:            rollouts-demo-canary
Namespace:       default
Status:          ✖ Degraded
Message:         InvalidSpec: The Rollout "rollouts-demo-canary" is invalid: template must be empty for workload reference rollout

Since the change occurs to Resolve(), it surfaces into a condition.

To prevent the user makes a mistake, do you mean change is suppose to throw an error when user submit the manifest (or even using kubectl-argo-rollouts lint)?

Comment on lines +128 to +133
// When workloadRef is resolved for the first time, TemplateResolvedFromRef = false.
// In this case, template must not be set
if !rollout.Spec.TemplateResolvedFromRef && !rollout.Spec.EmptyTemplate() {
return fmt.Errorf("template must be empty for workload reference rollout")
}

Copy link
Member

Choose a reason for hiding this comment

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

Instead of in here, can we put this in validation library so that the linter can catch the problem?

Copy link
Member Author

@huikang huikang May 29, 2021

Choose a reason for hiding this comment

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

Updated. The method is moved to validation package. However, lint still can not catch the problem as it reports the following error.

Error: spec.template.spec.containers: Required value

Please see the test case I added to validation_test.go. During reconciliation time, since the template.spec.containers is filled by clientset.Get(), validation method will only report this error -template must be empty for workload reference rollout.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi, @jessesuen , the validation are placed in both Resolve and ValidateRolloutSpec method. In ValidateRolloutSpec, an additional condition (!rollout.Spec.TemplateResolvedFromRef) is added because during reconciliation template is filled prior to validation; otherwise it results in false alarm.

An e2e test is added.

@jessesuen
Copy link
Member

I am not sure if I understand your question.
With the PR, if the uses submits a rollout like your example, the get rollout will show the following error

Yes, this answers my question! With the original problem, the rollout status field was never populated by the controller.

@huikang huikang force-pushed the 1222-fix-invalid-ref-spec branch 6 times, most recently from 4caf48b to 5a1551f Compare May 29, 2021 03:54
- Check lables and annotations of the template for workloadRef
- Add e2e test

Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the 1222-fix-invalid-ref-spec branch 6 times, most recently from d9d1962 to e8e4493 Compare May 29, 2021 06:06
@huikang huikang force-pushed the 1222-fix-invalid-ref-spec branch from e8e4493 to 5427383 Compare May 29, 2021 06:18
@sonarcloud
Copy link

sonarcloud bot commented May 29, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jessesuen jessesuen merged commit d9d1237 into argoproj:master Jun 3, 2021
caoyang001 pushed a commit to caoyang001/argo-rollouts that referenced this pull request Jun 12, 2021
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.

InvalidSpec not properly set in some circumstances
2 participants