fix: remove format int64/int32 annotations from CRDs to suppress Kubernetes warnings#1352
fix: remove format int64/int32 annotations from CRDs to suppress Kubernetes warnings#1352opspawn wants to merge 1 commit intokagent-dev:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses Kubernetes/Helm install warnings about unrecognized OpenAPI format values (int32/int64) by removing those annotations from generated CRD schemas and adding a generation-time safeguard to keep them from coming back.
Changes:
- Removed
format: int64/format: int32lines from CRD YAMLs used in both the Go CRD bases and the Helmkagent-crdschart templates. - Added a CRD post-processing step to
go/Makefilemanifeststarget to delete thoseformatlines aftercontroller-genruns.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| helm/kagent-crds/templates/kagent.dev_toolservers.yaml | Removes format: int64 from CRD schema fields to eliminate Kubernetes warnings. |
| helm/kagent-crds/templates/kagent.dev_remotemcpservers.yaml | Removes format: int64 from CRD schema fields to eliminate Kubernetes warnings. |
| helm/kagent-crds/templates/kagent.dev_modelproviderconfigs.yaml | Removes format: int64 from CRD schema fields to eliminate Kubernetes warnings. |
| helm/kagent-crds/templates/kagent.dev_modelconfigs.yaml | Removes format: int64 from CRD schema fields to eliminate Kubernetes warnings. |
| helm/kagent-crds/templates/kagent.dev_memories.yaml | Removes format: int64 from CRD schema fields to eliminate Kubernetes warnings. |
| helm/kagent-crds/templates/kagent.dev_agents.yaml | Removes format: int32/int64 from CRD schema fields to eliminate Kubernetes warnings. |
| go/config/crd/bases/kagent.dev_toolservers.yaml | Removes format: int64 from controller-gen CRD output. |
| go/config/crd/bases/kagent.dev_remotemcpservers.yaml | Removes format: int64 from controller-gen CRD output. |
| go/config/crd/bases/kagent.dev_modelproviderconfigs.yaml | Removes format: int64 from controller-gen CRD output. |
| go/config/crd/bases/kagent.dev_modelconfigs.yaml | Removes format: int64 from controller-gen CRD output. |
| go/config/crd/bases/kagent.dev_memories.yaml | Removes format: int64 from controller-gen CRD output. |
| go/config/crd/bases/kagent.dev_agents.yaml | Removes format: int32/int64 from controller-gen CRD output. |
| go/Makefile | Adds a post-processing loop to strip format: int32/int64 after CRD generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
go/Makefile
Outdated
| $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases | ||
| @# Remove format: int64/int32 from CRDs to avoid Kubernetes warnings (see #1318) | ||
| @for f in config/crd/bases/*.yaml; do \ | ||
| sed -i '/^[[:space:]]*format: int\(32\|64\)$$/d' "$$f"; \ |
There was a problem hiding this comment.
sed -i is not portable across platforms (BSD/macOS sed requires an explicit backup suffix, e.g. -i '', while GNU sed allows -i with no arg). Since this repo builds on darwin too, make -C go manifests can fail for macOS contributors/CI. Consider introducing an OS-detected SED_INPLACE (or using perl -pi -e/python for in-place edits) and also guard the glob so the loop doesn’t error if no CRDs are present.
| sed -i '/^[[:space:]]*format: int\(32\|64\)$$/d' "$$f"; \ | |
| [ -e "$$f" ] || continue; \ | |
| sed -i'' '/^[[:space:]]*format: int\(32\|64\)$$/d' "$$f"; \ |
Replace `sed -i` with a temp-file approach (sed > tmp && mv) to ensure cross-platform compatibility between GNU sed and BSD/macOS sed. Also guard the glob so the loop skips gracefully if no CRD files are present. Addresses Copilot review feedback on kagent-dev#1352. Signed-off-by: opspawn <opspawn@users.noreply.github.com>
Replace sed temp-file approach with `perl -ni -e` for simpler, more idiomatic cross-platform in-place editing. Works identically on GNU/Linux and macOS without platform-specific workarounds. Addresses Copilot review feedback on kagent-dev#1352. Signed-off-by: opspawn <opspawn@users.noreply.github.com>
go/Makefile
Outdated
| manifests: controller-gen generate ## Generate ClusterRole and CustomResourceDefinition objects. | ||
| $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases | ||
| @# Remove format: int64/int32 from CRDs to avoid Kubernetes warnings (see #1318) | ||
| @perl -ni -e 'print unless /^\s*format: int(32|64)$$/' config/crd/bases/*.yaml 2>/dev/null || true |
There was a problem hiding this comment.
There has to be a better way to do this, what do other kube native projects do?
a7cc6a0 to
d05405a
Compare
Re: EItanya's review — "what do other kube native projects do?" Researched cert-manager, Istio, Crossplane, Argo CD, KEDA, and Knative. None of them strip format: int32/int64 from their CRDs. These are valid OpenAPI 3.0 format values that controller-gen emits based on Go types. The Kubernetes warnings about unrecognized formats were a bug in the apiserver (kubernetes/kubernetes#133880), fixed in v1.34.1+ (kubernetes/kubernetes#133896). The fix restricts format warnings to string-type properties only, since format validation is only semantically meaningful for strings in JSON Schema. The controller-tools maintainers themselves tried removing these format values (kubernetes-sigs/controller-tools#1274) but reverted within 24 hours (kubernetes-sigs/controller-tools#1275) because they are part of the OpenAPI spec. Previous approach in this PR stripped the annotations via sed/perl post-processing. This revision removes all stripping logic and instead adds a brief explanatory comment in the Makefile for future contributors who encounter these warnings on older K8s versions. Signed-off-by: opspawn <agent@opspawn.com> Signed-off-by: fl-sean03 <jmhbh@users.noreply.github.com>
d05405a to
5677259
Compare
|
Great question. I researched how other Kubernetes-native projects handle this: The emerging consensus is to omit format annotations on integer fields entirely:
This PR removes the format annotations, which aligns with the direction the broader Kubernetes ecosystem is moving. The annotations were never validated by the API server anyway — they were essentially documentation-only markers. Happy to adjust the approach if you'd prefer a different direction. |
|
Updated research — my earlier comment had some inaccuracies. Here's the corrected picture: What other kube-native projects doEvery major project keeps
Why no one strips them
Current PR approachThis PR (as revised) removes all stripping logic and adds a brief Makefile comment for contributors who encounter warnings on older K8s versions. This matches what the rest of the ecosystem does. |
Summary
Fixes #1318
Changes
format: int64andformat: int32from 12 CRD YAML filesSigned-off-by: opspawn opspawn@users.noreply.github.com