AUTOSCALE-1061: test: add NodeClass CRD schema tests #72
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
maxcao13
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
OpenshiftEC2NodeClasssuites from openshift/hypershift, and addsOpenShiftAzureNodeClasscases.make test-schemaruns 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:
pkg/assets/hypershift/tests/<crdName>/.envtestbuild tag keeps plaingo test ./...from running the suite which would fail ifKUBEBUILDER_ASSETSis not set.Changed:
pkg/assets/hypershift/instead of a duplicated copy.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 intfield.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 newebscases 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 negativesystemReservedvalue, covered by the mixed-entries case above it). The "unknown fields" case now asserts the persisted object withexpected. Otherwise only names differ. ||
stable.openshiftec2nodeclasses.kubelet-field-promotion.testsuite.yaml| 5 | 6 | The first case now simulates a promotion:initialCRDPatchesinstall the CRD without the typedmaxPods, the object is created withmaxPods: 5000as 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 usesWhen X, it should Y. One case readWhen kubelet has unknown fields they should be preservedand now readsWhen kubelet has unknown fields, it should preserve them, because the repo convention isit 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 thatkubelet: {}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 (
vnetSubnetIDformat, subscriptionId, resourceGroupName, vnetName, subnetName, naming rules per segment) || Security group | 3 (empty, id format, valid id) | — |
| Tags | 3 (restricted
kubernetes.io/cluster/andkarpenter.sh/nodepoolkeys, valid keys) | 8 (empty, count limit, key/value length, character and backslash rules, reserved prefixes) || Disks | 8 (rootVolume uniqueness,
ebsrequired,ebsnon-empty, snapshot/size rules, update) | 2 (osDiskSizeGiBbounds) || Security | — | 2 (
securitynon-empty,hostEncryptionenum) || Version | 2 (format, valid) | 1 (format) |
| Provider-specific | 3 (
capacityReservationSelectorTermsid 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 madeebsrequired in everyblockDeviceMappingsentry.fix: report only the format error for short Azure subnet IDs: changes the Azure CRD validation, so please review it. ThevnetSubnetIDsegment rules indexed intoself.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
Plain
go test ./...skips the suite because of theenvtestbuild tag. See "Schema tests" inTESTING.md.Testing
make test-schemapasses on 1.35.1, 1.36.2 and 1.37.1 (107 specs).verifypasses on the PR head.