Add namespace and other info for logs
@@ -12,9 +12,17 @@ import (
// PodLog Format a log message with pod information
func PodLog(pod *v1.Pod) *logrus.Entry {
if pod != nil {
- return logrus.WithFields(logrus.Fields{
+ fields := logrus.Fields{
"PodName": pod.Name,
- })
+ "Namespace": pod.Namespace,
+ }
+ for _, owner := range pod.OwnerReferences {
+ if *owner.Controller {
+ fields["Owner"] = owner.Kind + "/" + owner.Name
+ break
+ }
+ }
+ return logrus.WithFields(fields)
}
return logrus.WithFields(logrus.Fields{
"Pod": pod,
@@ -26,6 +34,7 @@ func DeploymentV1Log(deployment *appv1.Deployment) *logrus.Entry {
if deployment != nil {
return logrus.WithFields(logrus.Fields{
"DeploymentName": deployment.Name,
+ "Namespace": deployment.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -38,6 +47,7 @@ func DeploymentV1Beta1Log(deployment *appv1beta1.Deployment) *logrus.Entry {
if deployment != nil {
return logrus.WithFields(logrus.Fields{
"DeploymentName": deployment.Name,
+ "Namespace": deployment.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -50,6 +60,7 @@ func DeploymentV1Beta2Log(deployment *appv1beta2.Deployment) *logrus.Entry {
if deployment != nil {
return logrus.WithFields(logrus.Fields{
"DeploymentName": deployment.Name,
+ "Namespace": deployment.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -62,6 +73,7 @@ func StatefulSetV1Log(ss *appv1.StatefulSet) *logrus.Entry {
if ss != nil {
return logrus.WithFields(logrus.Fields{
"StatefulSetName": ss.Name,
+ "Namespace": ss.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -74,6 +86,7 @@ func StatefulSetV1Beta1Log(ss *appv1beta1.StatefulSet) *logrus.Entry {
if ss != nil {
return logrus.WithFields(logrus.Fields{
"StatefulSetName": ss.Name,
+ "Namespace": ss.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -86,6 +99,7 @@ func StatefulSetV1Beta2Log(ss *appv1beta2.StatefulSet) *logrus.Entry {
if ss != nil {
return logrus.WithFields(logrus.Fields{
"StatefulSetName": ss.Name,
+ "Namespace": ss.Namespace,
})
}
return logrus.WithFields(logrus.Fields{
@@ -97,8 +111,8 @@ func StatefulSetV1Beta2Log(ss *appv1beta2.StatefulSet) *logrus.Entry {
func SnapshotLog(snap *crdv1.VolumeSnapshot) *logrus.Entry {
if snap != nil {
return logrus.WithFields(logrus.Fields{
- "SnapshotNamespace": snap.Metadata.Namespace,
"SnapshotName": snap.Metadata.Name,
+ "Namespace": snap.Metadata.Namespace,
})
}
