diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 9902ed6fe6..7986772e68 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -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" diff --git a/pkg/kubectl/describe_test.go b/pkg/kubectl/describe_test.go index 4ca08ac6e8..f97a01d5ba 100644 --- a/pkg/kubectl/describe_test.go +++ b/pkg/kubectl/describe_test.go @@ -182,6 +182,16 @@ func TestDescribeContainers(t *testing.T) { }, expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image"}, }, + //env + { + container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}}, + status: api.ContainerStatus{ + Name: "test", + Ready: true, + RestartCount: 7, + }, + expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz"}, + }, // Using limits. { container: api.Container{