Skip to content

Commit 0f2892c

Browse files
authored
add cpuArchitecture filter to nodeResources collector (#930)
* filter on cpu architecture * filter by cpu architecture * fail if we dont have a label match too * add tests for cpu arch filter * update for make schemas
1 parent df43c9f commit 0f2892c

File tree

10 files changed

+119
-10
lines changed

10 files changed

+119
-10
lines changed

config/crds/troubleshoot.sh_analyzers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ spec:
839839
type: BoolString
840840
filters:
841841
properties:
842+
architecture:
843+
type: string
842844
cpuAllocatable:
843845
type: string
844846
cpuCapacity:

config/crds/troubleshoot.sh_preflights.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ spec:
839839
type: BoolString
840840
filters:
841841
properties:
842+
architecture:
843+
type: string
842844
cpuAllocatable:
843845
type: string
844846
cpuCapacity:

config/crds/troubleshoot.sh_supportbundles.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ spec:
870870
type: BoolString
871871
filters:
872872
properties:
873+
architecture:
874+
type: string
873875
cpuAllocatable:
874876
type: string
875877
cpuCapacity:

examples/preflight/node-resources.yaml

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,68 @@ spec:
1616
- pass:
1717
message: This cluster has enough nodes.
1818
- nodeResources:
19-
checkName: Must have 3 nodes with at least 6 cores
19+
checkName: Must have 3 nodes with at least 6 cores each
2020
filters:
2121
cpuCapacity: "6"
2222
outcomes:
2323
- fail:
24-
when: "< 3"
24+
when: "count() < 3"
2525
message: This application requires at least 3 nodes with 6 cores each
2626
- pass:
27-
message: This cluster has enough nodes with enough codes
27+
message: This cluster has enough nodes with enough cores
2828
- nodeResources:
29-
checkName: Must have 1 node with 16 GB (available) memory and 5 cores (on a single node)
29+
checkName: Must have 1 node with 16 GB (available) memory and 10 cores (on a single node)
3030
filters:
3131
allocatableMemory: 16Gi
32-
cpuCapacity: "5"
32+
cpuCapacity: "10"
3333
outcomes:
3434
- fail:
3535
when: "< 1"
3636
message: This application requires at least 1 node with 16GB available memory
3737
- pass:
3838
message: This cluster has a node with enough memory.
3939
- nodeResources:
40-
checkName: There must be at least 3 nodes in the cluster
40+
checkName: Must have 1 node with 16 GB (available) memory and 4 cores of amd64 arch (on a single node)
41+
filters:
42+
allocatableMemory: 16Gi
43+
cpuArchitecture: amd64
44+
cpuCapacity: "4"
4145
outcomes:
4246
- fail:
43-
when: "count() < 3"
44-
message: This application requires at least 3 nodes in the cluster
47+
when: "< 1"
48+
message: This application requires at least 1 node with amd64 arch and 16GB available memory
49+
- pass:
50+
message: This cluster has a node with the correct architecture and enough memory.
51+
- nodeResources:
52+
checkName: Must have 1 manager node with 16 GB (available) memory and 4 cores of amd64 arch
53+
filters:
54+
selector:
55+
matchLabel:
56+
node-role.kubernetes.io/master: ""
57+
allocatableMemory: 16Gi
58+
cpuArchitecture: amd64
59+
cpuCapacity: "6"
60+
outcomes:
61+
- fail:
62+
when: "< 1"
63+
message: This application requires at least 1 manager node with amd64 arch, 16GB available memory, and the label `node-role.kubernetes.io/master=""`
4564
- pass:
46-
message: This cluster haas sufficient nodes
65+
message: This cluster has a node with the correct architecture and enough memory.
4766
- nodeResources:
4867
checkName: There must be a total of at least 32Gi of memory on all nodes
4968
outcomes:
5069
- fail:
5170
when: "sum(memoryCapacity) < 32Gi"
5271
message: This application requires that 32Gi or more memory be available to the cluster
5372
- pass:
54-
message: This cluster haas sufficient memory
73+
message: This cluster has sufficient memory
74+
- nodeResources:
75+
checkName: There must be a total of at least 32Gi of memory on amd64 nodes
76+
filters:
77+
cpuArchitecture: amd64
78+
outcomes:
79+
- fail:
80+
when: "sum(memoryCapacity) < 32Gi"
81+
message: This application requires that 32Gi or more memory on amd64 nodes be available to the cluster
82+
- pass:
83+
message: This cluster has sufficient memory

pkg/analyze/node_resources.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ func nodeMatchesFilters(node corev1.Node, filters *troubleshootv1beta2.NodeResou
351351
}
352352
}
353353

354+
if filters.Architecture != "" {
355+
parsed := filters.Architecture
356+
357+
if !strings.EqualFold(node.Status.NodeInfo.Architecture, parsed) {
358+
return false, nil
359+
}
360+
}
361+
354362
if filters.CPUCapacity != "" {
355363
parsed, err := resource.ParseQuantity(filters.CPUCapacity)
356364
if err != nil {

pkg/analyze/node_resources_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ func Test_nodeMatchesFilters(t *testing.T) {
392392
},
393393
},
394394
Status: corev1.NodeStatus{
395+
NodeInfo: corev1.NodeSystemInfo{
396+
Architecture: "amd64",
397+
},
395398
Capacity: corev1.ResourceList{
396399
"attachable-volumes-aws-ebs": resource.MustParse("25"),
397400
"cpu": resource.MustParse("2"),
@@ -438,6 +441,22 @@ func Test_nodeMatchesFilters(t *testing.T) {
438441
},
439442
expectResult: false,
440443
},
444+
{
445+
name: "true when cpu arch is amd64",
446+
node: node,
447+
filters: &troubleshootv1beta2.NodeResourceFilters{
448+
Architecture: "amd64",
449+
},
450+
expectResult: true,
451+
},
452+
{
453+
name: "false when cpu arch is not amd64",
454+
node: node,
455+
filters: &troubleshootv1beta2.NodeResourceFilters{
456+
Architecture: "armhf",
457+
},
458+
expectResult: false,
459+
},
441460
{
442461
name: "true when allocatable memory is available",
443462
node: node,
@@ -709,6 +728,43 @@ func Test_analyzeNodeResources(t *testing.T) {
709728
IconURI: "https://troubleshoot.sh/images/analyzer-icons/node-resources.svg?w=16&h=18",
710729
},
711730
},
731+
{
732+
name: "at least 8 cores on amd64", // filter for a node with enough amd64 cores
733+
analyzer: &troubleshootv1beta2.NodeResources{
734+
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
735+
CheckName: "amd64-exists",
736+
},
737+
Outcomes: []*troubleshootv1beta2.Outcome{
738+
{
739+
Fail: &troubleshootv1beta2.SingleOutcome{
740+
When: "max(cpuCapacity) < 8",
741+
Message: "There isn't a node with 8 or more cores on amd64 arch",
742+
URI: "",
743+
},
744+
},
745+
{
746+
Pass: &troubleshootv1beta2.SingleOutcome{
747+
When: "max(cpuCapacity) >= 8",
748+
Message: "There is a node with at least 8 cores on amd64 arch",
749+
URI: "",
750+
},
751+
},
752+
},
753+
Filters: &troubleshootv1beta2.NodeResourceFilters{
754+
Architecture: "amd64",
755+
},
756+
},
757+
want: &AnalyzeResult{
758+
IsPass: true,
759+
IsFail: false,
760+
IsWarn: false,
761+
Title: "amd64-exists",
762+
Message: "There is a node with at least 8 cores on amd64 arch",
763+
URI: "",
764+
IconKey: "kubernetes_node_resources",
765+
IconURI: "https://troubleshoot.sh/images/analyzer-icons/node-resources.svg?w=16&h=18",
766+
},
767+
},
712768
{
713769
name: "unfiltered CPU totals",
714770
analyzer: &troubleshootv1beta2.NodeResources{

pkg/apis/troubleshoot/v1beta2/analyzer_shared.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type NodeResources struct {
118118
}
119119

120120
type NodeResourceFilters struct {
121+
Architecture string `json:"architecture,omitempty" yaml:"cpuArchitecture,omitempty"`
121122
CPUCapacity string `json:"cpuCapacity,omitempty" yaml:"cpuCapacity,omitempty"`
122123
CPUAllocatable string `json:"cpuAllocatable,omitempty" yaml:"cpuAllocatable,omitempty"`
123124
MemoryCapacity string `json:"memoryCapacity,omitempty" yaml:"memoryCapacity,omitempty"`

schemas/analyzer-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@
12551255
"filters": {
12561256
"type": "object",
12571257
"properties": {
1258+
"architecture": {
1259+
"type": "string"
1260+
},
12581261
"cpuAllocatable": {
12591262
"type": "string"
12601263
},

schemas/preflight-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@
12551255
"filters": {
12561256
"type": "object",
12571257
"properties": {
1258+
"architecture": {
1259+
"type": "string"
1260+
},
12581261
"cpuAllocatable": {
12591262
"type": "string"
12601263
},

schemas/supportbundle-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,9 @@
13011301
"filters": {
13021302
"type": "object",
13031303
"properties": {
1304+
"architecture": {
1305+
"type": "string"
1306+
},
13041307
"cpuAllocatable": {
13051308
"type": "string"
13061309
},

0 commit comments

Comments
 (0)