Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
k8sutil: extend rand suffix length to 10 (#1882)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongchaodeng committed Jan 24, 2018
1 parent 75306f9 commit 243e785
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/util/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const (
serverTLSVolume = "member-server-tls"
operatorEtcdTLSDir = "/etc/etcdtls/operator/etcd-tls"
operatorEtcdTLSVolume = "etcd-client-tls"

randomSuffixLength = 10
// k8s object name has a maximum length
maxNameLength = 63 - randomSuffixLength - 1
)

const TolerateUnreadyEndpointsAnnotation = "service.alpha.kubernetes.io/tolerate-unready-endpoints"
Expand Down Expand Up @@ -474,5 +478,9 @@ func mergeLabels(l1, l2 map[string]string) {
}

func UniqueMemberName(clusterName string) string {
return fmt.Sprintf("%s-%s", clusterName, utilrand.String(5))
suffix := utilrand.String(randomSuffixLength)
if len(clusterName) > maxNameLength {
clusterName = clusterName[:maxNameLength]
}
return clusterName + "-" + suffix
}

0 comments on commit 243e785

Please sign in to comment.