Skip to content

Commit

Permalink
Merge branch 'master' into issue606
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien committed Feb 3, 2020
2 parents e5e4bfc + d82d557 commit 5c15f5d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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%"]
Expand Down
4 changes: 2 additions & 2 deletions docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-).
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-).
Expand All @@ -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.
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
3 changes: 1 addition & 2 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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. "+
Expand Down
13 changes: 9 additions & 4 deletions pkg/kn/commands/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) (
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
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

0 comments on commit 5c15f5d

Please sign in to comment.