mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
print env vars in kubectl describe pod
Signed-off-by: Sam Abed <samabed@gmail.com>
This commit is contained in:
parent
4e6325a3da
commit
2fe650dcee
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fieldpath"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"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, " Ready:\t%v\n", printBool(status.Ready))
|
||||||
fmt.Fprintf(out, " Restart Count:\t%d\n", status.RestartCount)
|
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 {
|
func printBool(value bool) string {
|
||||||
if value {
|
if value {
|
||||||
return "True"
|
return "True"
|
||||||
|
@ -182,6 +182,16 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image"},
|
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.
|
// Using limits.
|
||||||
{
|
{
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
|
Loading…
Reference in New Issue
Block a user