fix: add metadata.name length and format validation to all CRDs#1113
fix: add metadata.name length and format validation to all CRDs#1113IshwarKanse wants to merge 2 commits into
Conversation
|
Hi @IshwarKanse. Thanks for your PR. I'm waiting for a rhobs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
Warning Review limit reached
More reviews will be available in 57 minutes and 36 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (23)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: IshwarKanse 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 |
6130c69 to
e66cece
Compare
…nstaller CRD Assisted by Claude Code
f9e6340 to
f735c65
Compare
|
I'm surprised that you can create the |
|
|
I think that's a more systemic issue than just the |
|
@simonpasquier Yes, I added the fix currently for ObservabilityInstaller but this needs to be fixed globally as it affects CRD validation on all affected types. Do you want me to add the validation for all the affected types as well. ? We could fix util.AddCommonLabels to truncate long names — cap the label value at 63 characters (e.g. truncate to 57 chars + ashort hash suffix to keep uniqueness). This fixes all callers in one place but means the label no longer directly reflects the resource name, which would cause confusion for anyone using label selectors like app.kubernetes.io/part-of= Enforcing the limit at admission time with a clear error message seems like the right UX — users know immediately what to fix and why. The label always remains trustworthy. |
d508c13 to
e1635c0
Compare
|
@simonpasquier I updated the PR to fix this issue for all types. |
Summary
Resolves https://redhat.atlassian.net/browse/COO-1261
The
app.kubernetes.io/part-oflabel value is set from the owner resource's.metadata.nameviautil.AddCommonLabels. Kubernetes enforces a hard 63-character limit on label values, so CR names exceeding that length caused repeated reconciliation failures with no path to recovery.This PR fixes the issue at two layers (defence in depth):
Layer 1 — CRD admission validation (primary guard)
Added two CEL
x-kubernetes-validationsrules at the rootopenAPIV3Schemalevel for all three affected CRDs (ObservabilityInstaller,MonitoringStack,ThanosQuerier):size(self.metadata.name) <= 63— enforces the Kubernetes label-value length limitself.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')— enforces RFC 1123 DNS label formatRules are applied to both
bundle/manifests/anddeploy/crds/common/CRD YAMLs and backed by+kubebuilder:validation:XValidationmarkers in the Go types so they survive futuregenerate-crdsruns.Layer 2 — Runtime guard in
AddCommonLabels(secondary / defensive)Changed
util.AddCommonLabelssignature from(client.Object, string) client.Objectto(client.Object, string) (client.Object, error). The function now returns a hard error for names > 63 characters instead of silently producing invalid label values.Error propagation (all controllers)
To surface the new error cleanly, introduced a
ReconcilerBuilderaccumulator inpkg/reconciler/reconciler.go. It short-circuits on the first error so component builder functions (stackComponentReconcilers,thanosComponentReconcilers,pluginComponentReconcilers,operatorComponentReconcilers,observabilityreconcilers) can callb.Add(reconciler.NewUpdater(...))without per-call error handling. All reconciler constructors that callAddCommonLabelsnow return(Reconciler, error).Pre-existing bug fix (CodeRabbit)
Fixed a missing hyphen in the
UIPluginClusterRoleBinding name:plugin.Name+"cluster-monitoring-view"→plugin.Name+"-cluster-monitoring-view"Files changed
pkg/controllers/util/common.goAddCommonLabelsreturns(client.Object, error); rejects names > 63 charspkg/controllers/util/common_test.goAddCommonLabelspkg/reconciler/reconciler.goReconcilerBuilderaccumulator; all constructors return errorspkg/reconciler/create_update_reconciler.goAddCommonLabelspkg/controllers/monitoring/monitoring-stack/components.goReconcilerBuilder; returns errorpkg/controllers/monitoring/monitoring-stack/controller.gostackComponentReconcilerspkg/controllers/monitoring/thanos-querier/components.goReconcilerBuilder; returns errorpkg/controllers/monitoring/thanos-querier/controller.gothanosComponentReconcilerspkg/controllers/uiplugin/components.goReconcilerBuilder; returns error; fixes ClusterRoleBinding namepkg/controllers/uiplugin/controller.gopluginComponentReconcilersandNewMergerpkg/controllers/operator/components.goReconcilerBuilder; returns errorpkg/controllers/operator/controller.gooperatorComponentReconcilerspkg/controllers/observability/reconcilers.goNewCreateUpdateReconcilerandNewUpdaterpkg/apis/monitoring/v1alpha1/types.goMonitoringStackandThanosQuerierpkg/apis/monitoring/v1alpha1/types_test.goMonitoringStackandThanosQuerierpkg/apis/observability/v1alpha1/types.goObservabilityInstaller(first commit)pkg/apis/observability/v1alpha1/types_test.goObservabilityInstaller(first commit)bundle/manifests/monitoring.rhobs_monitoringstacks.yamlx-kubernetes-validationsbundle/manifests/monitoring.rhobs_thanosqueriers.yamlx-kubernetes-validationsbundle/manifests/observability.openshift.io_observabilityinstallers.yamlx-kubernetes-validations(first commit)deploy/crds/common/monitoring.rhobs_monitoringstacks.yamlx-kubernetes-validationsdeploy/crds/common/monitoring.rhobs_thanosqueriers.yamlx-kubernetes-validationsdeploy/crds/common/observability.openshift.io_observabilityinstallers.yamlx-kubernetes-validations(first commit)Test plan
pkg/controllers/util/common_test.go: covers valid names (≤ 63 chars), boundary (exactly 63), over-length (64, 108), label preservation, and nil-label initialisationpkg/apis/monitoring/v1alpha1/types_test.go: extracts rules from source annotations via regex and evaluates them withcel-gofor bothMonitoringStackandThanosQuerier(length and format)pkg/apis/observability/v1alpha1/types_test.go: same forObservabilityInstallergo test ./pkg/...andcd pkg/apis && go test ./...go buildandgo vetclean across the moduleTestUIPlugin/Cluster_health_analyzertimed out due to alert-firing latency on a fresh cluster (pre-existing, unrelated to this change)