-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ensure safe names for generated agent pods #19
Conversation
pkg/controller/ippool/common.go
Outdated
@@ -25,7 +26,7 @@ func prepareAgentPod( | |||
agentServiceAccountName string, | |||
agentImage *config.Image, | |||
) *corev1.Pod { | |||
name := fmt.Sprintf("%s-%s-agent", ipPool.Namespace, ipPool.Name) | |||
name := name.SafeConcatName(ipPool.Namespace, ipPool.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an IPPool in harvester-public/vlan1
. For the initial design, the name is:
harvester-system harvester-public-vlan1-agent
and the new implementation is
harvester-system harvester-public-vlan1
Maybe we can still consider adding a prefix here to make the pod name make more sense (say it's a dhcp agent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a slight change to the SafeConcatName to incorporate the "-agent" suffix. PTAL, thanks!
b70b1a6
to
430469f
Compare
|
||
func SafeAgentConcatName(name ...string) string { | ||
fullPath := strings.Join(name, "-") | ||
if len(fullPath) < 58 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious about why 58, should we add a name for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function was a modified version of https://github.com/rancher/wrangler/blob/004384a454ec6062420e10439bf9fa136fa38e4d/pkg/name/name.go#L56-L70 to incorporate the -agent
suffix. The reason (the characters limit) behind that is something about DNS name resolution (Object Names and IDs | Kubernetes)
digest := sha256.Sum256([]byte(fullPath)) | ||
// since we cut the string in the middle, the last char may not be compatible with what is expected in k8s | ||
// we are checking and if necessary removing the last char | ||
c := fullPath[50] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also curious about why 50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is because when we cut down the long token, we cannot be sure it won't accidentally collide with another name on the system. So, here, we preserve a little more space for incorporating a short and hashed string to make it unique.
Signed-off-by: Zespre Chang <[email protected]>
430469f
to
3fd6799
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
IMPORTANT: Please do not create a Pull Request without creating an issue first.
Problem:
Solution:
Related Issue:
harvester/harvester#5072
Test plan:
fi6cx9ca1kt1faq80k3ro9cowyumyjb67qdmg8fb9ydmz27rbk5btlg2m5avv3n