学习来源,新增一个ReplicaSet和kubevirt对应的实现。
对应的代码处于的k8s源码的位置已标注。
1. kube-controller-manager等的名称(自实现rand)
staging/src/k8s.io/apimachinery/pkg/util/rand/rand.go
const (
// We omit vowels from the set of available characters to reduce the chances
// of "bad words" being formed.
alphanums = "bcdfghjklmnpqrstvwxz2456789"
// No. of bits required to index into alphanums string.
alphanumsIdxBits = 5
// Mask used to extract last alphanumsIdxBits of an int.
alphanumsIdxMask = 1<<alphanumsIdxBits - 1
// No. of random letters we can extract from a single int63.
maxAlphanumsPerInt = 63 / alphanumsIdxBits
)
// String generates a random alphanumeric string, without vowels, which is n
// characters long. This will panic if n is less than zero.
// How the random string is created:
// - we generate random int63's
// - from each int63, we are extracting multiple random letters by bit-shifting and masking
// - if some index is out of range of alphanums we neglect it (unlikely to happen multiple times in a row)
func String(n int) string {
b := make([]byte, n)
rng.Lock()
defer rng.Unlock()
randomInt63 := rng.rand.Int63()
remaining := maxAlphanumsPerInt
for i := 0; i < n; {
if remaining == 0 {
randomInt63, remaining = rng.rand.Int63(), maxAlphanumsPerInt
}
if idx := int(randomInt63 & alphanumsIdxMask); idx < len(alphanums) {
b[i]

本文深入探讨了Kubernetes中的命名机制,包括kube-controller-manager、StatefulSet、ReplicaSet和kubevirt克隆的命名策略。详细介绍了源码位置,如stateful_set_utils.go、controller_utils.go和util.go,阐述了如何生成随机名、正则表达式以及通过hash加密来确定名称。
最低0.47元/天 解锁文章
8804

被折叠的 条评论
为什么被折叠?



