diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c044e45c39..469227d8ee 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -23,6 +23,16 @@ | adds --cluster-local / --no-cluster-local flags | https://github.com/knative/client/pull/629[#629] +## 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%"] diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index e322cff8ae..5d668c3546 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -48,7 +48,7 @@ kn service create NAME --image IMAGE [flags] --annotation stringArray Service annotation to set. name=value; you may provide this flag any number of times to set multiple annotations. To unset, specify the annotation name followed by a "-" (e.g., name-). --async Create service and don't wait for it to become ready. --autoscale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s) - --cluster-local specify that the service be private; sets service's route visibility to 'cluster-local'.(--no-cluster-local will remove any 'cluster-local' route visibility) + --cluster-local specify that the service be private. (--no-cluster-local will make the service publicly available --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given. -e, --env stringArray Environment variable to set. NAME=value; you may provide this flag any number of times to set multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-). @@ -64,7 +64,7 @@ kn service create NAME --image IMAGE [flags] --min-scale int Minimal number of replicas. --mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume. -n, --namespace string Specify the namespace to operate in. - --no-cluster-local do not specify that the service be private; sets service's route visibility to 'cluster-local'.(--no-cluster-local will remove any 'cluster-local' route visibility) (default true) + --no-cluster-local do not specify that the service be private. (--no-cluster-local will make the service publicly available (default true) --no-lock-to-digest do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) -p, --port int32 The port where application listens on. --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index fccc04a2f0..3a6194e4dc 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -41,7 +41,7 @@ kn service update NAME [flags] --annotation stringArray Service annotation to set. name=value; you may provide this flag any number of times to set multiple annotations. To unset, specify the annotation name followed by a "-" (e.g., name-). --async Update service and don't wait for it to become ready. --autoscale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s) - --cluster-local specify that the service be private; sets service's route visibility to 'cluster-local'.(--no-cluster-local will remove any 'cluster-local' route visibility) + --cluster-local specify that the service be private. (--no-cluster-local will make the service publicly available --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given. -e, --env stringArray Environment variable to set. NAME=value; you may provide this flag any number of times to set multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-). @@ -56,7 +56,7 @@ kn service update NAME [flags] --min-scale int Minimal number of replicas. --mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume. -n, --namespace string Specify the namespace to operate in. - --no-cluster-local do not specify that the service be private; sets service's route visibility to 'cluster-local'.(--no-cluster-local will remove any 'cluster-local' route visibility) (default true) + --no-cluster-local do not specify that the service be private. (--no-cluster-local will make the service publicly available (default true) --no-lock-to-digest do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) -p, --port int32 The port where application listens on. --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. diff --git a/pkg/kn/commands/revision/describe.go b/pkg/kn/commands/revision/describe.go index 686036f7e2..8e1c92a1f0 100644 --- a/pkg/kn/commands/revision/describe.go +++ b/pkg/kn/commands/revision/describe.go @@ -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) @@ -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) @@ -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 +} diff --git a/pkg/kn/commands/revision/describe_test.go b/pkg/kn/commands/revision/describe_test.go index 883ba0acc5..70a1dbdbcf 100644 --- a/pkg/kn/commands/revision/describe_test.go +++ b/pkg/kn/commands/revision/describe_test.go @@ -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 { @@ -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}, }, diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index fa096b5b55..ee49790a58 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -119,8 +119,7 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) { command.Flags().StringVar(&p.AutoscaleWindow, "autoscale-window", "", "Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s)") p.markFlagMakesRevision("autoscale-window") flags.AddBothBoolFlagsUnhidden(command.Flags(), &p.ClusterLocal, "cluster-local", "", false, - "specify that the service be private; sets service's route visibility to 'cluster-local'."+ - "(--no-cluster-local will remove any 'cluster-local' route visibility)") + "specify that the service be private. (--no-cluster-local will make the service publicly available") p.markFlagMakesRevision("cluster-local") command.Flags().IntVar(&p.ConcurrencyTarget, "concurrency-target", 0, "Recommendation for when to scale up based on the concurrent number of incoming request. "+ diff --git a/pkg/kn/commands/service/create_test.go b/pkg/kn/commands/service/create_test.go index 874ba4fcef..a512ba2917 100644 --- a/pkg/kn/commands/service/create_test.go +++ b/pkg/kn/commands/service/create_test.go @@ -35,6 +35,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" client_testing "k8s.io/client-go/testing" "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/reconciler/route/config" ) func fakeServiceCreate(args []string, withExistingService bool, sync bool) ( @@ -498,7 +499,7 @@ func TestServiceCreateWithServiceAccountName(t *testing.T) { func TestServiceCreateWithClusterLocal(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", - "--cluster-local"}, false, false) + "--cluster-local", "--async"}, false, false) if err != nil { t.Fatal(err) @@ -511,6 +512,10 @@ func TestServiceCreateWithClusterLocal(t *testing.T) { t.Fatal(err) } - _, present := template.Labels[config.VisibilityLabelKey] - assert.Assert(t, !present) -} + labelValue, present := template.Labels[config.VisibilityLabelKey] + assert.Assert(t, present) + + if labelValue != config.VisibilityClusterLocal { + t.Fatalf("Incorrect VisibilityClusterLocal value '%s'", labelValue) + } +} \ No newline at end of file diff --git a/pkg/kn/commands/service/describe.go b/pkg/kn/commands/service/describe.go index 7db5bdd7b9..3456da4f96 100644 --- a/pkg/kn/commands/service/describe.go +++ b/pkg/kn/commands/service/describe.go @@ -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) diff --git a/pkg/kn/commands/service/describe_test.go b/pkg/kn/commands/service/describe_test.go index b54e62e59d..c582996fb4 100644 --- a/pkg/kn/commands/service/describe_test.go +++ b/pkg/kn/commands/service/describe_test.go @@ -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]")) @@ -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}, },