print env vars in kubectl describe pod

Signed-off-by: Sam Abed <samabed@gmail.com>
This commit is contained in:
Sam Abed
2015-07-05 00:31:15 +10:00
committed by Sam Abed
parent 4e6325a3da
commit 2fe650dcee
2 changed files with 34 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fieldpath"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
@@ -528,9 +529,32 @@ func describeContainers(pod *api.Pod, out io.Writer) {
fmt.Fprintf(out, " Ready:\t%v\n", printBool(status.Ready))
fmt.Fprintf(out, " Restart Count:\t%d\n", status.RestartCount)
fmt.Fprintf(out, " Variables:\n")
for _, e := range container.Env {
if e.ValueFrom != nil && e.ValueFrom.FieldRef != nil {
valueFrom := envValueFrom(pod, e)
fmt.Fprintf(out, " %s:\t%s (%s:%s)\n", e.Name, valueFrom, e.ValueFrom.FieldRef.APIVersion, e.ValueFrom.FieldRef.FieldPath)
} else {
fmt.Fprintf(out, " %s:\t%s\n", e.Name, e.Value)
}
}
}
}
func envValueFrom(pod *api.Pod, e api.EnvVar) string {
internalFieldPath, _, err := api.Scheme.ConvertFieldLabel(e.ValueFrom.FieldRef.APIVersion, "Pod", e.ValueFrom.FieldRef.FieldPath, "")
if err != nil {
return "" // pod validation should catch this on create
}
valueFrom, err := fieldpath.ExtractFieldPathAsString(pod, internalFieldPath)
if err != nil {
return "" // pod validation should catch this on create
}
return valueFrom
}
func printBool(value bool) string {
if value {
return "True"