Skip to content

NO-JIRA: Add API dependency import restriction tool - #8364

Merged
openshift-merge-bot[bot] merged 4 commits into
openshift:mainfrom
JoelSpeed:api-import-restrictions
Apr 29, 2026
Merged

NO-JIRA: Add API dependency import restriction tool#8364
openshift-merge-bot[bot] merged 4 commits into
openshift:mainfrom
JoelSpeed:api-import-restrictions

Conversation

@JoelSpeed

@JoelSpeed JoelSpeed commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Follow up to #8355

The more polluted the import list is, the harder it is for consumers to integrate HyperShift into their projects. For example, we used to have karpenter as a dependency, this meant that any HyperShift consumer also had karpenter as a dependency, and must now manage both the HyperShift dependency compatibility but also the karpenter dependency compatibility.

It is best practice not to include implementation in the API module and to keep the module strictly to APIs.

This PR add make verify-api-deps to prevent folks from adding new dependencies until/unless they convince an API reviewer that there is a need.

Which issue(s) this PR fixes:

Fixes

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Chores

    • Added a new verify-api-deps check to validate the API module’s direct dependencies against an approved allowlist; runs locally and as part of parallel verification in CI.
    • Included a standalone CLI invocation to perform the dependency allowlist check.
  • Documentation

    • Added user-facing docs describing the allowlist format, default allowed modules (Kubernetes core and OpenShift API), how to run the check, and the workflow for requesting allowlist changes.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 29, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@JoelSpeed: This pull request explicitly references no jira issue.

Details

In response to this:

What this PR does / why we need it:

Follow up to #8355

The more polluted the import list is, the harder it is for consumers to integrate HyperShift into their projects. For example, we used to have karpenter as a dependency, this meant that any HyperShift consumer also had karpenter as a dependency, and must now manage both the HyperShift dependency compatibility but also the karpenter dependency compatibility.

It is best practice not to include implementation in the API module and to keep the module strictly to APIs.

This PR add make verify-api-deps to prevent folks from adding new dependencies until/unless they convince an API reviewer that there is a need.

Which issue(s) this PR fixes:

Fixes

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: b651c534-175d-4fc1-aa8d-14acf25e71d4

📥 Commits

Reviewing files that changed from the base of the PR and between 8ffd5a2 and 043607a.

📒 Files selected for processing (1)
  • api/AGENTS.md
✅ Files skipped from review due to trivial changes (1)
  • api/AGENTS.md

📝 Walkthrough

Walkthrough

Adds a Go-based API dependency verifier and integrates it into the Makefile. The Makefile defines VERIFY_API_DEPS, builds hack/tools/verify-api-deps into bin/verify-api-deps, exposes a verify-api-deps phony target, and runs it via verify-parallel. The new CLI reads api/.imports_allowed and api/go.mod, validates direct require entries (ignoring indirects), exits 1 with a detailed violation report on disallowed deps, or prints success on pass. A README and api/.imports_allowed file were also added.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Developer/CI
  participant Make as Makefile
  participant Build as Go Tool Builder
  participant Tool as verify-api-deps
  participant FS as FileSystem

  Runner->>Make: run `make verify` / `make verify-parallel`
  Make->>Build: build $(VERIFY_API_DEPS)
  Build-->>Make: built binary
  Make->>Tool: execute verify-api-deps
  Tool->>FS: read "api/.imports_allowed"
  Tool->>FS: read "api/go.mod"
  Tool->>Tool: parse go.mod, filter direct requires
  Tool->>Tool: compare requires against allowlist
  alt violations found
    Tool-->>Make: exit 1 + violation report (stderr)
    Make-->>Runner: verification failed
  else no violations
    Tool-->>Make: exit 0 + success message (stdout)
    Make-->>Runner: verification passed
  end
