@@ -60,6 +60,48 @@ var _ = Describe("TensorFusionPodMutator", func() {
6060 })
6161
6262 Context ("Handle" , func () {
63+ It ("should handle pod with empty namespace and set workload.Namespace to 'default' (via Handle)" , func () {
64+ // Create a pod with empty namespace
65+ pod := & corev1.Pod {
66+ ObjectMeta : metav1.ObjectMeta {
67+ Name : "test-pod-empty-ns" ,
68+ // empty namespace
69+ Namespace : "" ,
70+ Labels : map [string ]string {
71+ constants .TensorFusionEnabledLabelKey : "true" ,
72+ },
73+ Annotations : map [string ]string {
74+ constants .GpuPoolKey : "mock" ,
75+ constants .InjectContainerAnnotation : "main" ,
76+ constants .WorkloadKey : "test-workload-empty-ns" ,
77+ constants .GenWorkloadAnnotation : "true" ,
78+ },
79+ },
80+ Spec : corev1.PodSpec {
81+ Containers : []corev1.Container {{
82+ Name : "main" ,
83+ Image : "test-image" ,
84+ }},
85+ },
86+ }
87+ podBytes , err := json .Marshal (pod )
88+ Expect (err ).NotTo (HaveOccurred ())
89+
90+ // Construct an admission request with the pod
91+ req := admission.Request {
92+ AdmissionRequest : admissionv1.AdmissionRequest {
93+ Object : runtime.RawExtension {
94+ Raw : podBytes ,
95+ },
96+ Operation : admissionv1 .Create ,
97+ },
98+ }
99+
100+ // Call mutator.Handle to process the admission request
101+ resp := mutator .Handle (ctx , req )
102+ Expect (resp .Allowed ).To (BeTrue ())
103+ })
104+
63105 It ("should successfully mutate a pod with TF resources" , func () {
64106 // Set up a workload profile for testing
65107 workloadProfile := & tfv1.WorkloadProfile {
0 commit comments