Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pao-functests-updating-profile: cluster-label-worker-cnf pao-functests-update-on
pao-functests-update-only: $(BINDATA)
@echo "Cluster Version"
hack/show-cluster-version.sh
hack/run-test.sh -t "test/e2e/performanceprofile/functests/0_config test/e2e/performanceprofile/functests/2_performance_update test/e2e/performanceprofile/functests/3_performance_status test/e2e/performanceprofile/functests/7_performance_kubelet_node test/e2e/performanceprofile/functests/9_reboot test/e2e/performanceprofile/functests/13_llc" -p "-v -r --fail-fast --flake-attempts=2 --timeout=5h --junit-report=report.xml" -m "Running Functional Tests"
hack/run-test.sh -t "test/e2e/performanceprofile/functests/0_config test/e2e/performanceprofile/functests/2_performance_update test/e2e/performanceprofile/functests/3_performance_status test/e2e/performanceprofile/functests/7_performance_kubelet_node test/e2e/performanceprofile/functests/9_reboot test/e2e/performanceprofile/functests/13_llc" -p "-v -r --label-filter=!(hypershift) --fail-fast --flake-attempts=2 --timeout=5h --junit-report=report.xml" -m "Running Functional Tests"

.PHONY: pao-functests-update-only-hypershift
pao-functests-update-only-hypershift: $(BINDATA)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/performanceprofile/functests/0_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func printEnvs() {
name, _ := os.LookupEnv(hypershift.HostedClusterNameEnv)
testlog.Infof("%s=%s", hypershift.HostedClusterNameEnv, name)

v, _ := hypershift.GetManagementClusterNamespace()
v, _ := hypershift.GetHostedControlPlaneNamespace()
testlog.Infof("%s=%s", hypershift.HostedControlPlaneNamespaceEnv, v)

kcPath, _ := os.LookupEnv(hypershift.ManagementClusterKubeConfigEnv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package __performance_status
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/onsi/gomega/gcustom"
types2 "github.com/onsi/gomega/types"
tunedutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/tuned"
"k8s.io/apimachinery/pkg/labels"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -21,8 +22,11 @@ import (

ign2types "github.com/coreos/ignition/config/v2_2/types"
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift"
hypershiftconsts "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift/consts"
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/discovery"
Expand All @@ -32,6 +36,7 @@ import (
"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"
tunedutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/tuned"
v1 "github.com/openshift/custom-resource-status/conditions/v1"
)

Expand Down Expand Up @@ -139,6 +144,74 @@ var _ = Describe("Status testing of performance profile", Ordered, func() {
profiles.WaitForCondition(testutils.NodeSelectorLabels, v1.ConditionDegraded, corev1.ConditionTrue)
})
})

Context("Hypershift specific status validation", Label(string(label.HyperShift)), func() {
var profile *performancev2.PerformanceProfile
ctx := context.Background()
BeforeEach(func() {
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())
})

It("Should have ConfigMap status when running on HyperShift platform", Label(string(label.HyperShift)), func() {
hcpNs, err := hypershiftutils.GetHostedControlPlaneNamespace()
Expect(err).ToNot(HaveOccurred())

np, err := nodepools.GetNodePool(ctx, testclient.ControlPlaneClient)
Expect(err).ToNot(HaveOccurred())

cm := &corev1.ConfigMap{}
cmName := hypershift.GetStatusConfigMapName(fmt.Sprintf("%s-%s", profile.GetName(), np.GetName()))
key := client.ObjectKey{Namespace: hcpNs, Name: cmName}
Expect(testclient.ControlPlaneClient.Get(ctx, key, cm)).To(Succeed(), "failed to find ConfigMap %s/%s", hcpNs, cmName)
})

It("Should not create more than a single ConfigMap status per nodePool when PerformanceProfile gets replace or updated", Label(string(label.HyperShift)), func() {
hcpNs, err := hypershiftutils.GetHostedControlPlaneNamespace()
Expect(err).ToNot(HaveOccurred())

np, err := nodepools.GetNodePool(ctx, testclient.ControlPlaneClient)
Expect(err).ToNot(HaveOccurred())

newProfile := profile.DeepCopy()
newProfile.Name = fmt.Sprintf("%s-2", profile.Name)
Expect(testclient.ControlPlaneClient.Create(ctx, newProfile)).To(Succeed())

// Cleanup: revert back to the original profile and delete the temporary one
defer func() {
By("Reverting back to the original profile")
Expect(nodepools.ReplaceTuningObject(ctx, testclient.ControlPlaneClient, profile, newProfile)).To(Succeed())

By("Waiting for node pool configuration to revert")
Expect(nodepools.WaitForConfigToBeReady(ctx, testclient.ControlPlaneClient, np.Name, np.Namespace)).To(Succeed())

By("Deleting the temporary profile")
Expect(testclient.ControlPlaneClient.Delete(ctx, newProfile)).To(Succeed())
}()

Expect(nodepools.ReplaceTuningObject(ctx, testclient.ControlPlaneClient, newProfile, profile)).To(Succeed())

// nothing changed in the profile but the name, so the nodepool will be transition into updating state for a really
// short time.
// to make sure it's not being missing, the test will only wait for updated state.
By("Waiting to see no more than a single configmap status created")
Consistently(func() {
cmList := &corev1.ConfigMapList{}
opts := &client.ListOptions{
Namespace: hcpNs,
LabelSelector: labels.SelectorFromSet(map[string]string{
hypershiftconsts.NTOGeneratedPerformanceProfileStatusConfigMapLabel: "true",
hypershiftconsts.NodePoolNameLabel: np.GetName(),
}),
}
Expect(testclient.ControlPlaneClient.List(ctx, cmList, opts)).To(Succeed())
Expect(cmList.Items).To(HaveLen(1), "More than a single ConfigMap status was found")
}).WithPolling(time.Second * 10).WithTimeout(time.Minute * 2)

By("Waiting for the node pool configuration to be ready")
Expect(nodepools.WaitForConfigToBeReady(ctx, testclient.ControlPlaneClient, np.Name, np.Namespace)).To(Succeed())
})
})
})

