Correctly handle secret and configMap envs in kubectl describe

This commit is contained in:
Paul Morie
2016-04-05 17:36:22 -04:00
parent 4f329516ae
commit 9069cbb086
3 changed files with 76 additions and 3 deletions

View File

@@ -856,14 +856,22 @@ func describeContainers(containers []api.Container, containerStatuses []api.Cont
}
fmt.Fprintf(out, " Environment Variables:%s\n", none)
for _, e := range container.Env {
if e.ValueFrom != nil && e.ValueFrom.FieldRef != nil {
if e.ValueFrom == nil {
fmt.Fprintf(out, " %s:\t%s\n", e.Name, e.Value)
continue
}
switch {
case e.ValueFrom.FieldRef != nil:
var valueFrom string
if resolverFn != nil {
valueFrom = resolverFn(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)
case e.ValueFrom.SecretKeyRef != nil:
fmt.Fprintf(out, " %s:\t<set to the key '%s' in secret '%s'>\n", e.Name, e.ValueFrom.SecretKeyRef.Key, e.ValueFrom.SecretKeyRef.Name)
case e.ValueFrom.ConfigMapKeyRef != nil:
fmt.Fprintf(out, " %s:\t<set to the key '%s' of config map '%s'>\n", e.Name, e.ValueFrom.ConfigMapKeyRef.Key, e.ValueFrom.ConfigMapKeyRef.Name)
}
}
}