Skip to content

Conversation

@razo7
Copy link
Member

@razo7 razo7 commented Jan 12, 2025

Why we need this PR

FAR didn't stop the agent execution upon detecting NHC time-out annotation. Now it will do that, and on the next reconciliation fianlizer and taints can be removed (only) when far CR is deleted.

Changes made

Add stop agent execution (stopAgentAndGetCrStatus) function- Stop the agent when NHC time-out annotation (remediation.medik8s.io/nhc-timed-out) exists or when FAR CR has a finalizer and is deleted. The timed-out annotation is set on escalating remediations.

Which issue(s) this PR fixes

ECOPROJECT-2539

Test plan

Summary by CodeRabbit

  • Refactor
    • Improved internal logic for handling fence agent execution and status logging, resulting in clearer and more consistent behavior.
    • Enhanced log messages for better clarity and accuracy.

@openshift-ci openshift-ci bot requested review from clobrano and mshitrit January 12, 2025 16:30
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: razo7

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

Create three function to reconcile logic into smaller usable functions: remove FAR CR finalizer on deletion, remove FAR taint on deletion, and stop agent execution when NHC time out annotation exist or FAR CR was deleted
@razo7 razo7 force-pushed the remove-finalizer-nhc-timeout branch from d545c84 to 06547b1 Compare January 12, 2025 16:30
@razo7 razo7 changed the title Remove finalizer on NHC Timeout deleted FAR CR Remove Finalizer & Taints on NHC Timeout Deleted FAR CR Jan 12, 2025
@razo7
Copy link
Member Author

razo7 commented Jan 13, 2025

/hold

Delete taints and finalizer on the next reconilation
@razo7 razo7 changed the title Remove Finalizer & Taints on NHC Timeout Deleted FAR CR Stop FAR Agent on NHC Timeout Annotation Jan 14, 2025
@razo7
Copy link
Member Author

razo7 commented Jan 14, 2025

/retest

