Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add --max-pods to vc nodepool add command #65

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/kperf/commands/virtualcluster/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])",
Expand Down Expand Up @@ -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),
)
},
Expand Down
5 changes: 3 additions & 2 deletions manifests/virtualcluster/nodes/templates/nodes.tpl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions manifests/virtualcluster/nodes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ nodeLabels: {}
replicas: 0
cpu: 0
memory: 0
maxPods: 0
24 changes: 19 additions & 5 deletions virtualcluster/nodes_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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")
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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...)}
}

Expand Down
Loading