Loading

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Ote Binary Stdout Contract ❌ Error The verify-api-deps tool violates the OTE Binary Stdout Contract by writing to stdout in main() via fmt.Println() on line 26. Remove or redirect the stdout print statement on line 26 to stderr using fmt.Fprintf(os.Stderr, ...) instead.
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 (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new API dependency import restriction tool to the codebase.
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.
Stable And Deterministic Test Names ✅ Passed The PR introduces API dependency verification tool and configuration without Ginkgo test definitions, making the stable test names check inapplicable.
Test Structure And Quality ✅ Passed This pull request does not contain Ginkgo test code; it introduces a new API dependency verification tool and documentation without unit tests.
Microshift Test Compatibility ✅ Passed PR introduces API dependency verification tooling without Ginkgo e2e tests; MicroShift Test Compatibility check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This pull request does not add any new Ginkgo e2e tests; it contains only a command-line dependency verification tool and supporting files.
Topology-Aware Scheduling Compatibility ✅ Passed This pull request introduces a dependency verification tool for the HyperShift API module with build tooling and documentation updates, containing no deployment manifests, operator code, or Kubernetes resources with scheduling constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR does not add any Ginkgo e2e tests with IPv4 assumptions or external connectivity requirements.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

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

Comment thread hack/tools/verify-api-deps/main.go Outdated
Comment on lines +13 to +24
// allowedAPIModules defines the restricted list of allowed direct dependencies for the API module.
// Any new dependencies MUST be reviewed by API reviewers BEFORE being added to this list.
// Note: Indirect dependencies are automatically ignored by the verification logic.
var allowedAPIModules = sets.New(
// Core Kubernetes API dependencies
"k8s.io/api",
"k8s.io/apimachinery",
"k8s.io/utils",

// OpenShift API dependencies
"github.com/openshift/api",
)

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.

Possibly this would be better as a file in the api folder so that it comes under the API OWNERS file rather than the root OWNERS file

@openshift-ci
openshift-ci Bot requested review from Nirshal and muraee April 29, 2026 08:26
@openshift-ci openshift-ci Bot added area/ci-tooling Indicates the PR includes changes for CI or tooling and removed do-not-merge/needs-area labels Apr 29, 2026
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.46%. Comparing base (60802b1) to head (043607a).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8364   +/-   ##
=======================================
  Coverage   36.46%   36.46%           
=======================================
  Files         765      765           
  Lines       93256    93256           
=======================================
  Hits        34010    34010           
  Misses      56532    56532           
  Partials     2714     2714           
Flag Coverage Δ
cmd-support 30.34% <ø> (ø)
cpo-hostedcontrolplane 37.05% <ø> (ø)
cpo-other 35.69% <ø> (ø)
hypershift-operator 47.89% <ø> (ø)
other 28.37% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hack/tools/verify-api-deps/README.md`:
- Around line 29-31: The README currently tells users to change into
hack/tools/verify-api-deps then run the tool, which makes Go look for api/go.mod
in that subdirectory and fails; update the instructions in README.md for the
verify-api-deps tool to tell users to run the tool from the repository root and
invoke go run against hack/tools/verify-api-deps/main.go (i.e., do not cd into
the subdirectory), so the correct api/go.mod is resolved when executing main.go.
🪄 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: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bd4a9e96-baa9-4570-a68d-8e7f9e796c7a

📥 Commits

Reviewing files that changed from the base of the PR and between 60802b1 and d02544d.

📒 Files selected for processing (3)
  • Makefile
  • hack/tools/verify-api-deps/README.md
  • hack/tools/verify-api-deps/main.go

Comment thread hack/tools/verify-api-deps/README.md Outdated
@openshift-ci openshift-ci Bot added the area/api Indicates the PR includes changes for the API label Apr 29, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hack/tools/verify-api-deps/main.go`:
- Around line 60-82: The error string returned when len(violations) > 0
incorrectly instructs users to "Update the allowlist in
hack/tools/verify-api-deps/main.go"; update the fmt.Errorf message (the return
fmt.Errorf(...) that uses formatViolations(violations)) to remove the stale
reference and instead direct users to the canonical allowlist location (the
existing api/.imports_allowed reference already present later in the message),
ensuring the only allowlist instruction points to api/.imports_allowed.
🪄 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: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 7e63c228-99e9-48c2-beae-70adc281f6c3

📥 Commits

Reviewing files that changed from the base of the PR and between d02544d and b0934e9.

📒 Files selected for processing (3)
  • api/.imports_allowed
  • hack/tools/verify-api-deps/README.md
  • hack/tools/verify-api-deps/main.go
✅ Files skipped from review due to trivial changes (2)
  • api/.imports_allowed
  • hack/tools/verify-api-deps/README.md

Comment thread hack/tools/verify-api-deps/main.go
@JoelSpeed
JoelSpeed force-pushed the api-import-restrictions branch from b0934e9 to 21a5fb3 Compare April 29, 2026 08:37
The more polluted the import list is, the harder it is for consumers to
integrate HyperShift into their projects. For example, we used to have
karpenter as a dependency, this meant that any HyperShift consumer also
had karpenter as a dependency, and must now manage both the HyperShift
dependency compatibility but also the karpenter dependency compatibility.

