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

NO-JIRA: e2e: set performance profile cpus using env vars #909

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 39 additions & 8 deletions test/e2e/performanceprofile/functests/0_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/cpuset"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -65,11 +66,11 @@ var _ = Describe("[performance][config] Performance configuration", Ordered, fun

It("Should successfully deploy the performance profile", func() {

performanceProfile := testProfile()
performanceProfile, err := testProfile()
Expect(err).ToNot(HaveOccurred(), "failed to build performance profile: %v", err)
profileAlreadyExists := false

performanceManifest, foundOverride := os.LookupEnv("PERFORMANCE_PROFILE_MANIFEST_OVERRIDE")
var err error
if foundOverride {
performanceProfile, err = externalPerformanceProfile(performanceManifest)
Expect(err).ToNot(HaveOccurred(), "Failed overriding performance profile", performanceManifest)
Expand Down Expand Up @@ -158,9 +159,42 @@ func externalPerformanceProfile(performanceManifest string) (*performancev2.Perf
return profile, nil
}

func testProfile() *performancev2.PerformanceProfile {
func testProfile() (*performancev2.PerformanceProfile, error) {
reserved := performancev2.CPUSet("0")
isolated := performancev2.CPUSet("1-3")
profileCpus := &performancev2.CPU{
Reserved: &reserved,
Isolated: &isolated,
}

customReserved, foundReserved := os.LookupEnv("RESERVED_CPU_SET")
customIsolated, foundIsolated := os.LookupEnv("ISOLATED_CPU_SET")
if foundReserved != foundIsolated {
return nil, fmt.Errorf("overriding default profile CPU setting requires both environment variables RESERVED_CPU_SET and ISOLATED_CPU_SET to be set")
}

if foundReserved {
shajmakh marked this conversation as resolved.
Show resolved Hide resolved
if _, err := cpuset.Parse(customReserved); err != nil {
return nil, fmt.Errorf("failed to parse the provided reserved cpu set %s: %v. Using default values", customReserved, err)
}
reserved = performancev2.CPUSet(customReserved)
}

if foundIsolated {
if _, err := cpuset.Parse(customIsolated); err != nil {
return nil, fmt.Errorf("failed to parse the provided isolated cpu set %s: %v. Using default values", customIsolated, err)
}
isolated = performancev2.CPUSet(customIsolated)
}
customOfflined, foundOfflined := os.LookupEnv("OFFLINED_CPU_SET")
if foundOfflined {
if _, err := cpuset.Parse(customOfflined); err != nil {
return nil, fmt.Errorf("failed to parse the provided offlined cpu set %s: %v. Using default values", customOfflined, err)
}
offlined := performancev2.CPUSet(customOfflined)
profileCpus.Offlined = &offlined
}

hugePagesSize := performancev2.HugePageSize("1G")

profile := &performancev2.PerformanceProfile{
Expand All @@ -172,10 +206,7 @@ func testProfile() *performancev2.PerformanceProfile {
Name: utils.PerformanceProfileName,
},
Spec: performancev2.PerformanceProfileSpec{
CPU: &performancev2.CPU{
Reserved: &reserved,
Isolated: &isolated,
},
CPU: profileCpus,
HugePages: &performancev2.HugePages{
DefaultHugePagesSize: &hugePagesSize,
Pages: []performancev2.HugePage{
Expand Down Expand Up @@ -215,5 +246,5 @@ func testProfile() *performancev2.PerformanceProfile {
"pools.operator.machineconfiguration.openshift.io/master": "",
}
}
return profile
return profile, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ func verifyV2Conversion(v2Profile *performancev2.PerformanceProfile, v1Profile *
}

if (specCPU.Offlined == nil) != (v1Profile.Spec.CPU.Offlined == nil) {
return fmt.Errorf("spec CPUs Isolated field is different")
return fmt.Errorf("spec CPUs Offlined field is different")
}
if specCPU.Offlined != nil {
if string(*specCPU.Offlined) != string(*v1Profile.Spec.CPU.Offlined) {
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/performanceprofile/functests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This deployment takes some time and requires reboot
Tests are executed in order of file-names
So be careful with renaming existing or adding new suites

DISCOVERY_MODE env variable to get an already deployed performanceProfile
Environment variables:
DISCOVERY_MODE: to get an already deployed performanceProfile.
If DISCOVERY_MODE set to true the suites will search for a PerformanceProfile on the cluster and use it.
If no PerformanceProfile is found, that suites will be skipped
If no PerformanceProfile is found, that suites will be skipped.

RESERVED_CPU_SET, ISOLATED_CPU_SET, OFFLINED_CPU_SET: strings that present the CPU sets distributed between reserved, isolated, and offlined CPU profile specifications. The runner is responsible for validating that these values are compatible with the testing environment.