Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
////


## v0.13.0 (unreleased)

[cols="1,10,3", options="header", width="100%"]
|===
| | Description | PR

| 🐛
| Show envFrom when running describe service or revision
| https://github.com/knative/client/pull/630

## v0.12.0 (2020-01-29)

[cols="1,10,3", options="header", width="100%"]
Expand Down
26 changes: 26 additions & 0 deletions pkg/kn/commands/revision/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func describe(w io.Writer, revision *v1alpha1.Revision, service *v1alpha1.Servic
WriteImage(dw, revision)
WritePort(dw, revision)
WriteEnv(dw, revision, printDetails)
WriteEnvFrom(dw, revision, printDetails)
WriteScale(dw, revision)
WriteConcurrencyOptions(dw, revision)
WriteResources(dw, revision)
Expand Down Expand Up @@ -190,6 +191,13 @@ func WriteEnv(dw printers.PrefixWriter, revision *v1alpha1.Revision, printDetail
}
}

func WriteEnvFrom(dw printers.PrefixWriter, revision *v1alpha1.Revision, printDetails bool) {
envFrom := stringifyEnvFrom(revision)
if envFrom != nil {
commands.WriteSliceDesc(dw, envFrom, "EnvFrom", printDetails)
}
}

func WriteScale(dw printers.PrefixWriter, revision *v1alpha1.Revision) {
// Scale spec if given
scale, err := clientserving.ScalingInfo(&revision.ObjectMeta)
Expand Down Expand Up @@ -274,3 +282,21 @@ func stringifyEnv(revision *v1alpha1.Revision) []string {
}
return envVars
}

func stringifyEnvFrom(revision *v1alpha1.Revision) []string {
container, err := clientserving.ContainerOfRevisionSpec(&revision.Spec)
if err != nil {
return nil
}

var result []string
for _, envFromSource := range container.EnvFrom {
if envFromSource.ConfigMapRef != nil {
result = append(result, "cm:"+envFromSource.ConfigMapRef.Name)
}
if envFromSource.SecretRef != nil {
result = append(result, "secret:"+envFromSource.SecretRef.Name)
}
}
return result
}
5 changes: 5 additions & 0 deletions pkg/kn/commands/revision/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestDescribeRevisionBasic(t *testing.T) {
}

assert.Assert(t, util.ContainsAll(data, "Image:", "gcr.io/test/image", "++ Ready", "Port:", "8080"))
assert.Assert(t, util.ContainsAll(data, "EnvFrom:", "cm:test1, cm:test2"))
}

func createTestRevision(revision string, gen int64) v1alpha1.Revision {
Expand Down Expand Up @@ -153,6 +154,10 @@ func createTestRevision(revision string, gen int64) v1alpha1.Revision {
{Name: "env1", Value: "eval1"},
{Name: "env2", Value: "eval2"},
},
EnvFrom: []v1.EnvFromSource{
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test1"}}},
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test2"}}},
},
Ports: []v1.ContainerPort{
{ContainerPort: 8080},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/kn/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func writeRevisions(dw printers.PrefixWriter, revisions []*revisionDesc, printDe
if printDetails {
revision.WritePort(section, revisionDesc.revision)
revision.WriteEnv(section, revisionDesc.revision, printDetails)
revision.WriteEnvFrom(section, revisionDesc.revision, printDetails)
revision.WriteScale(section, revisionDesc.revision)
revision.WriteConcurrencyOptions(section, revisionDesc.revision)
revision.WriteResources(section, revisionDesc.revision)
Expand Down
7 changes: 6 additions & 1 deletion pkg/kn/commands/service/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ func TestServiceDescribeVerbose(t *testing.T) {

assert.Assert(t, cmp.Regexp("Cluster:\\s+http://foo.default.svc.cluster.local", output))
assert.Assert(t, util.ContainsAll(output, "Image", "Name", "gcr.io/test/image (at 123456)", "50%", "(0s)"))
assert.Assert(t, util.ContainsAll(output, "Env:", "label1=lval1\n", "label2=lval2\n"))
assert.Assert(t, util.ContainsAll(output, "Env:", "env1=eval1\n", "env2=eval2\n"))
assert.Assert(t, util.ContainsAll(output, "EnvFrom:", "cm:test1\n", "cm:test2\n"))
assert.Assert(t, util.ContainsAll(output, "Annotations:", "anno1=aval1\n", "anno2=aval2\n"))
assert.Assert(t, util.ContainsAll(output, "Labels:", "label1=lval1\n", "label2=lval2\n"))
assert.Assert(t, util.ContainsAll(output, "[1]", "[2]"))
Expand Down Expand Up @@ -636,6 +637,10 @@ func createTestRevision(revision string, gen int64) v1alpha1.Revision {
{Name: "env1", Value: "eval1"},
{Name: "env2", Value: "eval2"},
},
EnvFrom: []v1.EnvFromSource{
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test1"}}},
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test2"}}},
},
Ports: []v1.ContainerPort{
{ContainerPort: 8080},
},
Expand Down