apiserver identity: use persistent identity format based on hostname

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
This commit is contained in:
Andrew Sy Kim 2022-10-24 11:24:26 -04:00
parent 208b2b7ca9
commit 21507902ba
2 changed files with 19 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"os"
"reflect" "reflect"
"strconv" "strconv"
"time" "time"
@ -515,6 +516,14 @@ func labelAPIServerHeartbeat(lease *coordinationapiv1.Lease) error {
} }
// This label indicates that kube-apiserver owns this identity lease object // This label indicates that kube-apiserver owns this identity lease object
lease.Labels[IdentityLeaseComponentLabelKey] = KubeAPIServer 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 return nil
} }

View File

@ -19,8 +19,10 @@ package server
import ( import (
"context" "context"
"fmt" "fmt"
"hash/fnv"
"net" "net"
"net/http" "net/http"
"os"
goruntime "runtime" goruntime "runtime"
"runtime/debug" "runtime/debug"
"sort" "sort"
@ -328,7 +330,14 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz} defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz}
var id string var id string
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerIdentity) { 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() lifecycleSignals := newLifecycleSignals()