Move Kubernetes API calls into kube-utils program
This reduces the size of the 'weaver' binary.
This commit is contained in:
1 parent
164175160a
commit
ad621c807e
3 files changed
+30
-35
No files matched your search
@@ -314,6 +314,8 @@ func main() {
|
|||||||
justReclaim bool
|
justReclaim bool
|
||||||
justCheck bool
|
justCheck bool
|
||||||
justSetNodeStatus bool
|
justSetNodeStatus bool
|
||||||
|
justVersion bool
|
||||||
|
justUID bool
|
||||||
peerName string
|
peerName string
|
||||||
nodeName string
|
nodeName string
|
||||||
logLevel string
|
logLevel string
|
||||||
@@ -323,6 +325,8 @@ func main() {
|
|||||||
flag.BoolVar(&runReclaimDaemon, "run-reclaim-daemon", false, "run background process that reclaim IP space from dead peers ")
|
flag.BoolVar(&runReclaimDaemon, "run-reclaim-daemon", false, "run background process that reclaim IP space from dead peers ")
|
||||||
flag.BoolVar(&justCheck, "check-peer-new", false, "return success if peer name is not stored in annotation")
|
flag.BoolVar(&justCheck, "check-peer-new", false, "return success if peer name is not stored in annotation")
|
||||||
flag.BoolVar(&justSetNodeStatus, "set-node-status", false, "set NodeNetworkUnavailable to false")
|
flag.BoolVar(&justSetNodeStatus, "set-node-status", false, "set NodeNetworkUnavailable to false")
|
||||||
|
flag.BoolVar(&justVersion, "print-k8s-version", false, "print the Kubernetes version and exit")
|
||||||
|
flag.BoolVar(&justUID, "print-uid", false, "print a UID for this installation and exit")
|
||||||
flag.StringVar(&peerName, "peer-name", "unknown", "name of this Weave Net peer")
|
flag.StringVar(&peerName, "peer-name", "unknown", "name of this Weave Net peer")
|
||||||
flag.StringVar(&nodeName, "node-name", "unknown", "name of this Kubernetes node")
|
flag.StringVar(&nodeName, "node-name", "unknown", "name of this Kubernetes node")
|
||||||
flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
|
flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
|
||||||
@@ -371,6 +375,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if justVersion {
|
||||||
|
k8sVersion, err := c.Discovery().ServerVersion()
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Fatalf("[kube-peers] Could not get Kubernetes version: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println(k8sVersion.String())
|
||||||
|
}
|
||||||
|
if justUID {
|
||||||
|
// use UID of `weave-net` configmap as unique ID of the Kubernetes cluster
|
||||||
|
cm, err := c.CoreV1().ConfigMaps(configMapNamespace).Get(context.Background(), configMapName, api.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Fatalf("Unable to fetch ConfigMap %s/%s to infer unique cluster ID", configMapNamespace, configMapName)
|
||||||
|
}
|
||||||
|
fmt.Println(cm.ObjectMeta.UID)
|
||||||
|
}
|
||||||
if runReclaimDaemon {
|
if runReclaimDaemon {
|
||||||
// Handle SIGINT and SIGTERM
|
// Handle SIGINT and SIGTERM
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ fi
|
|||||||
# weaver is running as the DB can only be opened by one process at a time
|
# weaver is running as the DB can only be opened by one process at a time
|
||||||
/usr/bin/weaveutil set-db-flag "$DB_PREFIX" peer-reclaim ok
|
/usr/bin/weaveutil set-db-flag "$DB_PREFIX" peer-reclaim ok
|
||||||
|
|
||||||
|
# couple more variables
|
||||||
|
WEAVE_KUBERNETES_VERSION=$(/home/weave/kube-utils -print-k8s-version)
|
||||||
|
WEAVE_KUBERNETES_UID=$(/home/weave/kube-utils -print-uid)
|
||||||
|
|
||||||
post_start_actions() {
|
post_start_actions() {
|
||||||
# Wait for weave process to become responsive
|
# Wait for weave process to become responsive
|
||||||
while true ; do
|
while true ; do
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ import (
|
|||||||
|
|
||||||
checkpoint "github.com/weaveworks/go-checkpoint"
|
checkpoint "github.com/weaveworks/go-checkpoint"
|
||||||
weave "github.com/weaveworks/weave/router"
|
weave "github.com/weaveworks/weave/router"
|
||||||
api "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/client-go/kubernetes"
|
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var checker *checkpoint.Checker
|
var checker *checkpoint.Checker
|
||||||
@@ -20,9 +17,7 @@ var newVersion atomic.Value
|
|||||||
var success atomic.Value
|
var success atomic.Value
|
||||||
|
|
||||||
const (
|
const (
|
||||||
updateCheckPeriod = 6 * time.Hour
|
updateCheckPeriod = 6 * time.Hour
|
||||||
configMapName = "weave-net"
|
|
||||||
configMapNamespace = "kube-system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkForUpdates(dockerVersion string, router *weave.NetworkRouter, clusterSize uint) {
|
func checkForUpdates(dockerVersion string, router *weave.NetworkRouter, clusterSize uint) {
|
||||||
@@ -88,36 +83,13 @@ func checkpointFlags(router *weave.NetworkRouter) []checkpoint.Flag {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkpoint Kubernetes specific details
|
// checkpoint Kubernetes specific details, passed in from launch script
|
||||||
func checkpointKubernetes(ctx context.Context, flags map[string]string, clusterSize uint) {
|
func checkpointKubernetes(ctx context.Context, flags map[string]string, clusterSize uint) {
|
||||||
// checks if weaver is running in Kubernetes
|
version := os.Getenv("WEAVE_KUBERNETES_VERSION")
|
||||||
host := os.Getenv("KUBERNETES_SERVICE_HOST")
|
if len(version) == 0 {
|
||||||
if len(host) == 0 {
|
return // not running under Kubernetes
|
||||||
return
|
|
||||||
}
|
}
|
||||||
config, err := rest.InClusterConfig()
|
flags["kubernetes-version"] = version
|
||||||
if err != nil {
|
flags["kubernetes-cluster-uid"] = string(os.Getenv("WEAVE_KUBERNETES_UID"))
|
||||||
Log.Printf("Could not get Kubernetes in-cluster config: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c, err := kubernetes.NewForConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
Log.Printf("Could not make Kubernetes client: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
k8sVersion, err := c.Discovery().ServerVersion()
|
|
||||||
if err != nil {
|
|
||||||
Log.Printf("Could not get Kubernetes version: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
flags["kubernetes-version"] = k8sVersion.String()
|
|
||||||
|
|
||||||
// use UID of `weave-net` configmap as unique ID of the Kubenerets cluster
|
|
||||||
cm, err := c.CoreV1().ConfigMaps(configMapNamespace).Get(ctx, configMapName, api.GetOptions{})
|
|
||||||
if err != nil {
|
|
||||||
Log.Printf("Unable to fetch ConfigMap %s/%s to infer unique cluster ID", configMapNamespace, configMapName)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
flags["kubernetes-cluster-uid"] = string(cm.ObjectMeta.UID)
|
|
||||||
flags["kubernetes-cluster-size"] = fmt.Sprint(clusterSize)
|
flags["kubernetes-cluster-size"] = fmt.Sprint(clusterSize)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user