Skip to content

Commit

Permalink
Connection limit for thick daemon.
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Hinze <[email protected]>
  • Loading branch information
juliusmh committed Nov 12, 2024
1 parent 781ecda commit 76b048b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/multus-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sync"
"syscall"

"golang.org/x/net/netutil"
utilwait "k8s.io/apimachinery/pkg/util/wait"

"gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
Expand Down Expand Up @@ -105,7 +106,7 @@ func main() {
}
}

if err := startMultusDaemon(ctx, daemonConf, ignoreReadinessIndicator); err != nil {
if err := startMultusDaemon(ctx, daemonConf, ignoreReadinessIndicator, daemonConf.ConnectionLimit); err != nil {
logging.Panicf("failed start the multus thick-plugin listener: %v", err)
os.Exit(3)
}
Expand Down Expand Up @@ -139,7 +140,7 @@ func main() {
logging.Verbosef("multus daemon is exited")
}

func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf, ignoreReadinessIndicator bool) error {
func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf, ignoreReadinessIndicator bool, connectionLimit *int) error {
if user, err := user.Current(); err != nil || user.Uid != "0" {
return fmt.Errorf("failed to run multus-daemon with root: %v, now running in uid: %s", err, user.Uid)
}
Expand All @@ -166,6 +167,11 @@ func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf,
return fmt.Errorf("failed to start the CNI server using socket %s. Reason: %+v", api.SocketPath(daemonConfig.SocketDir), err)
}

if limit := connectionLimit; limit != nil && *limit > 0 {
logging.Debugf("connection limit: %d", *limit)
l = netutil.LimitListener(l, *limit)
}

server.Start(ctx, l)

go func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type ControllerNetConf struct {
LogLevel string `json:"logLevel"`
LogToStderr bool `json:"logToStderr,omitempty"`
PerNodeCertificate *PerNodeCertificate `json:"perNodeCertificate,omitempty"`
ConnectionLimit *int `json:"connectionLimit,omitempty"`

MetricsPort *int `json:"metricsPort,omitempty"`

Expand Down
87 changes: 87 additions & 0 deletions vendor/golang.org/x/net/netutil/listen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ golang.org/x/net/http2
golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/internal/timeseries
golang.org/x/net/netutil
golang.org/x/net/trace
# golang.org/x/oauth2 v0.10.0
## explicit; go 1.17
Expand Down

0 comments on commit 76b048b

Please sign in to comment.