← Back to Pull requests

AUTOSCALE-1061: test: add NodeClass CRD schema tests #72

Closed
unknown closed this pull request without merging on Nov 09, 2026 12:05 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 14:15 UTC
Author

Related release PR: https://github.com/openshift/release/pull/88226

The NodeClass CRDs moved here from HyperShift without their schema tests. This PR adds an envtest runner, migrates the OpenshiftEC2NodeClass suites from openshift/hypershift, and adds OpenShiftAzureNodeClass cases.

make test-schema runs them against OpenShift kube-apiserver builds 1.35 (OCP 4.22, the oldest supported release) to 1.37. The binaries come from the OpenShift envtest index and are extracted from OCP release payloads, not upstream Kubernetes.

Most of these changes are vendored deps, then test suites and then the schema test go code. Most of the code is reused as the comparisons below show, so you don't necessarily have to focus review everything.

Fun fact: hypershift copied the test suite from openshift/api, so lot of the code is quite similar, for example:
https://github.com/openshift/api/blob/7912bdb546532a1245fc6b60bdbfa6d499973165/tests/generator.go#L164-L167

https://github.com/openshift/karpenter-operator/blob/241f757077d8fabed2c8b4099739880a73573fcc/test/schema/generator_test.go#L378-L381

The actual test generation is in test/schema/generator_test.go

Compared to HyperShift

Reused:

  • The runner is adapted from openshift/api/tests and keeps its testsuite YAML format.

  • Suites are stored next to the CRDs, in pkg/assets/hypershift/tests/<crdName>/.

  • The envtest build tag keeps plain go test ./... from running the suite which would fail if KUBEBUILDER_ASSETS is not set.
  • Changed:

  • No feature-gate or cluster-profile handling, which these CRDs don't need. The CRDs are read from pkg/assets/hypershift/ instead of a duplicated copy.

  • Only OpenShift kube-apiserver builds, in a plain loop instead of parallel sub-makes as it is simpler.

  • Suites are parsed strictly and checked at load time. A rejection must be an API validation error. A suite keeps running after a case fails. Invalid suites are not skipped anymore.

  • The kubelet ratcheting suite is maintained by hand as it is simpler instead of being generated.
  • What is ratcheting?

    Ratcheting here means that data already stored in a CRD must keep working after its schema gets stricter: fields that were previously accepted as unknown (x-kubernetes-preserve-unknown-fields) become typed and objects written under the old schema must still keep their values when written again under the new one.

    Example: assume spec.kubelet.maxPods wasn't typed right now, would still be passed through to karpenter though. ratcheting means, maxPods still keeps its value when adding a maxPods int field.

    The ratcheting suite proves that by creating an object under the stripped-down schema, restoring the real one with types, and checking the update succeeds with all values intact.

    Migration result per suite file

    | Suite file | HyperShift cases | Ours | Content differences (after normalizing case names) |
    |---|---|---|---|
    | stable.openshiftec2nodeclasses.testsuite.yaml | 18 | 23 | Only the 5 new ebs cases added (4 create + onUpdate). The 18 migrated cases are byte-identical apart from names. |
    | stable.openshiftec2nodeclasses.kubelet.testsuite.yaml | 53 | 52 | One redundant case dropped (the negative systemReserved value, covered by the mixed-entries case above it). The "unknown fields" case now asserts the persisted object with expected. Otherwise only names differ. |
    | stable.openshiftec2nodeclasses.kubelet-field-promotion.testsuite.yaml | 5 | 6 | The first case now simulates a promotion: initialCRDPatches install the CRD without the typed maxPods, the object is created with maxPods: 5000 as overflow, and the real CRD is restored before the update. A new case checks that changing that value is rejected. One case is renamed and the header comment is rewritten, the other cases are unchanged. |
    | stable.openshiftec2nodeclasses.kubelet-ratcheting.testsuite.yaml | 1 | 1 | Header comment (# Code generated by hack/kubelet-ratcheting-gen. DO NOT EDIT. replaced with hand-maintenance instructions) plus the case name. Bodies identical. |
    | Total | 77 | 82 | |

    Case-name normalization applied: HyperShift used When X it should Y (no comma); ours uses When X, it should Y. One case read When kubelet has unknown fields they should be preserved and now reads When kubelet has unknown fields, it should preserve them, because the repo convention is it should <verb>.

    Apart from the differences listed above, CRD name, apiVersion, version, crdName, initialCRDPatches/patches, expectations and status assertions are identical between the two copies.

    EC2 versus Azure coverage

    Azure has no equivalent of the kubelet suites. Both CRDs share openshiftkarpenterv1.KubeletConfiguration, so the 59 kubelet cases in the EC2 suites already cover that schema for both; the Azure suite only checks that kubelet: {} is rejected.

    | Area | OpenshiftEC2NodeClass | OpenShiftAzureNodeClass |
    |---|---|---|
    | Whole object | — | 3 (all fields valid, omitted spec, empty spec) |
    | Subnet reference | 5 (selector terms: empty, id/tags exclusivity, id format, valid tags) | 7 (vnetSubnetID format, subscriptionId, resourceGroupName, vnetName, subnetName, naming rules per segment) |
    | Security group | 3 (empty, id format, valid id) | — |
    | Tags | 3 (restricted kubernetes.io/cluster/ and karpenter.sh/nodepool keys, valid keys) | 8 (empty, count limit, key/value length, character and backslash rules, reserved prefixes) |
    | Disks | 8 (rootVolume uniqueness, ebs required, ebs non-empty, snapshot/size rules, update) | 2 (osDiskSizeGiB bounds) |
    | Security | — | 2 (security non-empty, hostEncryption enum) |
    | Version | 2 (format, valid) | 1 (format) |
    | Provider-specific | 3 (capacityReservationSelectorTerms id and ownerID, metadataOptions) | — |
    | Kubelet | 59 (52 validation, 6 field promotion, 1 ratcheting) | 1 (empty object rejected) |
    | Total | 23 + 59 | 25 |

    Commits

  • test: add NodeClass CRD schema tests: the runner, make test-schema, the docs, and the suites: 77 EC2 cases migrated from HyperShift (case names changed to the repo convention, a few cases changed as listed above) and 25 Azure cases.

  • test: cover required ebs in EC2 block device mappings: 5 cases for #47, which made ebs required in every blockDeviceMappings entry.

  • fix: report only the format error for short Azure subnet IDs: changes the Azure CRD validation, so please review it. The vnetSubnetID segment rules indexed into self.split('/') without a size check. IDs with fewer than 11 segments got CEL "index out of bounds" errors on top of the format error. The segment rules now apply only to IDs with 11 segments, so only the format error is reported. The Azure suite asserts this.
  • Running

    make test-schema
    make test-schema SCHEMA_TEST_K8S_VERSIONS=1.37.1
    

    Plain go test ./... skips the suite because of the envtest build tag. See "Schema tests" in TESTING.md.

    Testing

  • make test-schema passes on 1.35.1, 1.36.2 and 1.37.1 (107 specs).

  • CI verify passes on the PR head.

  • Negative checks: breaking a CEL rule or an expected error makes exactly the matching case fail.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: maxcao13 Review duration: 8510m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #72"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%