mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
apiserver identity: use persistent identity format based on hostname
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
This commit is contained in:
parent
208b2b7ca9
commit
21507902ba
@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -515,6 +516,14 @@ func labelAPIServerHeartbeat(lease *coordinationapiv1.Lease) error {
|
||||
}
|
||||
// This label indicates that kube-apiserver owns this identity lease object
|
||||
lease.Labels[IdentityLeaseComponentLabelKey] = KubeAPIServer
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// convenience label to easily map a lease object to a specific apiserver
|
||||
lease.Labels[apiv1.LabelHostname] = hostname
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,10 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
goruntime "runtime"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
@ -328,7 +330,14 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
|
||||
defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz}
|
||||
var id string
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerIdentity) {
|
||||
id = "kube-apiserver-" + uuid.New().String()
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
klog.Fatalf("error getting hostname for apiserver identity: %v", err)
|
||||
}
|
||||
|
||||
h := fnv.New32a()
|
||||
h.Write([]byte(hostname))
|
||||
id = "kube-apiserver-" + fmt.Sprint(h.Sum32())
|
||||
}
|
||||
lifecycleSignals := newLifecycleSignals()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user