From e3017e38e3921734a1d1d82ef67c9890efcd49ec Mon Sep 17 00:00:00 2001 From: guoshiuan Date: Wed, 11 Sep 2024 14:30:25 -0700 Subject: [PATCH] Keep kernel.pid_max smaller than 1048575. (#565) * Keep the kernel.pid_max smaller than 1048575. * Revise format and comment. --- topo/topo.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/topo/topo.go b/topo/topo.go index 41a91292..affdcc9f 100644 --- a/topo/topo.go +++ b/topo/topo.go @@ -19,6 +19,7 @@ import ( "fmt" "io" "os" + "path/filepath" "strings" "time" @@ -29,6 +30,7 @@ import ( "github.com/openconfig/gnmi/errlist" "github.com/openconfig/kne/cluster/kind" "github.com/openconfig/kne/events" + "github.com/openconfig/kne/exec/run" "github.com/openconfig/kne/metrics" "github.com/openconfig/kne/pods" cpb "github.com/openconfig/kne/proto/controller" @@ -45,6 +47,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + "k8s.io/client-go/util/homedir" log "k8s.io/klog/v2" _ "github.com/openconfig/kne/topo/node/alpine" @@ -61,6 +64,7 @@ import ( ) var ( + setPIDMaxScript = filepath.Join(homedir.HomeDir(), "kne-internal", "set_pid_max.sh") protojsonUnmarshaller = protojson.UnmarshalOptions{ AllowPartial: true, DiscardUnknown: false, @@ -484,6 +488,14 @@ func (m *Manager) load() error { uid++ } for k, n := range nMap { + // Bug: Some vendors incorrectly increase the value of kernel.pid_max which + // causes other vendors to have issues. Run this script as a temporary + // workaround. + if _, err := os.Stat(setPIDMaxScript); err == nil { + if err := run.LogCommand(setPIDMaxScript); err != nil { + return fmt.Errorf("failed to exec set_pid_max script: %w", err) + } + } log.Infof("Adding Node: %s:%s", n.Name, n.Vendor) nn, err := node.New(m.topo.Name, n, m.kClient, m.rCfg, m.basePath, m.kubecfg) if err != nil {