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

feat: add workload-ref/generation to rollout #1198

Merged
merged 5 commits into from
Jul 7, 2021

Conversation

huikang
Copy link
Member

@huikang huikang commented May 19, 2021

  • Add a "rollout.argoproj.io/workload-generation" annotation to
    the rollout metadata, which equals to the generation of reference
    workload
  • workload-generation is updated when the referenced workload is
    updated.
  • status.workloadObservedGeneration records the observed generation
    of the rollout
  • e2e test is updated

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

close #1189

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 huikang marked this pull request as draft May 19, 2021 04:19
@huikang huikang force-pushed the fix-workloadRef-generation branch from 0e35cf2 to 34a6cb1 Compare May 19, 2021 04:34
@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #1198 (d803ca0) into master (460262e) will increase coverage by 0.01%.
The diff coverage is 85.93%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1198      +/-   ##
==========================================
+ Coverage   81.37%   81.38%   +0.01%     
==========================================
  Files         106      106              
  Lines        9721     9776      +55     
==========================================
+ Hits         7910     7956      +46     
- Misses       1273     1279       +6     
- Partials      538      541       +3     
Impacted Files Coverage Δ
rollout/temlateref.go 83.67% <68.96%> (-4.52%) ⬇️
rollout/sync.go 76.42% <100.00%> (+0.32%) ⬆️
utils/annotations/annotations.go 97.02% <100.00%> (+0.68%) ⬆️
utils/rollout/rolloututil.go 88.23% <100.00%> (+1.79%) ⬆️
rollout/controller.go 78.35% <0.00%> (ø)

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 460262e...d803ca0. Read the comment docs.

@huikang huikang force-pushed the fix-workloadRef-generation branch 2 times, most recently from a0b9d1d to 2ebd1ae Compare May 19, 2021 15:40
@huikang huikang marked this pull request as ready for review May 19, 2021 15:40
@huikang huikang force-pushed the fix-workloadRef-generation branch 6 times, most recently from 5ad3f4c to df74692 Compare May 20, 2021 16:07
@sonarqubecloud
Copy link

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
17.0% 17.0% Duplication

@huikang
Copy link
Member Author

huikang commented May 20, 2021

Hi, @jessesuen , this PR is ready for review. (I was trying to increase the test coverage, but still fall short of the required target. Please provide any advice if you have. Thanks.)

@jessesuen
Copy link
Member

Thanks for working on this. Will be taking a look at this in the coming days.

@jessesuen
Copy link
Member

@alexmt thinks there might be a better way to address the issue. I will ask him to put an alternative proposal in the issue.

@huikang
Copy link
Member Author

huikang commented May 26, 2021

@alexmt thinks there might be a better way to address the issue. I will ask him to put an alternative proposal in the issue.

Sounds good. Will follow up the thread.

@jessesuen
Copy link
Member

@alexmt thinks there might be a better way to address the issue. I will ask him to put an alternative proposal in the issue.
Sounds good. Will follow up the thread.

I checked in with @alexmt about this again. He gave it some more thought but didn't have a better proposal. So we will go with the original improvement as discussed in the issue.

Copy link
Member

@jessesuen jessesuen left a comment

Choose a reason for hiding this comment

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

Change looks very good. Some minor points

Comment on lines 254 to 262
if key, err := cache.MetaNamespaceKeyFunc(ro); err == nil {
r.rolloutWorkQueue.Add(key)
}
Copy link
Member

Choose a reason for hiding this comment

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

There's actually no need to enqueue the rollout to r.rolloutWorkQueue anymore with this new approach because the act of annotating the rollout automatically gets the rollout into the workqueue. I think we should remove these three lines because we may be operating on the rollout prematurely (where the annotation is not reflected in the rollout), which could cause ConflictErrors during reconciliation.

Can we remove these lines?

		if key, err := cache.MetaNamespaceKeyFunc(ro); err == nil {
			r.rolloutWorkQueue.Add(key)
		}

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct. Thanks for the explanation.

Copy link
Member Author

@huikang huikang Jul 1, 2021

Choose a reason for hiding this comment

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

HI, @jessesuen , I tested remove the above 3 lines. However, the unit test failed at

require.False(t, done)
assert.Equal(t, "default/my-rollout", item)

The Get() does not return any object. I think this is because the test code uses argoprojectclientset := fake.Clientset{}. Any advice?

Copy link
Member

Choose a reason for hiding this comment

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