It is best practice not to include implementation in the API module
and to keep the module strictly to APIs.
… control

This means that any changes have to be approved by an API reviewer
This means it doesn't matter from where you execture the binary.

It will walk up the structure to find the root and then find the API module from there
@JoelSpeed
JoelSpeed force-pushed the api-import-restrictions branch from 21a5fb3 to 8ffd5a2 Compare April 29, 2026 09:06
@enxebre

enxebre commented Apr 29, 2026

Copy link
Copy Markdown
Member

can we please include a ref to this make target here https://github.com/openshift/hypershift/blob/main/api/AGENTS.md#api-versioning

@JoelSpeed

Copy link
Copy Markdown
Contributor Author

can we please include a ref to this make target here https://github.com/openshift/hypershift/blob/main/api/AGENTS.md#api-versioning

It's already included in the verify, do you still want me to put it in separately as an early/quick check?

@enxebre

enxebre commented Apr 29, 2026

Copy link
Copy Markdown
Member

It's already included in the verify, do you still want me to put it in separately as an early/quick check?

yes please, just like we have api-lint, api-lint-fix... in that list so it has a list of targeted items without needing to run verify which is more expensive all the time but only once.
we'll be putting evals for this soon.

Give the agents some guidance that utils and methods should not be included on API packages
@enxebre

enxebre commented Apr 29, 2026

Copy link
Copy Markdown
Member

/approve
/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 29, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-azure-self-managed
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws

@openshift-ci

openshift-ci Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enxebre, JoelSpeed

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 Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 29, 2026
@JoelSpeed

Copy link
Copy Markdown
Contributor Author

/verified by @JoelSpeed

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Apr 29, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@JoelSpeed: This PR has been marked as verified by @JoelSpeed.

Details

In response to this:

/verified by @JoelSpeed

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 openshift-eng/jira-lifecycle-plugin repository.

@hypershift-jira-solve-ci

Copy link
Copy Markdown
Contributor

AI Test Failure Analysis

Job: pull-ci-openshift-hypershift-main-e2e-azure-self-managed | Build: 2049480847299448832 | Cost: $4.379119750000002 | Failed step: hypershift-azure-run-e2e-self-managed

View full analysis report


Generated by hypershift-analyze-e2e-failure post-step using Claude claude-opus-4-6

@hypershift-jira-solve-ci

Copy link
Copy Markdown
Contributor

Now I have the complete picture. Let me generate the final report.

Test Failure Analysis Complete

Job Information

  • Prow Job: pull-ci-openshift-hypershift-main-e2e-azure-self-managed
  • Build ID: 2049480847299448832
  • Target: e2e-azure-self-managed
  • PR: NO-JIRA: Add API dependency import restriction tool #8364 (NO-JIRA: Add API dependency import restriction tool)
  • Start Time: 2026-04-29T13:28:06Z
  • Duration: ~3h

Test Failure Analysis

Error

DONE 283 tests, 26 skipped, 11 failures in 0.009s

TestNodePool/HostedCluster0 subtests (4 failures):
  - TestNodePoolInPlaceUpgrade: Failed to wait for 1 nodes to become ready in 45m0s (expected 1, got 0)
  - TestNTOMachineConfigGetsRolledOut: Failed to wait for 2 nodes to become ready in 45m0s (expected 2, got 1)
  - TestNTOPerformanceProfile: Failed to wait for 1 nodes to become ready in 45m0s (expected 1, got 0)
  - TestNodepoolMachineconfigGetsRolledout: Failed to wait for NodePool to finish config update in 45m0s (UpdatingConfig stuck True)

TestNodePool/HostedCluster2 subtests (1 failure):
  - TestAdditionalTrustBundlePropagation: Failed to wait for NodePool to stop updating in 20m0s
    Machine node-pool-5nwmk-test-additional-trust-bundle-propagation-g68bnh: NodeProvisioning: Waiting for a node with matching ProviderID to exist

Summary

All 11 test failures are Azure node provisioning timeouts in the TestNodePool test tree, concentrated in two HostedClusters (HostedCluster0 and HostedCluster2). The tests create new NodePools with additional worker nodes, but the Azure CAPI machines fail to provision within the 45-minute timeout — machines remain stuck in WaitingForInfrastructure or WaitingForNodeRef states. This is an Azure infrastructure flake, not a code regression: the PR only adds a Makefile target and an API dependency import restriction tool (verify-api-deps/main.go, api/.imports_allowed), touching zero test or product code. Other tests in the same run that also require node provisioning (TestCreateCluster, TestAutoscaling, TestNodePoolReplaceUpgrade, TestNodePoolPrevReleaseN1/N2, TestMirrorConfigs) all passed successfully, confirming intermittent Azure capacity/provisioning issues rather than a systematic failure.

