Skip to content
Open
Changes from 1 commit
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
70 changes: 70 additions & 0 deletions test/extended/scheduling/dra.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
admissionapi "k8s.io/pod-security-admission/api"
"k8s.io/utils/ptr"

configv1 "github.com/openshift/api/config/v1"
exutil "github.com/openshift/origin/test/extended/util"
)

Expand Down Expand Up @@ -755,5 +756,74 @@ var _ = g.Describe("[sig-scheduling][OCPFeatureGate:DynamicResourceAllocation]",
"v1 should be the preferred version")
})

// Adding a test for the DynamicResourceAllocation field in Scheduler ProfileCustomizations that depends on downstream DynamicResourceAllocation feature gate.
g.It("should support DynamicResourceAllocation field in Scheduler ProfileCustomizations [apigroup:config.openshift.io]", func(ctx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what value this test provides specific to DRA, if we want to validate that setting this value to either true or false enables/disables the dra plugin in the scheduler, then the test needs to wait for the scheduler to rollout and then validates appropriately.

g.By("getting the cluster Scheduler configuration")
schedulerConfig, err := oc.AdminConfigClient().ConfigV1().Schedulers().Get(ctx, "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to get cluster Scheduler configuration")
o.Expect(schedulerConfig).NotTo(o.BeNil())

// Store original configuration for restoration
originalDRAConfig := schedulerConfig.Spec.ProfileCustomizations.DynamicResourceAllocation

// Ensure cleanup to restore original configuration
g.DeferCleanup(func(ctx context.Context) {
framework.Logf("Restoring original DRA configuration: %s", originalDRAConfig)
scheduler, err := oc.AdminConfigClient().ConfigV1().Schedulers().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
framework.Logf("Warning: failed to get scheduler for cleanup: %v", err)
return
}
scheduler.Spec.ProfileCustomizations.DynamicResourceAllocation = originalDRAConfig
_, err = oc.AdminConfigClient().ConfigV1().Schedulers().Update(ctx, scheduler, metav1.UpdateOptions{})
if err != nil {
framework.Logf("Warning: failed to restore original scheduler configuration: %v", err)
}
})

g.By("verifying ProfileCustomizations field is accessible")
framework.Logf("Current DynamicResourceAllocation setting: %q", schedulerConfig.Spec.ProfileCustomizations.DynamicResourceAllocation)
o.Expect(schedulerConfig.Spec.ProfileCustomizations).NotTo(o.BeNil())

g.By("updating DynamicResourceAllocation to Enabled")
schedulerConfig.Spec.ProfileCustomizations.DynamicResourceAllocation = configv1.DRAEnablementEnabled
updatedScheduler, err := oc.AdminConfigClient().ConfigV1().Schedulers().Update(ctx, schedulerConfig, metav1.UpdateOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to update Scheduler with DRA Enabled")
o.Expect(updatedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablementEnabled))

g.By("verifying the update was persisted")
retrievedScheduler, err := oc.AdminConfigClient().ConfigV1().Schedulers().Get(ctx, "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to get updated Scheduler configuration")
o.Expect(retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablementEnabled))

g.By("updating DynamicResourceAllocation to Disabled")
retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation = configv1.DRAEnablementDisabled
updatedScheduler, err = oc.AdminConfigClient().ConfigV1().Schedulers().Update(ctx, retrievedScheduler, metav1.UpdateOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to update Scheduler with DRA Disabled")
o.Expect(updatedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablementDisabled))

g.By("verifying the Disabled setting was persisted")
retrievedScheduler, err = oc.AdminConfigClient().ConfigV1().Schedulers().Get(ctx, "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to get updated Scheduler configuration")
o.Expect(retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablementDisabled))

g.By("updating DynamicResourceAllocation to empty (omitted)")
retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation = ""
updatedScheduler, err = oc.AdminConfigClient().ConfigV1().Schedulers().Update(ctx, retrievedScheduler, metav1.UpdateOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to update Scheduler with DRA omitted")
o.Expect(updatedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablement("")))

g.By("verifying the empty setting was persisted")
retrievedScheduler, err = oc.AdminConfigClient().ConfigV1().Schedulers().Get(ctx, "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to get updated Scheduler configuration")
o.Expect(retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation).To(o.Equal(configv1.DRAEnablement("")))

g.By("verifying invalid values are rejected")
retrievedScheduler.Spec.ProfileCustomizations.DynamicResourceAllocation = configv1.DRAEnablement("Invalid")
_, err = oc.AdminConfigClient().ConfigV1().Schedulers().Update(ctx, retrievedScheduler, metav1.UpdateOptions{})
o.Expect(err).To(o.HaveOccurred(), "should reject invalid DynamicResourceAllocation value")
framework.Logf("Correctly rejected invalid value: %v", err)
})

})
})