VMCluster/VMAlertmanager: reject serviceSpec.type override with useAsDefault - #2491
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
AndrewChubatiuk
left a comment
There was a problem hiding this comment.
Thanks for a PR! Overall it's good, left some comments. Same changes probably should be propagated to all select and storage components as they also unconditionally set ClusterIP type
| // ValidateNoServiceTypeOverrideWithUseAsDefault rejects an explicit service type | ||
| // combined with useAsDefault for components whose default service is headless | ||
| // (vmselect, vmstorage, vmalertmanager). Those services must stay headless | ||
| // (clusterIP: None) for cluster-native communication: an explicit type: ClusterIP | ||
| // would be silently ignored (the headless clusterIP is inherited from the default | ||
| // service), while type: LoadBalancer/NodePort would be honored and produce a | ||
| // non-headless service that breaks cluster-native discovery. Reject the combination | ||
| // loudly so users pick an intended setup: drop the type override, or create a | ||
| // separate additional service (useAsDefault=false with a distinct metadata.name). |
There was a problem hiding this comment.
please make this comment brief, it's a trivial check not need to have this multiline explanantion
| return nil | ||
| } | ||
| if asc.Spec.Type != "" { | ||
| return fmt.Errorf("serviceSpec.useAsDefault cannot be combined with an explicit spec.type=%q for %s: the default service is headless (clusterIP: None) and must stay headless for cluster-native communication (an explicit type is either silently ignored or produces a non-headless service that breaks it). Remove spec.type from the serviceSpec override, or create a separate service by setting serviceSpec.useAsDefault=false with a distinct metadata.name", asc.Spec.Type, component) |
There was a problem hiding this comment.
same is here, additionally no need to pass component name here,
…tion (VictoriaMetrics#2491) - Shorten the helper GoDoc/rationale comment (it was a trivial check, no need for the multiline explanation). - Remove the unused component-name parameter from ValidateNoServiceTypeOverrideWithUseAsDefault(); the error message no longer references a specific component. - Correct the rationale: the default service must stay headless (clusterIP: None) for cluster-native communication; an explicit spec.type with useAsDefault=true is rejected so users pick an intended setup (per VictoriaMetrics#2487). - Applied to vmselect, vmstorage (VMCluster) and vmalertmanager. vminsert is intentionally left allowed: its default Service is not headless, so an explicit type override there works as expected. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
|
Thanks @AndrewChubatiuk — addressed the feedback:
On propagation to all select/storage components: I deliberately kept vminsert allowed, because its default Service is not headless (unlike vmselect/vmstorage/vmalertmanager), so an explicit type override there works as intended and shouldn't be rejected. If you'd still like vminsert covered (or the standalone CRDs like VMAgent/VMAlert/VMSingle), let me know and I'll extend it. Force-pushed |
What
Follows up on #2487. As discussed in the issue, the default Service of
vmselect,vmstorageandvmalertmanageris intentionally headless (clusterIP: None) because it also exposes cluster-native / gossip ports. Because of that, combiningserviceSpec.useAsDefault: truewith an explicitspec.typesilently produces a service that is still headless - the user gets no error and no VIP, which is confusing.Per the maintainer's suggestion in #2487 (comment) (prohibit overriding the service type for these components when
useAsDefault: true), this PR makes the operator reject that combination with a clear error message instead of silently ignoring it.Changes
AdditionalServiceSpec.ValidateNoServiceTypeOverrideWithUseAsDefault(component)- new helper that rejects an explicitspec.typewhenuseAsDefaultis set.VMCluster.Validate()forvmselectandvmstorage.VMAlertmanager.Validate()forvmalertmanager.vminsertis intentionally left allowed: its default Service is not headless, so an explicit type override there works as expected.Users who need a different service type can still create a separate additional Service by setting
serviceSpec.useAsDefault: falsewith a distinctmetadata.name.Tests
Added unit test cases covering: reject for vmselect/vmstorage/vmalertmanager, allow when no explicit type is set, allow separate additional services, and allow type override for vminsert.
Feedback welcome - happy to adjust the error message wording or the scope if you'd rather also cover
vminsert.