/
cpu_pressure.go
51 lines (42 loc) · 1.37 KB
/
cpu_pressure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024 Datadog, Inc.
package v1beta1
import (
"github.com/hashicorp/go-multierror"
"k8s.io/apimachinery/pkg/util/intstr"
)
// CPUPressureSpec represents a cpu pressure disruption
type CPUPressureSpec struct {
// Count represents the number of cores to target
// either an integer form or a percentage form appended with a %
// if empty, it will be considered to be 100%
Count *intstr.IntOrString `json:"count,omitempty"`
}
// Validate validates args for the given disruption
func (s *CPUPressureSpec) Validate() (retErr error) {
if s.Count == nil {
return nil
}
// Rule: count must be valid
if err := ValidateCount(s.Count); err != nil {
retErr = multierror.Append(retErr, err)
}
return retErr
}
// GenerateArgs generates injection or cleanup pod arguments for the given spec
func (s *CPUPressureSpec) GenerateArgs() []string {
args := []string{
"cpu-pressure",
}
if s.Count != nil {
args = append(args, "--count", s.Count.String())
} else {
// starting from here, we expect downstream consumer to benefit from a valid disruption
// mostly the injector
// hence we provide a non empty value
args = append(args, "--count", "100%")
}
return args
}