aim to fix runtime class error

This commit is contained in:
Kevin Hannon 2025-02-06 13:01:45 -05:00
parent e54be1e133
commit f75965e5d9

View File

@ -56,9 +56,11 @@ var _ = SIGDescribe("RuntimeClass", func() {
*/ */
framework.ConformanceIt("should reject a Pod requesting a non-existent RuntimeClass", f.WithNodeConformance(), func(ctx context.Context) { framework.ConformanceIt("should reject a Pod requesting a non-existent RuntimeClass", f.WithNodeConformance(), func(ctx context.Context) {
rcName := f.Namespace.Name + "-nonexistent" rcName := f.Namespace.Name + "-nonexistent"
expectPodRejection(ctx, f, e2eruntimeclass.NewRuntimeClassPod(rcName)) err := expectPodRejection(ctx, f, rcName)
// We are expecting a pod rejection above.
// We will fail the test if we get an error other than rejected.
framework.ExpectNoError(err, "unexpected error for pod rejection")
}) })
// The test CANNOT be made a Conformance as it depends on a container runtime to have a specific handler not being installed. // The test CANNOT be made a Conformance as it depends on a container runtime to have a specific handler not being installed.
f.It("should reject a Pod requesting a RuntimeClass with an unconfigured handler", feature.RuntimeHandler, func(ctx context.Context) { f.It("should reject a Pod requesting a RuntimeClass with an unconfigured handler", feature.RuntimeHandler, func(ctx context.Context) {
handler := f.Namespace.Name + "-handler" handler := f.Namespace.Name + "-handler"
@ -160,8 +162,7 @@ var _ = SIGDescribe("RuntimeClass", func() {
rcClient := f.ClientSet.NodeV1().RuntimeClasses() rcClient := f.ClientSet.NodeV1().RuntimeClasses()
ginkgo.By("Deleting RuntimeClass "+rcName, func() { ginkgo.By("Deleting RuntimeClass "+rcName, func() {
err := rcClient.Delete(ctx, rcName, metav1.DeleteOptions{}) deleteRuntimeClass(ctx, f, rcName)
framework.ExpectNoError(err, "failed to delete RuntimeClass %s", rcName)
ginkgo.By("Waiting for the RuntimeClass to disappear") ginkgo.By("Waiting for the RuntimeClass to disappear")
framework.ExpectNoError(wait.PollUntilContextTimeout(ctx, framework.Poll, time.Minute, true, func(ctx context.Context) (bool, error) { framework.ExpectNoError(wait.PollUntilContextTimeout(ctx, framework.Poll, time.Minute, true, func(ctx context.Context) (bool, error) {
@ -176,7 +177,9 @@ var _ = SIGDescribe("RuntimeClass", func() {
})) }))
}) })
expectPodRejection(ctx, f, e2eruntimeclass.NewRuntimeClassPod(rcName)) gomega.Eventually(ctx, func() error {
return expectPodRejection(ctx, f, rcName)
}, ContainerStatusRetryTimeout, ContainerStatusPollInterval).Should(gomega.Succeed())
}) })
/* /*
@ -375,12 +378,19 @@ func createRuntimeClass(ctx context.Context, f *framework.Framework, name, handl
return rc.GetName() return rc.GetName()
} }
func expectPodRejection(ctx context.Context, f *framework.Framework, pod *v1.Pod) { // expectPodRejection is testing that kubelet cannot admit a runtime class pod
_, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, pod, metav1.CreateOptions{}) // rejections happen in the admission and we expect a forbidden error for these cases.
gomega.Expect(err).To(gomega.HaveOccurred(), "should be forbidden") func expectPodRejection(ctx context.Context, f *framework.Framework, rcName string) error {
if !apierrors.IsForbidden(err) { pod := e2eruntimeclass.NewRuntimeClassPod(rcName)
framework.Failf("expected forbidden error, got %#v", err) _, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, pod, metav1.CreateOptions{DryRun: []string{metav1.DryRunAll}})
if err == nil {
return fmt.Errorf("should get forbidden error")
} }
if !apierrors.IsForbidden(err) {
return err
}
// in this case means we got the forbidden error
return nil
} }
// expectPodSuccess waits for the given pod to terminate successfully. // expectPodSuccess waits for the given pod to terminate successfully.