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

Remove workload, flavor, os labels from templates which have older version #50

Closed

Conversation

ksimon1
Copy link
Member

@ksimon1 ksimon1 commented Nov 25, 2020

What this PR does / why we need it:
remove workload, flavor, os labels from templates which have older version

With labels removed, old templates will no longer be visible in UI.
Which issue(s) this PR fixes:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1859235

Release note:

SSP operator now removes workload, flavor, os labels from templates which have older version

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Nov 25, 2020
@ksimon1 ksimon1 force-pushed the remove-duplicate-labels-templates branch from 84f61b8 to b6637cc Compare November 25, 2020 12:07
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Nov 25, 2020
}
}

return common.ResourceStatus{}, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

@akrejcir, @vatsalparekh what should be returned in this case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For other resources, this return value signals if the resource is still being updated, or if it is in the desired state. If any resource is still updating, the operator will not be in phase deployed.

In this case however, the operator does not own any of the old templates, so I think they should not block the operator from being in deployed state. The return value can be left as is now.

@ksimon1 ksimon1 changed the title [WIP] remove workload, flavor, os labels from templates which have older version Remove workload, flavor, os labels from templates which have older version Nov 26, 2020
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 26, 2020
internal/operands/common-templates/reconcile.go Outdated Show resolved Hide resolved
internal/operands/common-templates/reconcile.go Outdated Show resolved Hide resolved
for _, template := range oldTemplates.Items {
for key := range template.Labels {
if strings.HasPrefix(key, "os.template.kubevirt.io/") || strings.HasPrefix(key, "flavor.template.kubevirt.io/") || strings.HasPrefix(key, "workload.template.kubevirt.io/") {
delete(template.Labels, key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know go allows removing elements from map while iterating over it. Good to know it does, in other languages it is usually not a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be safe operation.
See https://golang.org/ref/spec#For_statements

The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next. If a map entry that has not yet been reached is removed during iteration, the corresponding iteration value will not be produced. If a map entry is created during iteration, that entry may be produced during the iteration or may be skipped. The choice may vary for each entry created and from one iteration to the next. If the map is nil, the number of iterations is 0. 

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it is safe. I just didn't know that before reading this code. I always learn something new.

internal/operands/common-templates/reconcile.go Outdated Show resolved Hide resolved
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign akrejcir
You can assign the PR to them by writing /assign @akrejcir 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

@akrejcir
Copy link
Collaborator

akrejcir commented Dec 3, 2020

Looks good. Do you think this needs a functional test?

@ksimon1
Copy link
Member Author

ksimon1 commented Dec 3, 2020

Looks good. Do you think this needs a functional test?

Yes, but there is already one https://github.com/kubevirt/ssp-operator/blob/master/tests/e2e-test-csv-generator.sh

@akrejcir
Copy link
Collaborator

akrejcir commented Dec 3, 2020

That file only tests CSV generator, not old templates.

@ksimon1
Copy link
Member Author

ksimon1 commented Dec 3, 2020

ah you are right, sorry I posted wrong link

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 4, 2020
@ksimon1 ksimon1 force-pushed the remove-duplicate-labels-templates branch from b00edaf to 68d7164 Compare December 4, 2020 08:10
@kubevirt-bot kubevirt-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 4, 2020
@ksimon1 ksimon1 force-pushed the remove-duplicate-labels-templates branch from 68d7164 to b0acf10 Compare December 7, 2020 12:00
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 7, 2020
Copy link
Collaborator

@akrejcir akrejcir left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

tests/commonTemplates_test.go Outdated Show resolved Hide resolved
tests/commonTemplates_test.go Outdated Show resolved Hide resolved
tests/tests_suite_test.go Outdated Show resolved Hide resolved
…rsion

With labels removed, old templates will no longer be visible in UI.

Signed-off-by: Karel Simon <ksimon@redhat.com>
@ksimon1 ksimon1 force-pushed the remove-duplicate-labels-templates branch from b0acf10 to 2e70ea2 Compare December 7, 2020 18:32
@openshift-merge-robot
Copy link

@ksimon1: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-functests 2e70ea2 link /test e2e-functests
ci/prow/e2e-upgrade-functests 2e70ea2 link /test e2e-upgrade-functests

Full PR test history. Your PR dashboard.

Instructions 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. I understand the commands that are listed here.

@@ -122,4 +127,66 @@ var _ = Describe("Common templates", func() {
table.Entry("[test_id:4770]golden image NS", &goldenImageNS),
)
})

FContext("update old templates", func() {
Copy link
Collaborator

@akrejcir akrejcir Dec 8, 2020

Choose a reason for hiding this comment

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

You forgot to unfocus the test. The CI will fail if any tests are focused.

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2020
@kubevirt-bot
Copy link
Contributor

@ksimon1: PR needs rebase.

Instructions 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.

@vatsalparekh
Copy link

Cloned this PR to #71
/close

@kubevirt-bot
Copy link
Contributor

@vatsalparekh: Closed this PR.

In response to this:

Cloned this PR to #71
/close

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants