hook: infer Pod namespace from admission request
Pods passed to mutating webhook may have empty name/namespace
if they are created from templates in Jobs.  For such cases,
name/namespace given by the admission request can be used
instead.
@@ -46,6 +46,13 @@ func (m podMutator) Handle(ctx context.Context, req admission.Request) admission
return admission.Allowed("no volumes")
}
+ // Pods instantiated from templates may have empty name/namespace.
+ // To lookup PVC in the same namespace, we set namespace obtained from req.
+ if pod.Namespace == "" {
+ pmLogger.Info("infer pod namespace from req", "namespace", req.Namespace)
+ pod.Namespace = req.Namespace
+ }
+
targets, err := m.targetStorageClasses(ctx)
if err != nil {
pmLogger.Error(err, "targetStorageClasses failed")
