Merge pull request #113649 from andrewsykim/apiserver-identity-hash

apiserver identity : use SHA256 hash in lease names
This commit is contained in:
Kubernetes Prow Robot 2022-11-07 11:20:49 -08:00 committed by GitHub
commit 3d5725d9c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -18,8 +18,9 @@ package server
import (
"context"
"crypto/sha256"
"encoding/base32"
"fmt"
"hash/fnv"
"net"
"net/http"
"os"
@ -335,9 +336,8 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
klog.Fatalf("error getting hostname for apiserver identity: %v", err)
}
h := fnv.New32a()
h.Write([]byte(hostname))
id = "kube-apiserver-" + fmt.Sprint(h.Sum32())
hash := sha256.Sum256([]byte(hostname))
id = "kube-apiserver-" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:16]))
}
lifecycleSignals := newLifecycleSignals()

View File

@ -18,9 +18,11 @@ package controlplane
import (
"context"
"crypto/sha256"
"encoding/base32"
"fmt"
"hash/fnv"
"os"
"strings"
"testing"
"time"
@ -44,9 +46,8 @@ const (
)
func expectedAPIServerIdentity(hostname string) string {
h := fnv.New32a()
h.Write([]byte(hostname))
return "kube-apiserver-" + fmt.Sprint(h.Sum32())
hash := sha256.Sum256([]byte(hostname))
return "kube-apiserver-" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:16]))
}
func TestCreateLeaseOnStart(t *testing.T) {