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 cpuArchitecture filter to nodeResources collector #930

Merged
merged 8 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
49 changes: 39 additions & 10 deletions examples/preflight/node-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,68 @@ spec:
- pass:
message: This cluster has enough nodes.
- nodeResources:
checkName: Must have 3 nodes with at least 6 cores
checkName: Must have 3 nodes with at least 6 cores each
filters:
cpuCapacity: "6"
outcomes:
- fail:
when: "< 3"
when: "count() < 3"
message: This application requires at least 3 nodes with 6 cores each
- pass:
message: This cluster has enough nodes with enough codes
message: This cluster has enough nodes with enough cores
- nodeResources:
checkName: Must have 1 node with 16 GB (available) memory and 5 cores (on a single node)
checkName: Must have 1 node with 16 GB (available) memory and 10 cores (on a single node)
filters:
allocatableMemory: 16Gi
cpuCapacity: "5"
cpuCapacity: "10"
outcomes:
- fail:
when: "< 1"
message: This application requires at least 1 node with 16GB available memory
- pass:
message: This cluster has a node with enough memory.
- nodeResources:
checkName: There must be at least 3 nodes in the cluster
checkName: Must have 1 node with 16 GB (available) memory and 4 cores of amd64 arch (on a single node)
filters:
allocatableMemory: 16Gi
cpuArchitecture: amd64
cpuCapacity: "4"
outcomes:
- fail:
when: "count() < 3"
message: This application requires at least 3 nodes in the cluster
when: "< 1"
message: This application requires at least 1 node with amd64 arch and 16GB available memory
- pass:
message: This cluster has a node with the correct architecture and enough memory.
- nodeResources:
checkName: Must have 1 manager node with 16 GB (available) memory and 4 cores of amd64 arch
filters:
selector:
matchLabel:
node-role.kubernetes.io/master: ""
allocatableMemory: 16Gi
cpuArchitecture: amd64
cpuCapacity: "6"
outcomes:
- fail:
when: "< 1"
message: This application requires at least 1 manager node with amd64 arch, 16GB available memory, and the label `node-role.kubernetes.io/master=""`
- pass:
message: This cluster haas sufficient nodes
message: This cluster has a node with the correct architecture and enough memory.
- nodeResources:
checkName: There must be a total of at least 32Gi of memory on all nodes
outcomes:
- fail:
when: "sum(memoryCapacity) < 32Gi"
message: This application requires that 32Gi or more memory be available to the cluster
- pass:
message: This cluster haas sufficient memory
message: This cluster has sufficient memory
- nodeResources:
checkName: There must be a total of at least 32Gi of memory on amd64 nodes
filters:
cpuArchitecture: amd64
outcomes:
- fail:
when: "sum(memoryCapacity) < 32Gi"
message: This application requires that 32Gi or more memory on amd64 nodes be available to the cluster
- pass:
message: This cluster has sufficient memory
8 changes: 8 additions & 0 deletions pkg/analyze/node_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ func nodeMatchesFilters(node corev1.Node, filters *troubleshootv1beta2.NodeResou
}
}

if filters.Architecture != "" {
parsed := filters.Architecture

if !strings.EqualFold(node.Status.NodeInfo.Architecture, parsed) {
return false, nil
}
}

if filters.CPUCapacity != "" {
parsed, err := resource.ParseQuantity(filters.CPUCapacity)
if err != nil {
Expand Down
56 changes: 56 additions & 0 deletions pkg/analyze/node_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ func Test_nodeMatchesFilters(t *testing.T) {
},
},
Status: corev1.NodeStatus{
NodeInfo: corev1.NodeSystemInfo{
Architecture: "amd64",
},
Capacity: corev1.ResourceList{
"attachable-volumes-aws-ebs": resource.MustParse("25"),
"cpu": resource.MustParse("2"),
Expand Down Expand Up @@ -438,6 +441,22 @@ func Test_nodeMatchesFilters(t *testing.T) {
},
expectResult: false,
},
{
name: "true when cpu arch is amd64",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
Architecture: "amd64",
},
expectResult: true,
},
{
name: "false when cpu arch is not amd64",
node: node,
filters: &troubleshootv1beta2.NodeResourceFilters{
Architecture: "armhf",
},
expectResult: false,
},
{
name: "true when allocatable memory is available",
node: node,
Expand Down Expand Up @@ -709,6 +728,43 @@ func Test_analyzeNodeResources(t *testing.T) {
IconURI: "https://troubleshoot.sh/images/analyzer-icons/node-resources.svg?w=16&h=18",
},
},
{
name: "at least 8 cores on amd64", // filter for a node with enough amd64 cores
analyzer: &troubleshootv1beta2.NodeResources{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
CheckName: "amd64-exists",
},
Outcomes: []*troubleshootv1beta2.Outcome{
{
Fail: &troubleshootv1beta2.SingleOutcome{
When: "max(cpuCapacity) < 8",
Message: "There isn't a node with 8 or more cores on amd64 arch",
URI: "",
},
},
{
Pass: &troubleshootv1beta2.SingleOutcome{
When: "max(cpuCapacity) >= 8",
Message: "There is a node with at least 8 cores on amd64 arch",
URI: "",
},
},
},
Filters: &troubleshootv1beta2.NodeResourceFilters{
Architecture: "amd64",
},
},
want: &AnalyzeResult{
IsPass: true,
IsFail: false,
IsWarn: false,
Title: "amd64-exists",
Message: "There is a node with at least 8 cores on amd64 arch",
URI: "",
IconKey: "kubernetes_node_resources",
IconURI: "https://troubleshoot.sh/images/analyzer-icons/node-resources.svg?w=16&h=18",
},
},
{
name: "unfiltered CPU totals",
analyzer: &troubleshootv1beta2.NodeResources{
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/troubleshoot/v1beta2/analyzer_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type NodeResources struct {
}

type NodeResourceFilters struct {
Architecture string `json:"architecture,omitempty" yaml:"cpuArchitecture,omitempty"`
CPUCapacity string `json:"cpuCapacity,omitempty" yaml:"cpuCapacity,omitempty"`
CPUAllocatable string `json:"cpuAllocatable,omitempty" yaml:"cpuAllocatable,omitempty"`
MemoryCapacity string `json:"memoryCapacity,omitempty" yaml:"memoryCapacity,omitempty"`
Expand Down