Skip to content

HYPERFLEET-1090 - feat: WIFConfig plugin registration#198

Merged
openshift-merge-bot[bot] merged 2 commits into
openshift-hyperfleet:mainfrom
sherine-k:1090-WIFConfig
Jun 4, 2026
Merged

HYPERFLEET-1090 - feat: WIFConfig plugin registration#198
openshift-merge-bot[bot] merged 2 commits into
openshift-hyperfleet:mainfrom
sherine-k:1090-WIFConfig

Conversation

@sherine-k
Copy link
Copy Markdown
Contributor

@sherine-k sherine-k commented Jun 2, 2026

Summary

This PR adds a plugin to register WIFConfig as an entity at API startup.
It also introduces schema validation for registered resources (channels, versions, wifConfigs) that have a spec defined (provided by an external openapi schema).
This PR also aligns the kind naming convention to PascalCase with hyperfleet-api-spec-template [PR#5}(https://github.com/openshift-hyperfleet/hyperfleet-api-spec-template/pull/5)

  • HYPERFLEET-1090

Out of Scope: Deletion protection (preventing accidental removal of WIF configs that active clusters depend on)

Test Plan

  • Unit tests added/updated
  • make test-all passes
  • make lint passes
  • Helm chart changes validated with make test-helm (if applicable)
  • Deployed to a development cluster and verified (if Helm/config changes)
  • E2E tests passed (if cross-component or major changes)

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 2, 2026

Hi @sherine-k. 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Warning

Review limit reached

@sherine-k, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 28 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: ee44b943-dab0-4dc3-9c39-63839c0e45c4

📥 Commits

Reviewing files that changed from the base of the PR and between 54ed659 and 4befe9c.

📒 Files selected for processing (3)
  • pkg/middleware/schema_validation.go
  • pkg/middleware/schema_validation_match_test.go
  • pkg/middleware/schema_validation_test.go
📝 Walkthrough

Walkthrough

This PR makes spec-schema discovery registry-driven and pluraI-keyed. It adds registry.WithSpecSchema(), refactors NewSchemaValidator to build schemas map by entity plural (with temporary clusters/nodepools seeding), converts middleware to regex-based rightmost-plural matching for POST/PATCH and to call Validate(plural,...), and registers a new WifConfig plugin + integration tests plus a permissive test validation-schema.yaml.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Middleware as SchemaValidation<br/>Middleware
  participant Registry
  participant Validator as SchemaValidator
  participant Handler
  Client->>Middleware: POST /clusters/{id}/nodepools<br/>{"spec": {...}}
  Middleware->>Registry: WithSpecSchema()
  Registry-->>Middleware: [Cluster, NodePool, WifConfig, ...]
  Middleware->>Middleware: shouldValidateRequest(method, path, entities)<br/>&`#x2192`; "nodepools"
  Middleware->>Validator: Validate("nodepools", spec)
  Validator->>Validator: Look up schema by plural key
  Validator-->>Middleware: nil (valid) or ValidationWithDetails
  alt Valid
    Middleware->>Handler: next()
    Handler-->>Client: 201 Created
  else Invalid
    Middleware-->>Client: 400 ProblemDetails<br/>(HYPERFLEET-VAL-000)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.74% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly identifies the main change: adding a WIFConfig plugin registration to the system.
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.
Sec-02: Secrets In Log Output ✅ Passed No log statements in non-test files contain tokens, passwords, credentials, or secrets; all logging is of safe metadata only.
Description check ✅ Passed The PR description clearly relates to the changeset: adding a WIFConfig plugin, schema validation for registered resources, and aligning naming conventions.

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

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

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.

@tirthct
Copy link
Copy Markdown
Contributor

tirthct commented Jun 2, 2026

/ok-to-test

@hyperfleet-ci-bot
Copy link
Copy Markdown

hyperfleet-ci-bot Bot commented Jun 2, 2026

Risk Score: 5 — risk/high

Signal Detail Points
PR size 1285 lines (>500) +2
Sensitive paths cmd/ +2
Test coverage Missing tests for: cmd/hyperfleet-api plugins/wifconfigs +1

Computed by hyperfleet-risk-scorer

@sherine-k sherine-k changed the title WIP: HYPERFLEET-1090: WIFConfig plugin registration HYPERFLEET-1090: WIFConfig plugin registration Jun 2, 2026
@sherine-k
Copy link
Copy Markdown
Contributor Author

/test validate-commits

@sherine-k sherine-k changed the title HYPERFLEET-1090: WIFConfig plugin registration HYPERFLEET-1090 - feat: WIFConfig plugin registration Jun 2, 2026
@sherine-k
Copy link
Copy Markdown
Contributor Author

/test validate-commits

Comment thread plugins/wifconfigs/plugin.go Outdated
)