I think test needs to be modified since we no longer update workqueue directly. So I think this part of test can be removed as well.

Maybe in place of this, we verify the rollout was annotated.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. Will change the test to verify annotation is added.

Copy link
Member

Choose a reason for hiding this comment

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

In fact, can we remove the rolloutWorkQueue field entirely from NewInformerBasedWorkloadRefResolver?

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 , I updated the test to verifying the annotations are added for the rollout. However, it looks like the test clientset can't turn interface{} to rollout. Could you help to test a look?

https://github.com/argoproj/argo-rollouts/pull/1198/files#diff-52c4f59609dee33fdeab90f1c17716000fca7922b7524c4e718e114cc1e41afdR243

test/e2e/canary_test.go Outdated Show resolved Hide resolved
Hui Kang added 2 commits June 30, 2021 23:21
- Add a "rollout.argoproj.io/workload-generation" annotation to
  the rollout metadata, which equals to the generation of reference
  workload
- workload-generation is updated when the referenced workload is
  updated.
- status.workloadObservedGeneration records the observed generation
  of the rollout
- workloadref e2e test is update

Signed-off-by: Hui Kang <[email protected]>
- fix proto number after rebase

Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the fix-workloadRef-generation branch 2 times, most recently from 8d7fcfd to 9d51b8e Compare July 1, 2021 03:50
@huikang huikang force-pushed the fix-workloadRef-generation branch 3 times, most recently from d3a5abf to bb5ad39 Compare July 2, 2021 05:11
for _, ro := range rollouts {
if key, err := cache.MetaNamespaceKeyFunc(ro); err == nil {
r.rolloutWorkQueue.Add(key)
un, ok := ro.(*unstructured.Unstructured)
Copy link
Member Author

@huikang huikang Jul 2, 2021

Choose a reason for hiding this comment

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

@jessesuen , in the e2e test, the ro can be mappted to *unstructured.Unstructured without any issue (so the e2e test passed). However, in the unit test code, the rollout can't be resolved. Do you have any idea about this? Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, to reproduce: go test -timeout 999s -run ^TestRequeueReferencedRollouts$ ./rollout -v

@huikang huikang force-pushed the fix-workloadRef-generation branch 2 times, most recently from 8bd3ab6 to f2d24f4 Compare July 2, 2021 15:35
@huikang huikang force-pushed the fix-workloadRef-generation branch from f2d24f4 to e7ceecc Compare July 2, 2021 15:45
…ange

- doc update: migration.md
- Remove the workqueue of informerBasedTemplateResolver

Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the fix-workloadRef-generation branch from e7ceecc to ab451dc Compare July 2, 2021 17:41
Comment on lines 48 to 58
func isWorkloadGenerationObserved(ro *v1alpha1.Rollout) bool {
if _, ok := annotations.GetWorkloadGenerationAnnotation(ro); !ok {
return true
}
workloadGeneration, _ := annotations.GetWorkloadGenerationAnnotation(ro)
observedWorkloadGen, err := strconv.Atoi(ro.Status.WorkloadObservedGeneration)
if err != nil {
return true
}

return int32(observedWorkloadGen) == workloadGeneration
Copy link
Member

Choose a reason for hiding this comment

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

  1. The code scanner is catching a valid concern with the use of strconv.Atoi. We should use strconv.ParseInt(ro.Status.WorkloadObservedGeneration, 10, 32) instead

  2. I just noticed that we may not handle the case properly where we still may have a workloadGenerationAnnotation on the rollout (leftover from when it switched from workload to non-workload ref) even if rollout switched to using inline template.

I think this function needs to check if ro.Spec.WorkloadRef != nil before proceeding. At the same time, I think we should remove the workload generation annotation from the rollout, since I don't think that gets cleaned up at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback. The PR is updated and an e2e test case is added to verify the workload generation annotation is removed after it switches to inline template.

@huikang huikang force-pushed the fix-workloadRef-generation branch 3 times, most recently from 10e2d89 to 990c469 Compare July 3, 2021 03:37
@huikang huikang force-pushed the fix-workloadRef-generation branch 5 times, most recently from 48149d5 to adb1264 Compare July 5, 2021 17:53
Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the fix-workloadRef-generation branch from adb1264 to d803ca0 Compare July 5, 2021 23:41
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 5, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jessesuen jessesuen merged commit 2339ddc into argoproj:master Jul 7, 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.

workloadRef rollouts should record status.workloadObservedGeneration
2 participants