Skip to content

Commit

Permalink
operator: Add no hugepages test (#2505)
Browse files Browse the repository at this point in the history
* operator: Add no hugepages test

* Add new skipFn for missing pods
  • Loading branch information
sebrandon1 authored Oct 16, 2024
1 parent 1f6df2b commit 8b7da6e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
24 changes: 20 additions & 4 deletions CATALOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Depending on the workload type, not all tests are required to pass to satisfy be

## Test cases summary

### Total test cases: 112
### Total test cases: 113

### Total suites: 10

Expand All @@ -19,7 +19,7 @@ Depending on the workload type, not all tests are required to pass to satisfy be
|manageability|2|
|networking|11|
|observability|5|
|operator|7|
|operator|8|
|performance|6|
|platform-alteration|13|
|preflight|17|
Expand All @@ -36,11 +36,11 @@ Depending on the workload type, not all tests are required to pass to satisfy be
|---|---|
|7|1|

### Non-Telco specific tests only: 65
### Non-Telco specific tests only: 66

|Mandatory|Optional|
|---|---|
|42|23|
|42|24|

### Telco specific tests only: 27

Expand Down Expand Up @@ -1250,6 +1250,22 @@ Tags|common,operator
|Non-Telco|Mandatory|
|Telco|Mandatory|

#### operator-pods-no-hugepages

Property|Description
---|---
Unique ID|operator-pods-no-hugepages
Description|Tests that the pods do not have hugepages enabled.
Suggested Remediation|Ensure that the pods are not using hugepages
Best Practice Reference|https://redhat-best-practices-for-k8s.github.io/guide/#redhat-best-practices-for-k8s-cnf-operator-requirements
Exception Process|No exceptions
Tags|common,operator
|**Scenario**|**Optional/Mandatory**|
|Extended|Optional|
|Far-Edge|Optional|
|Non-Telco|Optional|
|Telco|Optional|

#### operator-semantic-versioning

Property|Description
Expand Down
1 change: 1 addition & 0 deletions expected_results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ testCases:
- operator-install-status-succeeded
- operator-semantic-versioning
- operator-single-crd-owner
- operator-pods-no-hugepages
- performance-exclusive-cpu-pool
- performance-max-resources-exec-probes
- performance-shared-cpu-pool-non-rt-scheduling-policy # hazelcast pod meets requirements
Expand Down
10 changes: 10 additions & 0 deletions pkg/testhelper/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@ func GetNoOperatorsSkipFn(env *provider.TestEnvironment) func() (bool, string) {
}
}

func GetNoOperatorPodsSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
if len(env.CSVToPodListMap) == 0 {
return true, "no operator pods found"
}

return false, ""
}
}

func GetNoOperatorCrdsSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
if len(env.Crds) == 0 {
Expand Down
1 change: 1 addition & 0 deletions tests/identifiers/doclinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
TestOperatorRunAsNonRootDocLink = DocOperatorRequirement
TestOperatorAutomountTokensDocLink = DocOperatorRequirement
TestOperatorReadOnlyFilesystemDocLink = DocOperatorRequirement
TestOperatorPodsNoHugepagesDocLink = DocOperatorRequirement

// Observability Test Suite
TestLoggingIdentifierDocLink = "https://redhat-best-practices-for-k8s.github.io/guide/#redhat-best-practices-for-k8s-logging"
Expand Down
17 changes: 17 additions & 0 deletions tests/identifiers/identifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ var (
TestOperatorCrdVersioningIdentifier claim.Identifier
TestOperatorCrdSchemaIdentifier claim.Identifier
TestOperatorSingleCrdOwnerIdentifier claim.Identifier
TestOperatorPodsNoHugepages claim.Identifier
TestPodNodeSelectorAndAffinityBestPractices claim.Identifier
TestPodHighAvailabilityBestPractices claim.Identifier
TestPodClusterRoleBindingsBestPracticesIdentifier claim.Identifier
Expand Down Expand Up @@ -1016,6 +1017,22 @@ that Node's kernel may not have the same hacks.'`,
},
TagCommon)

TestOperatorPodsNoHugepages = AddCatalogEntry(
"pods-no-hugepages",
common.OperatorTestKey,
`Tests that the pods do not have hugepages enabled.`,
OperatorPodsNoHugepagesRemediation,
NoExceptions,
TestOperatorPodsNoHugepagesDocLink,
false,
map[string]string{
FarEdge: Optional,
Telco: Optional,
NonTelco: Optional,
Extended: Optional,
},
TagCommon)

TestPodNodeSelectorAndAffinityBestPractices = AddCatalogEntry(
"pod-scheduling",
common.LifecycleTestKey,
Expand Down
2 changes: 2 additions & 0 deletions tests/identifiers/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const (

OperatorSingleCrdOwnerRemediation = `Ensure that a CRD is owned by only one Operator`

OperatorPodsNoHugepagesRemediation = `Ensure that the pods are not using hugepages`

PodNodeSelectorAndAffinityBestPracticesRemediation = `In most cases, Pod's should not specify their host Nodes through nodeSelector or nodeAffinity. However, there are cases in which workloads require specialized hardware specific to a particular class of Node.`

PodHighAvailabilityBestPracticesRemediation = `In high availability cases, Pod podAntiAffinity rule should be specified for pod scheduling and pod replica value is set to more than 1 .`
Expand Down
28 changes: 28 additions & 0 deletions tests/operator/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func LoadChecks() {
testOperatorSingleCrdOwner(c, &env)
return nil
}))

checksGroup.Add(checksdb.NewCheck(identifiers.GetTestIDAndLabels(identifiers.TestOperatorPodsNoHugepages)).
WithSkipCheckFn(testhelper.GetNoOperatorsSkipFn(&env), testhelper.GetNoOperatorPodsSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testOperatorPodsNoHugepages(c, &env)
return nil
}))
}

// This function check if the Operator CRD version follows K8s versioning
Expand Down Expand Up @@ -317,3 +324,24 @@ func testOperatorSingleCrdOwner(check *checksdb.Check, env *provider.TestEnviron

check.SetResult(compliantObjects, nonCompliantObjects)
}

func testOperatorPodsNoHugepages(check *checksdb.Check, env *provider.TestEnvironment) {
var compliantObjects []*testhelper.ReportObject
var nonCompliantObjects []*testhelper.ReportObject

for csv, pods := range env.CSVToPodListMap {
CsvResult := SplitCsv(csv)
check.LogInfo("Name of csv: %q in namespaces: %q", CsvResult.NameCsv, CsvResult.Namespace)
for _, pod := range pods {
check.LogInfo("Testing Pod %q in namespace %q", pod.Name, pod.Namespace)
if pod.HasHugepages() {
check.LogError("Pod %q in namespace %q has hugepages", pod.Name, pod.Namespace)
nonCompliantObjects = append(nonCompliantObjects, testhelper.NewPodReportObject(pod.Namespace, pod.Name, "Pod has hugepages", false))
} else {
check.LogInfo("Pod %q in namespace %q has no hugepages", pod.Name, pod.Namespace)
compliantObjects = append(compliantObjects, testhelper.NewPodReportObject(pod.Namespace, pod.Name, "Pod has no hugepages", true))
}
}
check.SetResult(compliantObjects, nonCompliantObjects)
}
}

0 comments on commit 8b7da6e

Please sign in to comment.