const (
kindWifConfig = "Wifconfig"
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 wonder if the kind should be WifConfig or even WIFConfig

We have nodepools with kind being NodePool

But, in this case WIF is an acronym for "Workload Identity Federation", so the uppercase could also be considered valid

Copy link
Copy Markdown
Contributor

@ciaranRoche ciaranRoche Jun 3, 2026

Choose a reason for hiding this comment

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

In OCM we ended up pascalcasing everything, As we had var names like OCMAWSSTSConfig, instead we followed OcmAwsStsConfig to make it a bit easier.
Not sure if that is something we want to follow here. I do not envision we will have as many use cases as we had in OCM for this. But best to chose one and we capture it in our standards

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.

In this case we better using Pascal Case for consistency with other plugins

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.

Just note that this would be up to our partners to decide when they can configure their own generic API resources

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, in that case, I'll also sync with https://github.com/openshift-hyperfleet/hyperfleet-api-spec-template and PR#2 which we'd need to put in pascalcasing too?
cc @tirthct @ciaranRoche @rh-amarin

@sherine-k sherine-k marked this pull request as draft June 3, 2026 09:08
@sherine-k sherine-k force-pushed the 1090-WIFConfig branch 4 times, most recently from ec791d2 to dda3fa0 Compare June 4, 2026 09:46
@sherine-k sherine-k marked this pull request as ready for review June 4, 2026 09:46
@openshift-ci openshift-ci Bot requested review from ciaranRoche and jsell-rh June 4, 2026 09:46
Copy link
Copy Markdown

@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: 2

🤖 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 `@pkg/validators/schema_validator_test.go`:
- Around line 580-596: The test helper functions setupTestValidator and
setupTestValidatorWithOptionalEntities need to call t.Helper() at the top so
test failures are reported at the caller site; update each function to begin
with t.Helper() (inside the function body, before any t.Fatalf calls or other
test assertions) to mark them as helpers and improve failure location reporting.

In `@test/integration/wifconfigs_test.go`:
- Around line 63-70: The test currently discards the error return from
resty.Post and asserts on resp2; update the call to capture the error (e.g.,
resp2, err := resty.R()....Post(h.RestURL(wifConfigsPath))) and assert that err
is nil before checking resp2.StatusCode() so transport failures fail the test
clearly; if err is non-nil, fail the test (Expect(err).To(BeNil()) or t.Fatalf)
and only then assert that resp2.StatusCode() equals http.StatusBadRequest for
the non-object spec case (references: resp2, err, resty.R().Post,
invalidTypeJSON, h.RestURL(wifConfigsPath), wifConfigsPath).
🪄 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: CHILL

Plan: Enterprise

Run ID: 16f5ec3f-6519-409c-b646-28717b4845dd

📥 Commits

Reviewing files that changed from the base of the PR and between adda43a and dda3fa0.

📒 Files selected for processing (14)
  • cmd/hyperfleet-api/main.go
  • pkg/middleware/schema_validation.go
  • pkg/middleware/schema_validation_match_test.go
  • pkg/middleware/schema_validation_test.go
  • pkg/registry/registry.go
  • pkg/registry/registry_test.go
  • pkg/validators/schema_validator.go
  • pkg/validators/schema_validator_test.go
  • plugins/wifconfigs/plugin.go
  • test/CLAUDE.md
  • test/integration/clusters_test.go
  • test/integration/integration_test.go
  • test/integration/wifconfigs_test.go
  • test/validation-schema.yaml

Comment thread pkg/validators/schema_validator_test.go
Comment thread test/integration/wifconfigs_test.go Outdated
…idation

Register WIFConfig as a generic resource plugin using the new ResourceHandler pattern,
with spec validation driven by the entity registry rather than hardcoded resource types.

- Add WIFConfig plugin with CRUD routes and registry descriptor
- Refactor SchemaValidationMiddleware to discover entities from registry.WithSpecSchema()
- Refactor SchemaValidator to dynamically load schemas for all registered entities
- Add rightmost-match path logic so nested routes (e.g. /clusters/{id}/nodepools) use the child schema
- Add registry.WithSpecSchema() and registry.Reset() helpers
- Add permissive test/validation-schema.yaml for integration tests
- Add WIFConfig integration tests covering CRUD, schema validation, and error details
- Add schema_validation_match_test.go for nested path disambiguation
- Extend schema_validator_test.go with registry-driven validation coverage

// shouldValidateRequest determines if the request requires spec validation
// Returns (shouldValidate bool, resourceType string)
func shouldValidateRequest(method, path string) (bool, string) {
Copy link
Copy Markdown
Contributor

@ma-hill ma-hill Jun 4, 2026

Choose a reason for hiding this comment

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

Could name the return values to be inline with the comment:
func shouldValidateRequest(method, path string) (shouldValidate bool, resourcePlural string)

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.

But I don't know if we follow that go-ism here, so might be unnecessary.

//
// When a path contains multiple registered plurals (e.g. /clusters/{id}/nodepools),
// the rightmost matching segment wins so nested resources use their own spec schema.
func shouldValidateRequest(
Copy link
Copy Markdown
Contributor

@rh-amarin rh-amarin Jun 4, 2026

Choose a reason for hiding this comment

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

I wonder if it will be more clear to use a regex here to validate that giving a , the URL will match ending in

  • <plural>
  • <plural>/
  • <plural>/<uuid>

In go

func buildRegex(word string) *regexp.Regexp {
pattern := fmt.Sprintf(
	`/%s(?:/?|/[0-9a-fA-F-]{36})$`,
	regexp.QuoteMeta(word),
)
return regexp.MustCompile(pattern)
}

@rh-amarin
Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 4, 2026

[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-ci openshift-ci Bot added the approved label Jun 4, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit ef2f472 into openshift-hyperfleet:main Jun 4, 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.

5 participants