diff --git a/cmd/kperf/commands/virtualcluster/nodepool.go b/cmd/kperf/commands/virtualcluster/nodepool.go index 0c8ab29..97d746a 100644 --- a/cmd/kperf/commands/virtualcluster/nodepool.go +++ b/cmd/kperf/commands/virtualcluster/nodepool.go @@ -49,6 +49,11 @@ var nodepoolAddCommand = cli.Command{ Usage: "The allocatable Memory resource per node (GiB)", Value: 16, }, + cli.IntFlag{ + Name: "max-pods", + Usage: "The maximum Pods per node", + Value: 110, + }, cli.StringSliceFlag{ Name: "affinity", Usage: "Deploy controllers to the nodes with a specific labels (FORMAT: KEY=VALUE[,VALUE])", @@ -76,6 +81,7 @@ var nodepoolAddCommand = cli.Command{ virtualcluster.WithNodepoolCPUOpt(cliCtx.Int("cpu")), virtualcluster.WithNodepoolMemoryOpt(cliCtx.Int("memory")), virtualcluster.WithNodepoolCountOpt(cliCtx.Int("nodes")), + virtualcluster.WithNodepoolMaxPodsOpt(cliCtx.Int("max-pods")), virtualcluster.WithNodepoolNodeControllerAffinity(affinityLabels), ) }, diff --git a/manifests/virtualcluster/nodes/templates/nodes.tpl b/manifests/virtualcluster/nodes/templates/nodes.tpl index c8e290d..de7ada2 100644 --- a/manifests/virtualcluster/nodes/templates/nodes.tpl +++ b/manifests/virtualcluster/nodes/templates/nodes.tpl @@ -1,6 +1,7 @@ {{- $name := .Values.name }} {{- $cpu := .Values.cpu }} {{- $memory := .Values.memory }} +{{- $maxPods := .Values.maxPods }} {{- $labels := .Values.nodeLabels }} {{- range $index := (untilStep 0 (int .Values.replicas) 1) }} apiVersion: v1 @@ -35,11 +36,11 @@ status: allocatable: cpu: {{ $cpu }} memory: {{ $memory }}Gi - pods: 110 + pods: {{ $maxPods }} capacity: cpu: {{ $cpu }} memory: {{ $memory }}Gi - pods: 110 + pods: {{ $maxPods }} nodeInfo: architecture: amd64 containerRuntimeVersion: "kwok" diff --git a/manifests/virtualcluster/nodes/values.yaml b/manifests/virtualcluster/nodes/values.yaml index eeb7428..2f0999b 100644 --- a/manifests/virtualcluster/nodes/values.yaml +++ b/manifests/virtualcluster/nodes/values.yaml @@ -3,3 +3,4 @@ nodeLabels: {} replicas: 0 cpu: 0 memory: 0 +maxPods: 0 diff --git a/virtualcluster/nodes_common.go b/virtualcluster/nodes_common.go index 4a09052..f4adf4a 100644 --- a/virtualcluster/nodes_common.go +++ b/virtualcluster/nodes_common.go @@ -11,9 +11,10 @@ import ( var ( defaultNodepoolCfg = nodepoolConfig{ - count: 10, - cpu: 8, - memory: 16, // GiB + count: 10, + cpu: 8, + memory: 16, // GiB + maxPods: 110, } // virtualnodeReleaseLabels is used to mark that helm chart release @@ -53,6 +54,8 @@ type nodepoolConfig struct { // memory represents a logical memory resource provided by virtual node. // The unit is GiB. memory int + // maxPods represents maximum Pods per node. + maxPods int // labels is to be applied to each virtual node. labels []string // nodeSelectors forces virtual node's controller to nodes with that specific labels. @@ -65,6 +68,10 @@ func (cfg *nodepoolConfig) validate() error { cfg.count, cfg.cpu, cfg.memory) } + if cfg.maxPods <= 0 { + return fmt.Errorf("required max pods > 0, but got %d", cfg.maxPods) + } + if cfg.name == "" { return fmt.Errorf("required non-empty name") } @@ -107,6 +114,13 @@ func WithNodepoolMemoryOpt(memory int) NodepoolOpt { } } +// WithNodepoolMaxPodsOpt updates max pods. +func WithNodepoolMaxPodsOpt(maxPods int) NodepoolOpt { + return func(cfg *nodepoolConfig) { + cfg.maxPods = maxPods + } +} + // WithNodepoolLabelsOpt updates node's labels. func WithNodepoolLabelsOpt(labels []string) NodepoolOpt { return func(cfg *nodepoolConfig) { @@ -126,13 +140,13 @@ func WithNodepoolNodeControllerAffinity(nodeSelectors map[string][]string) Nodep // // NOTE: Please align with ../manifests/virtualcluster/nodes/values.yaml func (cfg *nodepoolConfig) toNodeHelmValuesAppliers() []helmcli.ValuesApplier { - res := make([]string, 0, 4) + res := make([]string, 0, 5) res = append(res, fmt.Sprintf("name=%s", cfg.name)) res = append(res, fmt.Sprintf("cpu=%d", cfg.cpu)) res = append(res, fmt.Sprintf("memory=%d", cfg.memory)) res = append(res, fmt.Sprintf("replicas=%d", cfg.count)) - + res = append(res, fmt.Sprintf("maxPods=%d", cfg.maxPods)) return []helmcli.ValuesApplier{helmcli.StringPathValuesApplier(res...)} }