Skip to content

cmd/k8s-operator: fix base truncating for extra long Service names - #10825

Merged
irbekrm merged 2 commits into
mainfrom
irbekrm/longnames2
Jan 11, 2024
Merged

irbekrm merged 2 commits into
mainfrom
irbekrm/longnames2

Conversation

@irbekrm

@irbekrm irbekrm commented Jan 11, 2024 •

Copy link
Copy Markdown
Contributor

Context

StatefulSet names for ingress/egress proxies are calculated using Kubernetes name generator and the parent resource name as a base.
We currently try pre-calculate how long the generated name will be and cut the base it is to be longer than 52 chars, see #10343.

Problem

The name generator also cuts the base, but has a higher max cap. This commit fixes a bug where, if we get a shortened base back from the generator, we cut off too little as the base that we have cut will be passed into the generator again, which will then itself cut less because the base is shorter- so we end up with a too long name again.

Fix

This PR fixes it by cutting recursively to ensure that, if the cut base produces a longer name again after being put through the name generator, we cut again till we ensure that the generated name will definitely be no longer than 52 chars.

Notes

The longest Service name supported before this fix is 54 chars. I have tested that with the contents of this PR vs latest release and verified that both produced the same base (so that the change in this PR does not calculate different names for existing StatefulSets)

Updates #10807

@irbekrm
irbekrm force-pushed the irbekrm/longnames2 branch from 5a66e0b to 0530e98 Compare January 11, 2024 18:01
@irbekrm
irbekrm requested review from knyar and maisem January 11, 2024 18:31
Comment thread cmd/k8s-operator/sts.go Resolved
StatefulSet names for ingress/egress proxies are calculated
using Kubernetes name generator and the parent resource name
as a base.
The name generator also cuts the base, but has a higher max cap.
This commit fixes a bug where, if we get a shortened base back
from the generator, we cut off too little as the base that we
have cut will be passed into the generator again, which will
then itself cut less because the base is shorter- so we end up
with a too long name again.

Updates #10807

Signed-off-by: Irbe Krumina <[email protected]>
@irbekrm
irbekrm force-pushed the irbekrm/longnames2 branch from 0530e98 to 2ac20d1 Compare January 11, 2024 18:58
@irbekrm irbekrm linked an issue Jan 11, 2024 that may be closed by this pull request
Comment thread cmd/k8s-operator/sts.go Resolved
Comment thread cmd/k8s-operator/sts_test.go Resolved
Comment thread cmd/k8s-operator/sts_test.go Resolved
@irbekrm
irbekrm force-pushed the irbekrm/longnames2 branch from edc97bc to 204f1fd Compare January 11, 2024 19:35
Co-authored-by: Maisem Ali <[email protected]>
Signed-off-by: Irbe Krumina <[email protected]>
Signed-off-by: Irbe Krumina <[email protected]>
@irbekrm
irbekrm force-pushed the irbekrm/longnames2 branch from 204f1fd to f25fab2 Compare January 11, 2024 19:47
@irbekrm
irbekrm merged commit 469af61 into main Jan 11, 2024
@irbekrm
irbekrm deleted the irbekrm/longnames2 branch January 11, 2024 20:02
Asutorufa pushed a commit to Asutorufa/tailscale that referenced this pull request Jan 19, 2024
…ailscale#10825)

cmd/k8s-operator: fix base truncating for extra long Service names

StatefulSet names for ingress/egress proxies are calculated
using Kubernetes name generator and the parent resource name
as a base.
The name generator also cuts the base, but has a higher max cap.
This commit fixes a bug where, if we get a shortened base back
from the generator, we cut off too little as the base that we
have cut will be passed into the generator again, which will
then itself cut less because the base is shorter- so we end up
with a too long name again.

Updates tailscale#10807

Co-authored-by: Maisem Ali <[email protected]>
Signed-off-by: Irbe Krumina <[email protected]>
chen8945 pushed a commit to Ckid-Home/tailscale that referenced this pull request Jul 31, 2024
…ailscale#10825)

cmd/k8s-operator: fix base truncating for extra long Service names

StatefulSet names for ingress/egress proxies are calculated
using Kubernetes name generator and the parent resource name
as a base.
The name generator also cuts the base, but has a higher max cap.
This commit fixes a bug where, if we get a shortened base back
from the generator, we cut off too little as the base that we
have cut will be passed into the generator again, which will
then itself cut less because the base is shorter- so we end up
with a too long name again.

Updates tailscale#10807

Co-authored-by: Maisem Ali <[email protected]>
Signed-off-by: Irbe Krumina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes Service can't be exposed if service name is long.

2 participants