Skip to content

cleanup(reporter): address review follow-ups on unchanged-condition skip - #334

Open
LightCreator1007 wants to merge 9 commits into
kubernetes-sigs:mainfrom
LightCreator1007:cleanup/reporter-idempotency-gate-followup
Open

cleanup(reporter): address review follow-ups on unchanged-condition skip#334
LightCreator1007 wants to merge 9 commits into
kubernetes-sigs:mainfrom
LightCreator1007:cleanup/reporter-idempotency-gate-followup

Conversation

@LightCreator1007

Copy link
Copy Markdown
Contributor

Description

Follow-up to #263, addressing the review comments left open when it merged.

  • Fold the idempotency check into a single early return after the condition search, dropping the needsUpdate flag and the separate transitionTime variable, the split logic was hard to follow.
  • Replace the block comment with line comments (block comments are a Go anti-pattern), and refer to heartbeatPeriod rather than a hardcoded "5 minutes", since the period is configurable.
  • Rename test case State change triggers immediate write to update condition on state change — the immediate write is the outcome, not the cause, and is now noted in a comment.
  • Return a bool instead of an update count from the test helper, collapsing the assertion to one comparison.

No behaviour change.

Related Issue

None

Type of Change

/kind cleanup

Testing

This change is a refactor only.

Checklist

  • make test passes
  • make lint passes

Does this PR introduce a user-facing change?

NONE

@kubernetes-prow kubernetes-prow Bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Aug 1, 2026
@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy Preview for node-readiness-controller ready!

Name Link
🔨 Latest commit 158bfa3
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6a8691cd5e5a7a00084af2b5
😎 Deploy Preview https://deploy-preview-334--node-readiness-controller.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubernetes-prow
kubernetes-prow Bot requested review from dchen1107 and mrunalp August 1, 2026 10:58
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 1, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @LightCreator1007. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 1, 2026
@ajaysundark

Copy link
Copy Markdown
Contributor

Thanks for iterating on this!

/cc @AnuragThePathak as he had the original comments

@kubernetes-prow

Copy link
Copy Markdown

@ajaysundark: GitHub didn't allow me to request PR reviews from the following users: had, the, original, AnuragThePathak, as, he.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

Thanks for iterating on this!

/cc @AnuragThePathak as he had the original comments

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-sigs/prow repository.

@AnuragThePathak AnuragThePathak 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 following up @LightCreator1007 glad you decided not to wrap up the chapter with merging of the original PR.

Comment thread cmd/readiness-condition-reporter/main.go Outdated
Comment thread cmd/readiness-condition-reporter/main.go
@ajaysundark

Copy link
Copy Markdown
Contributor

/cc @AnuragThePathak

@ajaysundark

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 3, 2026
}
}