Root Cause

Intermittent Azure node provisioning failures — not related to PR #8364.

The root cause is Azure infrastructure intermittently failing to provision new worker nodes for specific NodePools within the 45-minute timeout. The evidence shows:

  1. Machines stuck in provisioning: CAPI machines remained in WaitingForInfrastructure and WaitingForNodeRef states, meaning Azure did not complete VM creation or the VMs did not register with the cluster within the timeout window.

  2. Selective failure pattern: Only specific subtests that create additional NodePools (InPlaceUpgrade, NTOMachineConfig, NTOPerformanceProfile, MachineConfig, AdditionalTrustBundle) failed, while other subtests in the same HostedClusters that also create NodePools (ReplaceUpgrade, PrevReleaseN1/N2, MirrorConfigs) succeeded. This indicates a transient Azure capacity or timing issue, not a deterministic bug.

  3. PR has zero impact: The PR changes consist of:

    • Makefile: +9 lines adding a verify-api-deps target
    • api/.imports_allowed: new allowlist file
    • hack/tools/verify-api-deps/main.go: new static analysis tool
    • api/AGENTS.md, hack/tools/go.mod: minor documentation/dependency updates

    None of these files affect test logic, NodePool controller behavior, CAPI machine provisioning, or Azure infrastructure code.

  4. Post-test condition mismatch is a symptom, not root cause: The ValidateHostedClusterConditions errors (e.g., "wanted ClusterVersionAvailable=False, got True") are a diagnostic check that runs only after tests have already failed. It runs with hasWorkerNodes=false because the failed subtests' NodePools never got their nodes ready, but the HostedCluster itself was fully provisioned — this is expected behavior and confirms the HostedCluster was healthy while individual NodePool provisioning failed.

Recommendations
  1. Retest the PR — This failure is an Azure infrastructure flake unrelated to the PR changes. A /retest should pass.

  2. No code changes needed — The PR (verify-api-deps tool addition) does not interact with any test or product code paths involved in these failures.

  3. If the failure recurs, investigate Azure capacity in the centralus region or check for AKS VMSS provisioning delays in the hypershift-azure CI profile. The specific machines that failed were in NodePools created as part of nodepool mutation tests (config updates, in-place upgrades).

Evidence
Evidence Detail
Test results 283 total, 246 passed, 26 skipped, 11 failed (all in TestNodePool)
Failure pattern All failures are 45min node provisioning timeouts in Azure
HostedCluster0 failures 4 subtests: InPlaceUpgrade (0/1 nodes), NTOMachineConfig (1/2 nodes), NTOPerformanceProfile (0/1 nodes), Machineconfig (stuck UpdatingConfig)
HostedCluster2 failures 1 subtest: AdditionalTrustBundle (machine g68bnh stuck in NodeProvisioning/WaitingForNodeRef)
Passing NodePool tests (same HostedClusters) ReplaceUpgrade (1261s), PrevReleaseN1 (561s), PrevReleaseN2 (660s), MirrorConfigs (408s) — all created machines and provisioned nodes successfully
Other passing tests TestCreateCluster (2306s), TestAutoscaling, TestUpgradeControlPlane, TestHAEtcdChaos, TestAzureOAuthLoadBalancer, TestAzurePrivateTopology — all passed
CAPI condition AllMachinesReady=False: WaitingForInfrastructure, AllNodesHealthy=False: WaitingForNodeRef
PR files changed Makefile, api/.imports_allowed, api/AGENTS.md, hack/tools/go.mod, hack/tools/verify-api-deps/ (zero test/product code)
Azure region centralus
Platform Azure HyperShift self-managed (AKS management cluster)

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 60802b1 and 2 for PR HEAD 043607a in total

@cwbotbot

Copy link
Copy Markdown

Test Results

e2e-aws

e2e-aks

@openshift-ci

openshift-ci Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@JoelSpeed: all tests passed!

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.

@openshift-merge-bot
openshift-merge-bot Bot merged commit bcd1884 into openshift:main Apr 29, 2026
60 of 64 checks passed
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. area/api Indicates the PR includes changes for the API area/ci-tooling Indicates the PR includes changes for CI or tooling jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants