mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
apiserver identity : use SHA256 hash in lease names
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
This commit is contained in:
parent
62e9df085a
commit
5b3a9e2d75
@ -18,8 +18,9 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -335,9 +336,8 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
|
|||||||
klog.Fatalf("error getting hostname for apiserver identity: %v", err)
|
klog.Fatalf("error getting hostname for apiserver identity: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h := fnv.New32a()
|
hash := sha256.Sum256([]byte(hostname))
|
||||||
h.Write([]byte(hostname))
|
id = "kube-apiserver-" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:16]))
|
||||||
id = "kube-apiserver-" + fmt.Sprint(h.Sum32())
|
|
||||||
}
|
}
|
||||||
lifecycleSignals := newLifecycleSignals()
|
lifecycleSignals := newLifecycleSignals()
|
||||||
|
|
||||||
|
@ -18,9 +18,11 @@ package controlplane
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -44,9 +46,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func expectedAPIServerIdentity(hostname string) string {
|
func expectedAPIServerIdentity(hostname string) string {
|
||||||
h := fnv.New32a()
|
hash := sha256.Sum256([]byte(hostname))
|
||||||
h.Write([]byte(hostname))
|
return "kube-apiserver-" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:16]))
|
||||||
return "kube-apiserver-" + fmt.Sprint(h.Sum32())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateLeaseOnStart(t *testing.T) {
|
func TestCreateLeaseOnStart(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user