@@ -50,7 +50,7 @@ func (whsvr *Webhook) getEnvVarsToInject(pod *corev1.Pod, container *corev1.Cont
5050 createEnvVarFromString ("NEW_RELIC_METADATA_KUBERNETES_CONTAINER_IMAGE_NAME" , container .Image ),
5151 }
5252
53- whsvr .Logger .Infow ("creating env variables" , "cluster_name" , whsvr .ClusterName , "container_name" , container .Name , "container_image" , container .Image )
53+ whsvr .Logger .Debugw ("creating env variables" , "cluster_name" , whsvr .ClusterName , "container_name" , container .Name , "container_image" , container .Image )
5454 // Guess the name of the deployment. We check whether the Pod is Owned by a ReplicaSet and confirms with the
5555 // naming convention for a Deployment. This can give a false positive if the user uses ReplicaSets directly.
5656 if len (pod .OwnerReferences ) == 1 && pod .OwnerReferences [0 ].Kind == "ReplicaSet" {
@@ -156,12 +156,22 @@ func (whsvr *Webhook) mutate(ar *admissionv1.AdmissionReview) ([]byte, error) {
156156 return nil , err
157157 }
158158
159- whsvr .Logger .Infow ("received admission review" , "kind" , req .Kind , "namespace" , req .Namespace , "name" ,
159+ willMutate := mutationRequired (ignoredNamespaces , & pod .ObjectMeta )
160+ whsvr .Logger .Infow (
161+ "admission review received" ,
162+ "operation" , req .Operation ,
163+ "kind" , req .Kind .Kind ,
164+ "namespace" , pod .Namespace ,
165+ "podGenerateName" , pod .GenerateName , // final pod name not set until after the admission webhooks have run
166+ "uid" , req .UID ,
167+ "mutate" , willMutate ,
168+ )
169+
170+ whsvr .Logger .Debugw ("received admission review" , "kind" , req .Kind , "namespace" , req .Namespace , "name" ,
160171 req .Name , "pod" , pod .Name , "UID" , req .UID , "operation" , req .Operation , "userinfo" , req .UserInfo )
161172
162173 // determine whether to perform mutation
163- if ! mutationRequired (ignoredNamespaces , & pod .ObjectMeta ) {
164- whsvr .Logger .Infow ("skipped mutation" , "namespace" , pod .Namespace , "pod" , pod .Name , "reason" , "policy check (special namespaces)" )
174+ if ! willMutate {
165175 return nil , nil
166176 }
167177
@@ -170,7 +180,7 @@ func (whsvr *Webhook) mutate(ar *admissionv1.AdmissionReview) ([]byte, error) {
170180 return nil , err
171181 }
172182
173- whsvr .Logger .Infow ("admission response created" , "response" , string (patchBytes ))
183+ whsvr .Logger .Debugw ("admission response created" , "response" , string (patchBytes ))
174184 return patchBytes , nil
175185}
176186
@@ -259,7 +269,7 @@ func (whsvr *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
259269 http .Error (w , fmt .Sprintf ("could not encode response: %v" , err ), http .StatusInternalServerError )
260270 return
261271 }
262- whsvr .Logger .Info ("writing response" )
272+ whsvr .Logger .Debug ("writing response" )
263273 if _ , err := w .Write (resp ); err != nil {
264274 whsvr .Logger .Errorw ("can't write response" , "err" , err )
265275 http .Error (w , fmt .Sprintf ("could not write response: %v" , err ), http .StatusInternalServerError )
0 commit comments