func createBadMachineConfig(name string) *machineconfigv1.MachineConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func BuildControlPlaneClient() (client.Client, error) {
if err != nil {
return nil, err
}
ns, err := GetManagementClusterNamespace()
ns, err := GetHostedControlPlaneNamespace()
if err != nil {
return nil, fmt.Errorf("failed to build management-cluster client for hypershift; err %v", err)
}
Expand All @@ -57,7 +57,7 @@ func GetHostedClusterName() (string, error) {
return v, nil
}

func GetManagementClusterNamespace() (string, error) {
func GetHostedControlPlaneNamespace() (string, error) {
ns, ok := os.LookupEnv(HostedControlPlaneNamespaceEnv)
if !ok {
return "", fmt.Errorf("failed to retrieve management cluster namespace; %q environment var is not set", HostedControlPlaneNamespaceEnv)
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/performanceprofile/functests/utils/nodepools/nodepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ func AttachTuningObjectToNodePool(ctx context.Context, cli client.Client, object
return nil
}

// ReplaceTuningObject works similar to AttachTuningObject but replaces one object with another instead of appending
func ReplaceTuningObject(ctx context.Context, cli client.Client, newObject, oldObject client.Object) error {
var err error
np, err := GetNodePool(ctx, cli)
if err != nil {
return err
}

updatedTuningConfig := corev1.LocalObjectReference{Name: newObject.GetName()}
for i, tuningConfig := range np.Spec.TuningConfig {
if tuningConfig.Name == oldObject.GetName() {
np.Spec.TuningConfig[i] = updatedTuningConfig
}
}
if cli.Update(ctx, np) != nil {
return err
}
return nil
}

func DeattachTuningObject(ctx context.Context, cli client.Client, object client.Object) error {
np, err := GetNodePool(ctx, cli)
if err != nil {
Expand Down