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

status-manager, Fix bad compare of status #1031

Merged
merged 1 commit into from
Oct 5, 2021

Conversation

RamLavi
Copy link
Collaborator

@RamLavi RamLavi commented Sep 29, 2021

When comparing statuses to see if the status has changed, there is a bug
since oldStatus is a pointer and config.Status is not, hence the
DeepEqual() will always return true

Note that this fix will not reduce status issues, since the heartbeat of statuses Degraded and Available are updated every reconcile.

What this PR does / why we need it:

Special notes for your reviewer:

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Sep 29, 2021
@RamLavi
Copy link
Collaborator Author

RamLavi commented Sep 29, 2021

/cherry-pick release-0.58

@phoracek do we want to cherry-pick to other stable branches?

@kubevirt-bot
Copy link
Collaborator

@RamLavi: once the present PR merges, I will cherry-pick it on top of release-0.58 in a new PR and assign it to you.

In response to this:

/cherry-pick release-0.58

@phoracek do we want to cherry-pick to other stable branches?

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.

@RamLavi
Copy link
Collaborator Author

RamLavi commented Sep 29, 2021

/retest

@oshoval
Copy link
Collaborator

oshoval commented Sep 29, 2021

DeepEqual() will always return true

you mean false maybe ?

Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

Looks like there are better ways to do this.

@@ -178,7 +178,7 @@ func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...condi
// Failing condition had been replaced by Degraded in 0.12.0, drop it from CR if needed
conditionsv1.RemoveStatusCondition(&config.Status.Conditions, conditionsv1.ConditionType("Failing"))

if reflect.DeepEqual(oldStatus, config.Status) {
if reflect.DeepEqual(*oldStatus, config.Status) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about using what is proposed here ? kubernetes-sigs/kubebuilder#592 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

interesting! will try

Copy link
Collaborator Author

@RamLavi RamLavi Sep 30, 2021

Choose a reason for hiding this comment

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

ok, so I compared the two, and although for most cases it will act the same, in some it will not, in a way that is not suitable for this case.
the reason is that DeepDerivative ignores unset parameters (see example), which is good for comparing configuration specs, but not good for comparing statuses.

Although we don't really "remove" conditions, only change them, I don't think it's better than DeepEqual for this particular case, so let's keep it :)

This is an example of how it works (this unit tests passes)

Context("LALALA", func() {
		status1 := shared.NetworkAddonsConfigStatus{}
		status2 := shared.NetworkAddonsConfigStatus{}
		It("RI!!", func() {
			Expect(equality.Semantic.DeepDerivative(status1, status2)).To(BeTrue(), "1.1")
			Expect(equality.Semantic.DeepDerivative(status2, status1)).To(BeTrue(), "1.2")

			status1.Conditions = []conditionsv1.Condition{}
			Expect(equality.Semantic.DeepDerivative(status1, status2)).To(BeTrue(), "2.1")
			Expect(equality.Semantic.DeepDerivative(status2, status1)).To(BeTrue(), "2.2")

			status1.Conditions = []conditionsv1.Condition{
				conditionsv1.Condition{Reason: "simple diff"},
			}
			Expect(equality.Semantic.DeepDerivative(status1, status2)).To(BeFalse(), "3.1")
			Expect(equality.Semantic.DeepDerivative(status2, status1)).To(BeTrue(), "3.2")
		})
	})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we encapsulate this into a function that expect proper types? Also check if we are doing the same at other parts of the code and use that function, or similar. This is the kind of things that are super difficult to find if something is failing, this kind of unsafe code has to be encapsulated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we encapsulate this into a function that expect proper types?

can you explain? I'm not sure I understand your concern.

btw we don't use reflect.DeepEqual() anywhere else on CNAO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ohhh now I get what you mean and why you asked this.. I was on another plane hehe, sure will do

Copy link
Collaborator Author

@RamLavi RamLavi Oct 4, 2021

Choose a reason for hiding this comment

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

since shared.NetworkAddonsConfigStatus is defined on pkg/apis/shared/networkaddonsconfig_types.go, do you think it's ok to add the function there? I worry that this file might break operator-sdk scripts there

Is it ok if I add a function on statusManager? (status *StatusManager) statusDeepEqual(oldStatus, newStatus cnao.NetworkAddonsConfigStatus) bool

Copy link
Collaborator

@qinqon qinqon Oct 5, 2021

Choose a reason for hiding this comment

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

We can add at "shared" package whatever we want, we don't have to add the functions to _types.go we can add a _operators.go, also the "shared" stuff was right at the moment but looks like it's not the actual patter at operator-sdk/kubebuilder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll open a networkaddonsconfig_operators.go on cluster-network-addons-operator/pkg/apis/networkaddonsoperator/shared/

pff.. well let deal with it one dish at a time :) I'll open an issue to align with operator-sdk/kubebuilder

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed here

@RamLavi
Copy link
Collaborator Author

RamLavi commented Sep 30, 2021

/retest

When comparing statuses to see if the status has changed, there is a bug
since oldStatus is a pointer and config.Status is not, hence the
DeepEqual() will always return true.
Encapsulate the comparing to a function to prevent this type of mistake
from happening.

Signed-off-by: Ram Lavi <ralavi@redhat.com>
@sonarcloud
Copy link

sonarcloud bot commented Oct 5, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2021
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qinqon

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 5, 2021
@kubevirt-bot kubevirt-bot merged commit cdcd653 into kubevirt:main Oct 5, 2021
@kubevirt-bot
Copy link
Collaborator

@RamLavi: new pull request created: #1034

In response to this:

/cherry-pick release-0.58

@phoracek do we want to cherry-pick to other stable branches?

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
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants