Skip to content

HYPERFLEET-876 - feat: add when condition to post-actions#122

Merged
openshift-merge-bot[bot] merged 5 commits into
openshift-hyperfleet:mainfrom
cristianoveiga:feat/HYPERFLEET-876-post-action-when
May 14, 2026
Merged

HYPERFLEET-876 - feat: add when condition to post-actions#122
openshift-merge-bot[bot] merged 5 commits into
openshift-hyperfleet:mainfrom
cristianoveiga:feat/HYPERFLEET-876-post-action-when

Conversation

@cristianoveiga

Copy link
Copy Markdown
Contributor

Summary

Extends the adapter framework to support a when condition on post-actions. If the when expression evaluates to false, the post-action is skipped. This allows adapters to conditionally skip status reporting or other post-actions based on execution state (e.g. skip reporting when resources were skipped).

Jira: https://redhat.atlassian.net/browse/HYPERFLEET-876

Changes

  • internal/configloader/types.go: add When field to PostActionConfig
  • internal/executor/post_action_executor.go: evaluate when CEL expression before executing; skip if false
  • internal/executor/post_action_executor_test.go: test coverage for when-gated post-actions (skip/execute branches)

Test plan

  • Unit tests pass (go test ./...)
  • Post-action with when: expression: "!adapter.resourcesSkipped" skips correctly when resources are skipped

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • work-in-progress

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 04ad3305-0158-43e9-9ab3-4cde2f5c3031

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change adds conditional execution for post-actions via a new optional when field (PostActionWhen) containing a CEL expression. The executor evaluates the expression using an execution context; if it evaluates false the action is marked skipped (StatusSkipped) with a reason and not executed, if true the action runs, and if evaluation fails the executor returns an error. The change includes type additions, executor logic to evaluate conditions and adjust logging, tests covering nil/true/false/invalid expressions, and example config updates to use the new guard.

Sequence Diagram(s)

sequenceDiagram
    actor Client as PostActionExecutor
    participant When as PostAction.When
    participant CEL as CEL Evaluator
    participant ExecCtx as Exec Context
    participant API as API Client
    participant Result as PostActionResult

    Client->>When: Is When set?
    alt When set
        Client->>ExecCtx: Build CEL variables
        Client->>CEL: Create evaluator with variables
        alt evaluator creation fails
            CEL-->>Result: Return ExecutorError
        else evaluator created
            Client->>CEL: Evaluate Expression
            alt evaluation error
                CEL-->>Result: Return ExecutorError
            else evaluation succeeds
                alt expression true
                    Client->>API: Execute API call / perform action
                    API-->>Result: Return success/status
                else expression false
                    Client-->>Result: Mark Skipped, StatusSkipped, set SkipReason
                end
            end
        end
    else When not set
        Client->>API: Execute API call / perform action
        API-->>Result: Return success/status
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a 'when' condition feature to post-actions, which is the primary objective of this pull request.
Description check ✅ Passed The description is directly related to the changeset, explaining the new 'when' condition feature, its purpose, affected files, and test plans for conditional post-action execution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci

openshift-ci Bot commented May 13, 2026

Copy link
Copy Markdown

Hi @cristianoveiga. Thanks for your PR.

I'm waiting for a openshift-hyperfleet 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.

Regular contributors should join the org to skip this step.

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.

@cristianoveiga cristianoveiga force-pushed the feat/HYPERFLEET-876-post-action-when branch 2 times, most recently from 6e6c28a to 96dda70 Compare May 13, 2026 15:00
@cristianoveiga cristianoveiga marked this pull request as ready for review May 13, 2026 15:29
@openshift-ci openshift-ci Bot requested review from Mischulee and jsell-rh May 13, 2026 15:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/configloader/types.go`:
- Around line 406-411: PostActionWhen.Expression is documented as required but
lacks a validation tag, so add a validation requirement to the Expression field
(e.g., add validate:"required" alongside the existing yaml tag) on the
PostActionWhen struct to ensure config validation fails fast; update any
validation code that reads struct tags if necessary so the
PostActionWhen.Expression field is enforced during config parsing/validation.

In `@internal/executor/post_action_executor_test.go`:
- Around line 730-737: The test currently only checks API-call side effects
(assert.Equal(t, tt.wantAPICall, result.APICallMade)) but doesn't assert skip
semantics; after require.NoError(t, err) add assertions that verify
result.Skipped matches the expected skip outcome (e.g. assert.Equal(t,
tt.wantSkipped, result.Skipped) or assert.False/True for the false `when` cases)
and, where applicable, assert the SkipReason (e.g. assert.Equal(t,
tt.wantSkipReason, result.SkipReason)) so the test enforces "skipped, not
failed" semantics in the same test block that checks APICallMade and error
state.

In `@internal/executor/post_action_executor.go`:
- Around line 260-264: The skip path in PostActionExecutor currently sets
result.Skipped = true but leaves result.Status at the default (StatusSuccess)
and logs unconditionally, which can make callers treat skipped actions as
successes; update the branch that checks celResult.Matched to also set
result.Status = StatusSkipped (or the appropriate skipped enum/constant used by
the executor), change the log call to conditional logging based on
result.Skipped (e.g., log a skip message when result.Skipped is true instead of
always Infof), and continue returning result, nil so callers can accurately
report skipped actions; reference symbols: celResult.Matched, result.Skipped,
result.Status, action.When.Expression, and the logging call pae.log.Infof.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: c8f3230b-1126-4eda-a374-56974567f558

📥 Commits

Reviewing files that changed from the base of the PR and between 2ff5ec0 and 96dda70.

📒 Files selected for processing (3)
  • internal/configloader/types.go
  • internal/executor/post_action_executor.go
  • internal/executor/post_action_executor_test.go

Comment thread internal/configloader/types.go Outdated
Comment thread internal/executor/post_action_executor_test.go
Comment thread internal/executor/post_action_executor.go
Extends the adapter framework to support a `when` condition on
post-actions. If the CEL expression evaluates to false, the post-action
is skipped (not failed). Also fixes two misleading nolint:govet
fieldalignment comments — both suppress genuine false positives where no
field reordering can reduce the struct size.

Jira: https://redhat.atlassian.net/browse/HYPERFLEET-876

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cristianoveiga cristianoveiga force-pushed the feat/HYPERFLEET-876-post-action-when branch from 96dda70 to 01871a7 Compare May 13, 2026 16:01
…-action

Skip status reporting when the adapter did no work (resourcesSkipped=true)
to avoid overwriting a previously reported status with stale data.

Jira: https://redhat.atlassian.net/browse/HYPERFLEET-876

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kuudori

kuudori commented May 13, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@cristianoveiga cristianoveiga changed the title feat(executor): add when condition to post-actions HYPERFLEET-876 - feat: add when condition to post-actions May 13, 2026
Move the fieldalignment rationale into the doc comment and shorten
the nolint directive to stay within the 120-char lll limit.

Co-Authored-By: Claude <noreply@anthropic.com>
@cristianoveiga cristianoveiga force-pushed the feat/HYPERFLEET-876-post-action-when branch from 135cc5a to 61a7dfb Compare May 13, 2026 18:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/executor/post_action_executor.go`:
- Around line 253-263: The PostActionResult (result) isn't updated when CEL
evaluation fails so callers see StatusSuccess; in the error branches around
criteria.NewEvaluator, evaluator.EvaluateCEL, and celResult.HasError set
result.Status to a failure state (e.g., StatusFailed) and populate result.Error
with the underlying error (err or celResult.Error) before returning
NewExecutorError; update the error-returning paths in
PostActionExecutor.Execute/ExecuteAll so ExecuteAll appends a result that
accurately reflects the failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: ece2abe2-af54-4ddb-b128-b900b864e554

📥 Commits

Reviewing files that changed from the base of the PR and between 96dda70 and 135cc5a.

📒 Files selected for processing (7)
  • charts/examples/maestro-two-resources/adapter-task-config.yaml
  • charts/examples/maestro/adapter-task-config.yaml
  • configs/adapter-task-config-template.yaml
  • internal/configloader/types.go
  • internal/executor/post_action_executor.go
  • internal/executor/post_action_executor_test.go
  • internal/executor/types.go

Comment thread internal/executor/post_action_executor.go
cristianoveiga and others added 2 commits May 13, 2026 15:06
Reorder struct fields in TestPostActionWhenCondition to fix the
govet/fieldalignment violation: move the `when` pointer field before
the `name` string field so pointer bytes reduce from 24 to 16.

Signed-off-by: Cristiano Veiga <cveiga@redhat.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@cristianoveiga cristianoveiga force-pushed the feat/HYPERFLEET-876-post-action-when branch from f6a125e to 46f2b14 Compare May 13, 2026 19:46
@rh-amarin

Copy link
Copy Markdown
Contributor

/ok-to-test

@rh-amarin

Copy link
Copy Markdown
Contributor

/retest

@rh-amarin

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci

openshift-ci Bot commented May 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rh-amarin

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

@openshift-merge-bot openshift-merge-bot Bot merged commit 55894fa into openshift-hyperfleet:main May 14, 2026
10 checks passed
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