@@ -28,6 +28,7 @@ import (
2828 corev1apply "k8s.io/client-go/applyconfigurations/core/v1"
2929 metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
3030 "k8s.io/utils/pointer"
31+ "k8s.io/utils/ptr"
3132
3233 offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1"
3334 "github.com/liqotech/liqo/pkg/consts"
@@ -458,6 +459,99 @@ var _ = Describe("Pod forging", func() {
458459 })
459460 })
460461
462+ Describe ("the runtimeClassNameMutator function" , func () {
463+ const (
464+ fakeRuntimeClassOffPatch = "foo"
465+ fakeRuntimeClassPodSpec = "bar"
466+ fakeRuntimeClassPodAnnot = "baz"
467+ )
468+
469+ var (
470+ local * corev1.Pod
471+ remote * corev1.PodSpec
472+ forgingOpts * forge.ForgingOpts
473+ )
474+
475+ BeforeEach (func () {
476+ local = & corev1.Pod {
477+ ObjectMeta : metav1.ObjectMeta {
478+ Name : "foo" ,
479+ Namespace : "bar" ,
480+ },
481+ Spec : corev1.PodSpec {},
482+ }
483+ remote = & corev1.PodSpec {}
484+ forgingOpts = & forge.ForgingOpts {}
485+ })
486+
487+ JustBeforeEach (func () { forge .RuntimeClassNameMutator (local , forgingOpts )(remote ) })
488+
489+ When ("runtimeclass is set in the OffloadingPatch" , func () {
490+ BeforeEach (func () {
491+ forgingOpts .RuntimeClassName = ptr .To (fakeRuntimeClassOffPatch )
492+ })
493+
494+ It ("should set the runtimeclass of the OffloadingPatch" , func () {
495+ Expect (remote .RuntimeClassName ).To (PointTo (Equal (fakeRuntimeClassOffPatch )))
496+ })
497+ })
498+
499+ When ("runtimeclass is set in the OffloadingPatch and in the Pod spec" , func () {
500+ BeforeEach (func () {
501+ forgingOpts .RuntimeClassName = ptr .To (fakeRuntimeClassOffPatch )
502+ local .Spec .RuntimeClassName = ptr .To (fakeRuntimeClassPodSpec )
503+ })
504+
505+ It ("should set the runtimeclass of the pod spec" , func () {
506+ Expect (remote .RuntimeClassName ).To (PointTo (Equal (fakeRuntimeClassPodSpec )))
507+ })
508+ })
509+
510+ When ("runtimeclass is set in the OffloadingPatch, Pod spec and Pod annotation" , func () {
511+ BeforeEach (func () {
512+ forgingOpts .RuntimeClassName = ptr .To (fakeRuntimeClassOffPatch )
513+ local .Spec .RuntimeClassName = ptr .To (fakeRuntimeClassPodSpec )
514+ local .Annotations = map [string ]string {consts .RemoteRuntimeClassNameAnnotKey : fakeRuntimeClassPodAnnot }
515+ })
516+
517+ It ("should set the runtimeclass of the pod annotation" , func () {
518+ Expect (remote .RuntimeClassName ).To (PointTo (Equal (fakeRuntimeClassPodAnnot )))
519+ })
520+ })
521+
522+ When ("runtimeclass is set to the liqo one" , func () {
523+ BeforeEach (func () {
524+ local .Spec .RuntimeClassName = ptr .To (consts .LiqoRuntimeClassName )
525+ })
526+
527+ When ("OffloadingPatch and Pod annotation are not set" , func () {
528+ It ("should leave the runtimeclass empty" , func () {
529+ Expect (remote .RuntimeClassName ).To (BeNil ())
530+ })
531+ })
532+
533+ When ("OffloadingPatch is set" , func () {
534+ BeforeEach (func () {
535+ forgingOpts .RuntimeClassName = ptr .To (fakeRuntimeClassOffPatch )
536+ })
537+
538+ It ("should set the runtimeclass of the OffloadingPatch" , func () {
539+ Expect (remote .RuntimeClassName ).To (PointTo (Equal (fakeRuntimeClassOffPatch )))
540+ })
541+ })
542+
543+ When ("Pod annotation is set" , func () {
544+ BeforeEach (func () {
545+ local .Annotations = map [string ]string {consts .RemoteRuntimeClassNameAnnotKey : fakeRuntimeClassPodAnnot }
546+ })
547+
548+ It ("should set the runtimeclass of the Pod annotation" , func () {
549+ Expect (remote .RuntimeClassName ).To (PointTo (Equal (fakeRuntimeClassPodAnnot )))
550+ })
551+ })
552+ })
553+ })
554+
461555 Describe ("the RemoteContainersAPIServerSupport function" , func () {
462556 var container corev1.Container
463557 var output []corev1.Container
0 commit comments