if !found {

@AnuragThePathak AnuragThePathak Aug 4, 2026

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.

I must admit, this is something I never had my eyes on, and didn't anticipate this change either until I saw this today (the major reason being it was not part of what you changed earlier and existed way before that). This slightly makes me question whether your former approach to use existingCondition was actually better, but considering that involves pointer, and considering simplicity of our current needs I'm approving this.

@AnuragThePathak

Copy link
Copy Markdown
Contributor

/assign @ajaysundark

Comment thread cmd/readiness-condition-reporter/main.go Outdated
@AnuragThePathak

Copy link
Copy Markdown
Contributor

/unassign @ajaysundark
/assign
/assign @LightCreator1007

@AnuragThePathak AnuragThePathak 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.

I have two more suggestions, I see that we are not testing two situations now.

  1. Smoke test for node not found error path
  2. Validation of the LastTransitionTime

Since we spent so much time refactoring, I think working on these two and sealing these two will elevate the standard of this method significantly.


countUpdates := func() int {
n := 0
updateCalled := func() bool {

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.

About this, I gave some thought about this, I think your original approach of counting was better. So please revert this one.

But change the wantUpdateCalled to integer value (update name of that variable too as wantUpdateCalled sounds boolean to anyone).

@DsThakurRawat

Copy link
Copy Markdown
Contributor

Heads up, #367 merged into main about an hour ago and it lands in this same file, so the branch doesn't merge cleanly any more. Checked it against main at d74dabd:

Auto-merging cmd/readiness-condition-reporter/main.go
CONFLICT (content): Merge conflict in cmd/readiness-condition-reporter/main_test.go

main.go is fine. The only conflict is in main_test.go and it's the mechanical kind: both branches appended a new top level test function at the end of the file, so git can't tell which one goes first. main has TestParseDurationWithDefault now, this branch has TestUpdateNodeConditionNodeNotFound.

Keeping both, in either order, clears it. I resolved it that way locally and gofmt, go build ./... and go test ./cmd/readiness-condition-reporter/... all came back clean, so there's nothing behavioural in it.

It might also sort itself out. The review note above suggests folding that case into the existing table rather than keeping a separate test, and if TestUpdateNodeConditionNodeNotFound goes away then so does the conflict.

Sorry about the collision, that was my PR that landed.

@kubernetes-prow kubernetes-prow 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 Aug 9, 2026

@AnuragThePathak AnuragThePathak 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.

Remaining looks good other than the addressed 3

for _, a := range client.Actions() {
if a.GetVerb() == "update" && a.GetSubresource() == "status" && a.GetResource().Resource == "nodes" {
n++
var objs []runtime.Object

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.

            var client *fake.Clientset
			if tt.existingNode != nil {
				client = fake.NewClientset(tt.existingNode)
			} else {
				client = fake.NewClientset()
			}


            var previousTransition metav1.Time
			if tt.existingNode != nil {
				for _, cond := range tt.existingNode.Status.Conditions {
					if string(cond.Type) == conditionType {
						previousTransition = cond.LastTransitionTime
						break
					}
				}
			}
			if previousTransition.IsZero() {
				previousTransition = metav1.NewTime(time.Now())
			}

Decouple client and previousTransition.


err := updateNodeCondition(context.Background(), client, nodeName, conditionType, tt.health, tt.heartbeatPeriod)
if tt.existingNode == nil {
if !apierrors.IsNotFound(err) {

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.

This log/condition won't tell exact failure scenario, as it doesn't differentiate between no error and error being something other than not found.

             if err != nil {
				if tt.wantNotFoundErr {
					if !apierrors.IsNotFound(err) {
						t.Fatalf("updateNodeCondition() error = %v, want a NotFound error", err)
					}
					if got := countUpdateCalls(client); got != tt.wantUpdateCount {
						t.Errorf("UpdateStatus called = %v, want %v", got, tt.wantUpdateCount)
					}
					return
				}
				t.Fatalf("updateNodeCondition() error = %v", err)
			}
			if tt.wantNotFoundErr {
				t.Fatalf("updateNodeCondition() succeeded, want a NotFound error")
			}

Also introduced wantNotFoundErr because inputs in tests are not often expected to remain the same during the runtime most often.

wantStatus corev1.ConditionStatus
wantReason string
wantUpdateCount int
wantTransitionPreserved bool

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.

@LightCreator1007 update this please

@AnuragThePathak AnuragThePathak 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.

@ajaysundark this one looks good to me. Feel free to merge as per release and other convince as no functional change

return n
}
if previousTransition.IsZero() {
previousTransition = metav1.NewTime(time.Now())

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.

nit: it'd be good to base previousTransition to a fixed / deterministic timestamp instead of injecting 'now' as you're using it to comparing later.

@ajaysundark ajaysundark 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.

@LightCreator1007 Thanks for this nice refactor!

added a nit comment (non blocking) if you could find time to update, please consider handling this.

/hold
/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 17, 2026
@kubernetes-prow kubernetes-prow Bot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 17, 2026
@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 19, 2026
@LightCreator1007
LightCreator1007 force-pushed the cleanup/reporter-idempotency-gate-followup branch from edc3734 to 158bfa3 Compare August 20, 2026 05:34
@kubernetes-prow kubernetes-prow Bot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 20, 2026

@ajaysundark ajaysundark 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.

/lgtm

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 20, 2026
@ajaysundark

Copy link
Copy Markdown
Contributor

Thanks @LightCreator1007 @AnuragThePathak !

@AnuragThePathak AnuragThePathak 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.

LGTM with the update on deterministic previousTransistion. We are not exactly testing the equality of time stamp, time.Now() put by the updateNodeCondition, but that should be fine I believe in current situation I think.

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ajaysundark, AnuragThePathak, LightCreator1007

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

The pull request process is described here

Details 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

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants