diff --git a/config/crds/troubleshoot.sh_analyzers.yaml b/config/crds/troubleshoot.sh_analyzers.yaml index 54617c82e..430671c44 100644 --- a/config/crds/troubleshoot.sh_analyzers.yaml +++ b/config/crds/troubleshoot.sh_analyzers.yaml @@ -839,6 +839,8 @@ spec: type: BoolString filters: properties: + architecture: + type: string cpuAllocatable: type: string cpuCapacity: diff --git a/config/crds/troubleshoot.sh_preflights.yaml b/config/crds/troubleshoot.sh_preflights.yaml index c5549c6be..7cfa5c19d 100644 --- a/config/crds/troubleshoot.sh_preflights.yaml +++ b/config/crds/troubleshoot.sh_preflights.yaml @@ -839,6 +839,8 @@ spec: type: BoolString filters: properties: + architecture: + type: string cpuAllocatable: type: string cpuCapacity: diff --git a/config/crds/troubleshoot.sh_supportbundles.yaml b/config/crds/troubleshoot.sh_supportbundles.yaml index c04621ae9..db8628056 100644 --- a/config/crds/troubleshoot.sh_supportbundles.yaml +++ b/config/crds/troubleshoot.sh_supportbundles.yaml @@ -870,6 +870,8 @@ spec: type: BoolString filters: properties: + architecture: + type: string cpuAllocatable: type: string cpuCapacity: diff --git a/examples/preflight/node-resources.yaml b/examples/preflight/node-resources.yaml index 9d9214be5..65af8d8ce 100644 --- a/examples/preflight/node-resources.yaml +++ b/examples/preflight/node-resources.yaml @@ -16,20 +16,20 @@ 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" @@ -37,13 +37,32 @@ spec: - 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: @@ -51,4 +70,14 @@ spec: 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 diff --git a/pkg/analyze/node_resources.go b/pkg/analyze/node_resources.go index 1860b6cfb..a37815d90 100644 --- a/pkg/analyze/node_resources.go +++ b/pkg/analyze/node_resources.go @@ -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 { diff --git a/pkg/analyze/node_resources_test.go b/pkg/analyze/node_resources_test.go index 70ff17619..0aeacc9cf 100644 --- a/pkg/analyze/node_resources_test.go +++ b/pkg/analyze/node_resources_test.go @@ -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"), @@ -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, @@ -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{ diff --git a/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go b/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go index c9e7883d3..c14e6f087 100644 --- a/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go @@ -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"` diff --git a/schemas/analyzer-troubleshoot-v1beta2.json b/schemas/analyzer-troubleshoot-v1beta2.json index 30391f55a..26c2fab32 100644 --- a/schemas/analyzer-troubleshoot-v1beta2.json +++ b/schemas/analyzer-troubleshoot-v1beta2.json @@ -1255,6 +1255,9 @@ "filters": { "type": "object", "properties": { + "architecture": { + "type": "string" + }, "cpuAllocatable": { "type": "string" }, diff --git a/schemas/preflight-troubleshoot-v1beta2.json b/schemas/preflight-troubleshoot-v1beta2.json index 37e4e867d..b0637f2cf 100644 --- a/schemas/preflight-troubleshoot-v1beta2.json +++ b/schemas/preflight-troubleshoot-v1beta2.json @@ -1255,6 +1255,9 @@ "filters": { "type": "object", "properties": { + "architecture": { + "type": "string" + }, "cpuAllocatable": { "type": "string" }, diff --git a/schemas/supportbundle-troubleshoot-v1beta2.json b/schemas/supportbundle-troubleshoot-v1beta2.json index b30b8a1c3..c8718dc84 100644 --- a/schemas/supportbundle-troubleshoot-v1beta2.json +++ b/schemas/supportbundle-troubleshoot-v1beta2.json @@ -1301,6 +1301,9 @@ "filters": { "type": "object", "properties": { + "architecture": { + "type": "string" + }, "cpuAllocatable": { "type": "string" },