Skip to content

Commit

Permalink
spiderpool-agent: support to configure the sysctl config
Browse files Browse the repository at this point in the history
Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
  • Loading branch information
cyclinder committed Jul 25, 2024
1 parent 2dd7749 commit ba63403
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
6 changes: 6 additions & 0 deletions charts/spiderpool/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ data:
enabled: {{ .Values.dra.enabled }}
cdiRootPath: {{ .Values.dra.cdiRootPath }}
hostDevicePath: {{ .Values.dra.hostDevicePath }}
{{- if .Values.spiderpoolAgent.sysctlConfigs }}
sysctlConfigs:
{{- with .Values.spiderpoolAgent.sysctlConfigs }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- if .Values.multus.multusCNI.install }}
---
kind: ConfigMap
Expand Down
10 changes: 10 additions & 0 deletions charts/spiderpool/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ spiderpoolAgent:
securityContext: {}
# runAsUser: 0

## @param spiderpoolAgent.sysctlConfigs the sysctl configs of spiderpoolAgent pod
sysctlConfigs:
net.ipv4.neigh.default.gc_thresh1: 0
net.ipv4.neigh.default.gc_thresh2: 512
net.ipv4.neigh.default.gc_thresh3: 8192
net.ipv6.neigh.default.gc_thresh3: 8192
net.ipv4.conf.all.arp_notify: 1
net.ipv4.conf.all.forwarding: 1
net.ipv6.conf.all.forwarding: 1

## @param spiderpoolAgent.httpPort the http Port for spiderpoolAgent, for health checking
httpPort: 5710

Expand Down
2 changes: 2 additions & 0 deletions cmd/spiderpool-agent/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func DaemonMain() {
}
logger.Sugar().Infof("Spiderpool-agent config: %+v", agentContext.Cfg)

// Setup sysctl

// Set up gops.
if agentContext.Cfg.GopsListenPort != "" {
address := "127.0.0.1:" + agentContext.Cfg.GopsListenPort
Expand Down
16 changes: 16 additions & 0 deletions cmd/spiderpool-controller/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/spidernet-io/spiderpool/pkg/manager/spidercliamparameter"
"github.com/spidernet-io/spiderpool/pkg/multuscniconfig"
"github.com/spidernet-io/spiderpool/pkg/namespacemanager"
"github.com/spidernet-io/spiderpool/pkg/networking/sysctl"

Check failure on line 38 in cmd/spiderpool-controller/cmd/daemon.go

View workflow job for this annotation

GitHub Actions / lint-golang

could not import github.com/spidernet-io/spiderpool/pkg/networking/sysctl (-: # github.com/spidernet-io/spiderpool/pkg/networking/sysctl
"github.com/spidernet-io/spiderpool/pkg/nodemanager"
"github.com/spidernet-io/spiderpool/pkg/openapi"
"github.com/spidernet-io/spiderpool/pkg/podmanager"
Expand Down Expand Up @@ -81,6 +82,11 @@ func DaemonMain() {
}
logger.Sugar().Infof("Spiderpool-controller config: %+v", controllerContext.Cfg)

// setup sysctls
if err := sysctlConfig(controllerContext.Cfg.SysctlConfig); err != nil {
logger.Sugar().Fatal(err)
}

// Set up gops.
if controllerContext.Cfg.GopsListenPort != "" {
address := "127.0.0.1:" + controllerContext.Cfg.GopsListenPort
Expand Down Expand Up @@ -605,3 +611,13 @@ func checkWebhookReady() {
break
}
}

// sysctlConfig set all sysctl config from given user configs.
func sysctlConfig(sysctlConfig map[string]string) error {
for sc, value := range sysctlConfig {
if err := sysctl.SetSysctl(sc, value); err != nil {
return err
}
}
return nil
}
23 changes: 22 additions & 1 deletion pkg/networking/sysctl/sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ package sysctl

import (
"fmt"
"os"
"strconv"

Check failure on line 9 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

"strconv" imported and not used

Check failure on line 9 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

"strconv" imported and not used

Check failure on line 9 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

"strconv" imported and not used

Check failure on line 9 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

"strconv" imported and not used
"strings"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
"os"
)

// SysctlRPFilter set rp_filter value for host netns and specify netns
Expand Down Expand Up @@ -77,3 +80,21 @@ func EnableIpv6Sysctl(netns ns.NetNS) error {
})
return err
}

func SetSysctl(sysConfig string, value string) error {
// sysConfig: net.ipv6.neigh.default.gc_thresh3
// to: net/ipv6/neigh/default/gc_thresh3
sysConfig = strings.ReplaceAll(sysConfig, ".", "/")
sysConfig = fmt.Sprintf("/proc/sys/%s", sysConfig)

_, err := os.Stat(sysConfig)
if err != nil {
return fmt.Errorf("invalis sysctl %s, failed to set: %w", sysConfig, err)
}

if err := sysctl.Sysctl(sysConfig, value); err != nil {

Check failure on line 95 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

assignment mismatch: 1 variable but sysctl.Sysctl returns 2 values (typecheck)

Check failure on line 95 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

assignment mismatch: 1 variable but sysctl.Sysctl returns 2 values) (typecheck)

Check failure on line 95 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

assignment mismatch: 1 variable but sysctl.Sysctl returns 2 values) (typecheck)

Check failure on line 95 in pkg/networking/sysctl/sysctl.go

View workflow job for this annotation

GitHub Actions / lint-golang

assignment mismatch: 1 variable but sysctl.Sysctl returns 2 values
return fmt.Errorf("error to set sysctl %s to %s: %w", sysConfig, value, err)
}

return nil
}
3 changes: 2 additions & 1 deletion pkg/types/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ type AutoPoolProperty struct {
}

type SpiderpoolConfigmapConfig struct {
DraConfig `yaml:"dra"`
IpamUnixSocketPath string `yaml:"ipamUnixSocketPath"`
EnableIPv4 bool `yaml:"enableIPv4"`
EnableIPv6 bool `yaml:"enableIPv6"`
Expand All @@ -118,6 +117,8 @@ type SpiderpoolConfigmapConfig struct {
EnableSpiderSubnet bool `yaml:"enableSpiderSubnet"`
EnableAutoPoolForApplication bool `yaml:"enableAutoPoolForApplication"`
ClusterSubnetAutoPoolDefaultRedundantIPNumber int `yaml:"clusterSubnetAutoPoolDefaultRedundantIPNumber"`
DraConfig `yaml:"dra"`
SysctlConfig map[string]string `yaml:"sysctlConfig"`
}

type DraConfig struct {
Expand Down

0 comments on commit ba63403

Please sign in to comment.