Fix admission hook for pods generated by ReplicaSet

In the pods generated automatically by Deployment/ReplicaSets
fields name and namespace might be missing.
We can use information about namespace from request itself.
This commit is contained in:
Alexander Kanevskiy 2019-10-24 23:58:36 +03:00 committed by Alexander Kanevskiy
parent b475adf162
commit 67825dcc06

View File

@ -87,8 +87,17 @@ func mutatePods(ar v1beta1.AdmissionReview, pm *patcherManager) *v1beta1.Admissi
fmt.Printf("ERROR: %+v\n", err)
return toAdmissionResponse(err)
}
debug.Printf("Received pod '%s' in name space '%s'", pod.Name, pod.Namespace)
patcher, err := pm.getPatcher(pod.Namespace)
namespace := pod.Namespace
if namespace == "" && ar.Request.Namespace != "" {
namespace = ar.Request.Namespace
}
name := pod.Name
if name == "" && pod.ObjectMeta.GenerateName != "" {
name = pod.ObjectMeta.GenerateName
}
debug.Printf("Received pod '%s' in name space '%s'", name, namespace)
patcher, err := pm.getPatcher(namespace)
if err != nil {
fmt.Printf("ERROR: %+v\n", err)
return toAdmissionResponse(err)