replace legacy kubebuilder-tools setup with sdk-go envtest script [main] - #87
Conversation
Replace the deprecated Google Cloud Storage kubebuilder-tools download with the sdk-go ensure-envtest.sh script that auto-detects K8s version from go.mod and installs setup-envtest automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: xuezhaojun <zxue@redhat.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: xuezhaojun The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
…leBinding With the upgraded envtest (K8s 1.31), CRD CEL validation rules are now properly enforced. Creating a ClusterPermission with an empty Subjects array in ClusterRoleBinding is correctly rejected by the XValidation rule defined in clusterpermission_types.go. Update the test assertion from Should(Succeed()) to ShouldNot(Succeed()). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: xuezhaojun <zxue@redhat.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
==========================================
- Coverage 69.13% 68.91% -0.23%
==========================================
Files 4 4
Lines 891 891
==========================================
- Hits 616 614 -2
- Misses 242 243 +1
- Partials 33 34 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a79de25
into
open-cluster-management-io:main
Summary
kubebuilder-toolsdownload (ensure-kubebuilder-toolstarget) with the newsdk-goensure-envtest.shscriptenvtest-setuptarget auto-detects the Kubernetes version fromgo.modand installssetup-envtestautomaticallyENVTEST_K8S_VERSION,KUBEBUILDER_ASSETS,K8S_VERSION,GOHOSTOS,GOHOSTARCH,KB_TOOLS_ARCHIVE_NAME,KB_TOOLS_ARCHIVE_PATH,ENVTEST)_output/to.gitignorefor envtest cached binariesClusterPermissionwith emptySubjectsinClusterRoleBindingis now rejected by CRD validationDetails
The old approach manually downloaded kubebuilder-tools from
storage.googleapis.com/kubebuilder-tools/with hardcoded K8s versions. This is now deprecated.The new approach uses
open-cluster-management-io/sdk-go/ci/envtest/ensure-envtest.shwhich:go.mod(k8s.io/apidependency)setup-envtestbranch from thecontroller-runtimeversion_output/tools/binKUBEBUILDER_ASSETSpath for use in test targetsReference guide: https://github.com/open-cluster-management-io/sdk-go/blob/main/ci/envtest/README-envtest.md
Test fix: CRD XValidation
The new envtest uses K8s 1.31 (up from 1.24/1.26), which enforces CRD CEL validation rules more strictly. The CRD defines
x-kubernetes-validationsrules using CEL expressions that require eithersubjectorsubjectsto be present in bindings:api/v1alpha1/clusterpermission_types.go:46—ClusterRoleBindingfield:// +kubebuilder:validation:XValidation:rule="has(self.subject) || has(self.subjects)",message="Either subject or subjects has to exist in clusterRoleBinding"api/v1alpha1/clusterpermission_types.go:51—ClusterRoleBindingsfield:// +kubebuilder:validation:XValidation:rule="self.all(i, has(i.subject) || has(i.subjects))",message="Either subject or subjects has to exist in every clusterRoleBinding"api/v1alpha1/clusterpermission_types.go:60—RoleBindingsfield:// +kubebuilder:validation:XValidation:rule="self.all(i, has(i.subject) || has(i.subjects))",message="Either subject or subjects has to exist in every roleBinding"These rules are propagated to the CRD YAML at
config/crds/rbac.open-cluster-management.io_clusterpermissions.yamlasx-kubernetes-validationsentries.The test previously expected
Createto succeed with an emptySubjectsarray, but newer K8s correctly rejects this. The fix changes the assertion from.Should(Succeed())to.ShouldNot(Succeed()).Test plan
make envtest-setupand verifyKUBEBUILDER_ASSETSis printed correctlymake testand verify tests execute with the new envtest setup_output/directory is created with cached binaries🤖 Generated with Claude Code