Skip to content

Commit

Permalink
Add function to fetch mcp or nodepool name based on cluster type
Browse files Browse the repository at this point in the history
Add utils functions GetPoolName which will fetch
mcp name based on the performance profile when using
standard cluster and return node pool name when using
hypershift

Signed-off-by: Niranjan M.R <[email protected]>
  • Loading branch information
Niranjan M.R committed Oct 8, 2024
1 parent a605be8 commit d9db25c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ import (
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/cgroup"
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/discovery"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/hypershift"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/images"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/label"
testlog "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/log"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/mcps"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodepools"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/pods"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profiles"
Expand Down Expand Up @@ -76,15 +73,8 @@ var _ = Describe("[performance] Cgroups and affinity", Ordered, Label(string(lab
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())

if !hypershift.IsHypershiftCluster() {
poolName, err = mcps.GetByProfile(profile)
Expect(err).ToNot(HaveOccurred())
} else {
hostedClusterName, err := hypershift.GetHostedClusterName()
np, err := nodepools.GetByClusterName(ctx, testclient.ControlPlaneClient, hostedClusterName)
Expect(err).ToNot(HaveOccurred())
poolName = client.ObjectKeyFromObject(np).String()
}
poolName, err = nodes.GetPoolName(ctx, profile)
Expect(err).ToNot(HaveOccurred())

isCgroupV2, err = cgroup.IsVersion2(ctx, testclient.DataPlaneClient)
Expect(err).ToNot(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import (
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/hypershift"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/label"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/mcps"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodepools"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profiles"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profilesupdate"
Expand All @@ -52,6 +49,9 @@ var _ = Describe("[ref_id: 45487][performance]additional kubelet arguments", Ord
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())

poolName, err = nodes.GetPoolName(ctx, profile)
Expect(err).ToNot(HaveOccurred())

if !hypershift.IsHypershiftCluster() {
poolName, err = mcps.GetByProfile(profile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -72,9 +72,6 @@ var _ = Describe("[ref_id: 45487][performance]additional kubelet arguments", Ord
It("[test_id:45488]Test performance profile annotation for changing multiple kubelet settings", func() {
sysctls := "{\"allowedUnsafeSysctls\":[\"net.core.somaxconn\",\"kernel.msg*\"],\"systemReserved\":{\"memory\":\"300Mi\"},\"kubeReserved\":{\"memory\":\"768Mi\"},\"imageMinimumGCAge\":\"3m\"}"
profile.Annotations = updateKubeletConfigOverrideAnnotations(profile.Annotations, sysctls)
//annotations, err := json.Marshal(profile.Annotations)
//Expect(err).ToNot(HaveOccurred())

By("updating Performance profile")
profiles.UpdateWithRetry(profile)

Expand Down
28 changes: 28 additions & 0 deletions test/e2e/performanceprofile/functests/utils/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"

performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/cluster"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/hypershift"
testlog "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/log"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/mcps"
nodeInspector "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/node_inspector"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodepools"
)

const (
Expand Down Expand Up @@ -543,3 +547,27 @@ func CpuManagerCpuSet(ctx context.Context, node *corev1.Node) (cpuset.CPUSet, er
fmt.Println("cpuset = ", nodeCpuSet.String())
return nodeCpuSet, err
}

// GetPoolName returns mcp associated with performance profile or hypershift node pool name
// in the case of hypershift cluster
func GetPoolName(ctx context.Context, profile *performancev2.PerformanceProfile) (string, error) {
var poolName string
var err error
if hypershift.IsHypershiftCluster() {
poolName, err = mcps.GetByProfile(profile)
if err != nil {
return "", fmt.Errorf("Unable to fetch performance profile %v", profile)
}
} else {
hostedClusterName, err := hypershift.GetHostedClusterName()
if err != nil {
return "", fmt.Errorf("unable to fetch hosted cluster name: %v", err)
}
np, err := nodepools.GetByClusterName(ctx, testclient.ControlPlaneClient, hostedClusterName)
if err != nil {
return "", fmt.Errorf("unable to find nodepools %v", err)
}
poolName = client.ObjectKeyFromObject(np).String()
}
return poolName, err
}

0 comments on commit d9db25c

Please sign in to comment.