// Check NHC timeout annotation
if isTimedOutByNHC(far) {
// Check NHC timeout annotation and stop the agent, since remediation is no longer relevant (most likely because fixed by a different remediator)
if r.Executor.Exists(far.GetUID()) && isTimedOutByNHC(far) {
Copy link
Member

@slintes slintes Jan 18, 2025

Choose a reason for hiding this comment

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

you add a condition here, and few lines below you change to requeue.... I think that's a significant unwanted change in execution flow, what happens on next reconcile?

@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

The reconciliation logic in the fence agents remediation controller was refactored to extract repeated code for stopping the agent and logging CR status conditions into a new method. Logging was improved for clarity, and comments were updated to accurately describe taint removal. Control flow and error handling remain unchanged.

Changes

File Change Summary
controllers/fenceagentsremediation_controller.go Refactored repeated logic into stopAgentAndGetCrConditionsStatus method; improved logging; updated comments.

Sequence Diagram(s)

sequenceDiagram
    participant Reconciler
    participant FenceAgentExecutor
    participant CR (Custom Resource)
    participant Logger

    Reconciler->>CR: Detects NHC timeout or deletion
    alt Executor exists for CR UID
        Reconciler->>Reconciler: stopAgentAndGetCrConditionsStatus(CR, nodeName)
        Reconciler->>Logger: Log processing and status conditions
        Reconciler->>FenceAgentExecutor: Remove executor by CR UID
    end
    Reconciler->>Logger: Log finalizer removal (using CR name)
Loading

Poem

In the garden of code, a refactor did bloom,
Repeated lines gathered, swept up with a broom.
Now agents stop cleanly, logs clearer and bright,
With comments that guide us, all wording just right.
🐇 Hopping through logic, we keep code in tune!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
controllers/fenceagentsremediation_controller.go (1)

135-142: Consider returning even when no executor is running & rename helper for clarity

  1. The early-exit currently requires r.Executor.Exists(far.GetUID()) to be true.
    If the NHC timeout annotation is present but the executor has already finished, the controller will continue with the rest of the reconciliation logic although the remediation is obsolete. A simpler—and safer—rule is: if NHC timed out ⇒ stop processing.

  2. stopAgentAndGetCrConditionsStatus neither “gets” nor returns any status; it only logs and stops the agent. The name is misleading and makes reviewers search for a returned value.

Example refactor:

- if r.Executor.Exists(far.GetUID()) && isTimedOutByNHC(far) {
+ if isTimedOutByNHC(far) {
+     if r.Executor.Exists(far.GetUID()) {
+         r.stopAgentAndLogCrConditions(far, node.Name)
+     }
      utils.UpdateConditions(utils.RemediationInterruptedByNHC, far, r.Log)
      commonEvents.RemediationStoppedByNHC(r.Recorder, far)
      return requeueImmediately, nil
 }

…and rename the helper accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce57ab4 and e17815f.

📒 Files selected for processing (1)
  • controllers/fenceagentsremediation_controller.go (5 hunks)

Comment on lines +281 to +288
// stopAgentAndGetCrStatus log FAR CR status and stops the agent's parallel execution
func (r *FenceAgentsRemediationReconciler) stopAgentAndGetCrConditionsStatus(far *v1alpha1.FenceAgentsRemediation, nodeName string) {
processingCondition := meta.FindStatusCondition(far.Status.Conditions, commonConditions.ProcessingType).Status
fenceAgentActionSucceededCondition := meta.FindStatusCondition(far.Status.Conditions, utils.FenceAgentActionSucceededType).Status
succeededCondition := meta.FindStatusCondition(far.Status.Conditions, commonConditions.SucceededType).Status
r.Log.Info("FAR agent was stopped", "Node Name", nodeName, "Agent Name", far.Spec.Agent, "processing condition", processingCondition,
"fenceAgentActionSucceeded condition", fenceAgentActionSucceededCondition, "succeeded condition", succeededCondition)
r.Executor.Remove(far.GetUID())
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Nil-pointer panic risk when reading CR conditions

meta.FindStatusCondition returns *metav1.Condition which can be nil when the condition is absent.
Directly dereferencing .Status will panic and crash the controller on the very scenario it tries to handle (e.g., first reconcile where conditions aren’t set).

- processingCondition := meta.FindStatusCondition(far.Status.Conditions, commonConditions.ProcessingType).Status
- fenceAgentActionSucceededCondition := meta.FindStatusCondition(far.Status.Conditions, utils.FenceAgentActionSucceededType).Status
- succeededCondition := meta.FindStatusCondition(far.Status.Conditions, commonConditions.SucceededType).Status
+ var processingStatus, actionSucceededStatus, succeededStatus metav1.ConditionStatus
+
+ if c := meta.FindStatusCondition(far.Status.Conditions, commonConditions.ProcessingType); c != nil {
+     processingStatus = c.Status
+ }
+ if c := meta.FindStatusCondition(far.Status.Conditions, utils.FenceAgentActionSucceededType); c != nil {
+     actionSucceededStatus = c.Status
+ }
+ if c := meta.FindStatusCondition(far.Status.Conditions, commonConditions.SucceededType); c != nil {
+     succeededStatus = c.Status
+ }

This guards against panics while preserving the intended log output.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In controllers/fenceagentsremediation_controller.go around lines 281 to 288, the
code directly dereferences the Status field of the result from
meta.FindStatusCondition without checking for nil, which can cause a nil-pointer
panic if the condition is absent. To fix this, first check if the returned
condition pointer is nil before accessing its Status field; if nil, use a
default value (e.g., an empty string or a specific status) to safely log the
condition status without panicking.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 7, 2025

@razo7: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.15-openshift-e2e e17815f link true /test 4.15-openshift-e2e
ci/prow/4.16-openshift-e2e e17815f link true /test 4.16-openshift-e2e
ci/prow/4.20-images e17815f link true /test 4.20-images
ci/prow/4.20-test e17815f link true /test 4.20-test
ci/prow/4.19-ci-bundle-my-bundle e17815f link true /test 4.19-ci-bundle-my-bundle
ci/prow/4.19-images e17815f link true /test 4.19-images
ci/prow/4.19-test e17815f link true /test 4.19-test
ci/prow/4.20-ci-bundle-my-bundle e17815f link true /test 4.20-ci-bundle-my-bundle
ci/prow/4.20-openshift-e2e e17815f link true /test 4.20-openshift-e2e
ci/prow/4.19-openshift-e2e e17815f link true /test 4.19-openshift-e2e

Full PR test history. Your PR dashboard.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants