Skip to content

Commit f4581bb

Browse files
author
Henrik Johansson
authored
Merge pull request #143 from scylladb/cpuset_incorrectly_set
QoS enforced on deploy of a cluster.
2 parents 8dd89e9 + 70fa793 commit f4581bb

File tree

8 files changed

+379
-7
lines changed

8 files changed

+379
-7
lines changed

Gopkg.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/gke/cluster.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ spec:
100100
limits:
101101
cpu: 30
102102
memory: 115G
103+
requests:
104+
cpu: 30
105+
memory: 115G
103106
placement:
104107
nodeAffinity:
105108
requiredDuringSchedulingIgnoredDuringExecution:

pkg/controller/cluster/resource/resource.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ func StatefulSetForRack(r scyllav1alpha1.RackSpec, c *scyllav1alpha1.Cluster, si
191191
"-c",
192192
fmt.Sprintf("cp -a /sidecar/* %s", naming.SharedDirName),
193193
},
194+
Resources: corev1.ResourceRequirements{
195+
Requests: corev1.ResourceList{
196+
corev1.ResourceCPU: resource.MustParse("1"),
197+
corev1.ResourceMemory: resource.MustParse("200M"),
198+
},
199+
Limits: corev1.ResourceList{
200+
corev1.ResourceCPU: resource.MustParse("1"),
201+
corev1.ResourceMemory: resource.MustParse("200M"),
202+
},
203+
},
194204
VolumeMounts: []corev1.VolumeMount{
195205
{
196206
Name: "shared",
@@ -396,6 +406,16 @@ func sysctlInitContainer(sysctls []string) *corev1.Container {
396406
SecurityContext: &corev1.SecurityContext{
397407
Privileged: &opt,
398408
},
409+
Resources: corev1.ResourceRequirements{
410+
Requests: corev1.ResourceList{
411+
corev1.ResourceCPU: resource.MustParse("1"),
412+
corev1.ResourceMemory: resource.MustParse("200M"),
413+
},
414+
Limits: corev1.ResourceList{
415+
corev1.ResourceCPU: resource.MustParse("1"),
416+
corev1.ResourceMemory: resource.MustParse("200M"),
417+
},
418+
},
399419
Command: []string{
400420
"/bin/sh",
401421
"-c",
@@ -432,6 +452,16 @@ func agentContainer(c *scyllav1alpha1.Cluster) *corev1.Container {
432452
ReadOnly: true,
433453
},
434454
},
455+
Resources: corev1.ResourceRequirements{
456+
Requests: corev1.ResourceList{
457+
corev1.ResourceCPU: resource.MustParse("1"),
458+
corev1.ResourceMemory: resource.MustParse("200M"),
459+
},
460+
Limits: corev1.ResourceList{
461+
corev1.ResourceCPU: resource.MustParse("1"),
462+
corev1.ResourceMemory: resource.MustParse("200M"),
463+
},
464+
},
435465
}
436466
}
437467

pkg/sidecar/config/config.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"os/exec"
9+
"strconv"
910
"strings"
1011

1112
"github.com/ghodss/yaml"
@@ -17,6 +18,7 @@ import (
1718
"github.com/scylladb/scylla-operator/pkg/naming"
1819
"github.com/scylladb/scylla-operator/pkg/sidecar/identity"
1920
"k8s.io/client-go/kubernetes"
21+
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
2022
"sigs.k8s.io/controller-runtime/pkg/client"
2123
)
2224

@@ -173,13 +175,18 @@ func (s *ScyllaConfig) setupEntrypoint(ctx context.Context) (*exec.Cmd, error) {
173175
devMode = "1"
174176
}
175177

178+
shards, err := strconv.Atoi(options.GetSidecarOptions().CPU)
179+
if err != nil {
180+
return nil, errors.WithStack(err)
181+
}
176182
args := []string{
177183
fmt.Sprintf("--listen-address=%s", m.IP),
178184
fmt.Sprintf("--broadcast-address=%s", m.StaticIP),
179185
fmt.Sprintf("--broadcast-rpc-address=%s", m.StaticIP),
180186
fmt.Sprintf("--seeds=%s", strings.Join(seeds, ",")),
181187
fmt.Sprintf("--developer-mode=%s", devMode),
182-
fmt.Sprintf("--smp=%s", options.GetSidecarOptions().CPU),
188+
fmt.Sprintf("--overprovisioned=%d", 0),
189+
fmt.Sprintf("--smp=%d", shards),
183190
}
184191
if cluster.Spec.Alternator.Enabled() {
185192
args = append(args, fmt.Sprintf("--alternator-port=%d", cluster.Spec.Alternator.Port))
@@ -194,7 +201,9 @@ func (s *ScyllaConfig) setupEntrypoint(ctx context.Context) (*exec.Cmd, error) {
194201
if err != nil {
195202
return nil, errors.WithStack(err)
196203
}
197-
204+
if err := s.validateCpuSet(ctx, cpusAllowed, shards); err != nil {
205+
return nil, errors.WithStack(err)
206+
}
198207
args = append(args, fmt.Sprintf("--cpuset=%s", cpusAllowed))
199208
}
200209

@@ -206,6 +215,18 @@ func (s *ScyllaConfig) setupEntrypoint(ctx context.Context) (*exec.Cmd, error) {
206215
return scyllaCmd, nil
207216
}
208217

218+
func (s *ScyllaConfig) validateCpuSet(ctx context.Context, cpusAllowed string, shards int) error {
219+
cpuSet, err := cpuset.Parse(cpusAllowed)
220+
if err != nil {
221+
return err
222+
}
223+
if cpuSet.Size() != shards {
224+
s.logger.Info(ctx, "suboptimal shard and cpuset config, shard count (config: 'CPU') and cpuset size should match for optimal performance",
225+
"shards", shards, "cpuset", cpuSet.String())
226+
}
227+
return nil
228+
}
229+
209230
// mergeYAMLs merges two arbitrary YAML structures at the top level.
210231
func mergeYAMLs(initialYAML, overrideYAML []byte) ([]byte, error) {
211232

pkg/webhook/default_server/cluster/validating/cluster_validation.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ func checkValues(c *scyllav1alpha1.Cluster) (allowed bool, msg string) {
3333
return false, fmt.Sprintf("when using cpuset, you must use whole cpu cores, but rack %s has %dm", rack.Name, cores)
3434
}
3535

36-
// Requests == Limits or only Limits must be set for QOS class guaranteed
36+
// Requests == Limits and Requests must be set and equal for QOS class guaranteed
3737
requests := rack.Resources.Requests
3838
if requests != nil {
39-
if requests.Cpu().MilliValue() == 0 {
39+
if requests.Cpu().MilliValue() != limits.Cpu().MilliValue() {
4040
return false, fmt.Sprintf("when using cpuset, cpu requests must be the same as cpu limits in rack %s", rack.Name)
4141
}
42-
if requests.Memory().MilliValue() == 0 {
42+
if requests.Memory().MilliValue() != limits.Memory().MilliValue() {
4343
return false, fmt.Sprintf("when using cpuset, memory requests must be the same as memory limits in rack %s", rack.Name)
4444
}
45-
return false, fmt.Sprintf("when using cpuset, requests must be the same as limits in rack %s", rack.Name)
45+
} else {
46+
// Copy the limits
47+
rack.Resources.Requests = limits.DeepCopy()
4648
}
4749
}
4850
}

vendor/k8s.io/kubernetes/pkg/kubelet/cm/cpuset/BUILD

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/k8s.io/kubernetes/pkg/kubelet/cm/cpuset/OWNERS

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)