Skip to content

Commit

Permalink
build/vmagent: set STS serviceName for headless service with non em…
Browse files Browse the repository at this point in the history
…pty shardCount

Previously, `serviceName` param for `VMAgent` with `statefulMode` and shardCount != nil was not set.

 It caused an issue with headless service routing. By default, kubernetes expects it to be the same
as Statefulset name. But for sharded `VMAgent` operator creates multiple StatefulSets with a single Service.

Consider the following example:
* headless service name - `vmagent-main`
* statefulsets shard names - `vmagent-main-0`, `vmagent-main-1`

 Kubernetes expects corresponding Service to exist. But since operator defines only a single Service.
It requires to set `serviceName: vmagent-main` for each StatefulSet.

 This issue makes dns name: `vmagent-main-0-0.vmagent-main.default.svc` unreachable.

 This commit fixes it by explicitly set `serviceName` for `shardCount != nil`.

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Dec 30, 2024
1 parent 5e0854a commit 275b0bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ aliases:

## tip

* BUGFIX: [vmagent](https://docs.victoriametrics.com/operator/resources/vmagent/): properly route headless service traffic to vmagent `pods` with `statefulMode` and `shardCount` defined.

## [v0.51.2](https://github.com/VictoriaMetrics/operator/releases/tag/v0.51.2)

**Release date:** 23 Dec 2024
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/operator/factory/vmagent/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ func buildSTSServiceName(cr *vmv1beta1.VMAgent) string {
cr.Spec.ServiceSpec.Spec.ClusterIP == corev1.ClusterIPNone {
return cr.Spec.ServiceSpec.NameOrDefault(cr.PrefixedName())
}
// special case for sharded mode
if cr.Spec.ShardCount != nil {
return cr.PrefixedName()
}
return ""
}

Expand Down

0 comments on commit 275b0bb

Please sign in to comment.