Skip to content

Commit

Permalink
Show ce-override extensions in describe output
Browse files Browse the repository at this point in the history
  • Loading branch information
navidshaikh committed May 29, 2020
1 parent e7e3dd7 commit 08dacb7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
17 changes: 17 additions & 0 deletions pkg/kn/commands/source/apiserver/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package apiserver
import (
"errors"
"fmt"
"sort"

"github.com/spf13/cobra"
v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
Expand Down Expand Up @@ -71,6 +72,10 @@ func NewAPIServerDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

if apiSource.Spec.CloudEventOverrides != nil && apiSource.Spec.CloudEventOverrides.Extensions != nil {
writeCeOverrides(dw, apiSource.Spec.CloudEventOverrides.Extensions)
}

writeResources(dw, apiSource.Spec.Resources)
dw.WriteLine()
if err := dw.Flush(); err != nil {
Expand Down Expand Up @@ -122,3 +127,15 @@ func writeAPIServerSource(dw printers.PrefixWriter, source *v1alpha2.ApiServerSo
dw.WriteAttribute("ServiceAccountName", source.Spec.ServiceAccountName)
dw.WriteAttribute("EventMode", source.Spec.EventMode)
}

func writeCeOverrides(dw printers.PrefixWriter, ceOverrides map[string]string) {
subDw := dw.WriteAttribute("CloudEvent Overrides", "")
var keys []string
for k := range ceOverrides {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
subDw.WriteAttribute(k, ceOverrides[k])
}
}
4 changes: 2 additions & 2 deletions pkg/kn/commands/source/apiserver/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestSimpleDescribe(t *testing.T) {
apiServerClient := v1alpha2.NewMockKnAPIServerSourceClient(t, "mynamespace")

apiServerRecorder := apiServerClient.Recorder()
sampleSource := createAPIServerSource("testsource", "Event", "v1", "testsa", "Reference", "testsvc", nil)
sampleSource := createAPIServerSource("testsource", "Event", "v1", "testsa", "Reference", "testsvc", map[string]string{"foo": "bar"})
apiServerRecorder.GetAPIServerSource("testsource", sampleSource, nil)

out, err := executeAPIServerSourceCommand(apiServerClient, nil, "describe", "testsource")
assert.NilError(t, err)
util.ContainsAll(out, "testsource", "testsa", "Reference", "testsvc", "Service", "Resources", "Event", "v1", "false", "Conditions")
util.ContainsAll(out, "testsource", "testsa", "Reference", "testsvc", "Service", "Resources", "Event", "v1", "false", "Conditions", "foo", "bar")

apiServerRecorder.Validate()
}
Expand Down
29 changes: 25 additions & 4 deletions pkg/kn/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ping
import (
"errors"
"fmt"
"sort"

"github.com/spf13/cobra"
v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
Expand Down Expand Up @@ -46,7 +47,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

cjSource, err := pingSourceClient.GetPingSource(name)
pingSource, err := pingSourceClient.GetPingSource(name)
if err != nil {
return err
}
Expand All @@ -59,21 +60,29 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
return err
}

writePingSource(dw, cjSource, printDetails)
writePingSource(dw, pingSource, printDetails)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
}

// Revisions summary info
writeSink(dw, &cjSource.Spec.Sink)
writeSink(dw, &pingSource.Spec.Sink)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
}

if pingSource.Spec.CloudEventOverrides != nil && pingSource.Spec.CloudEventOverrides.Extensions != nil {
writeCeOverrides(dw, pingSource.Spec.CloudEventOverrides.Extensions)
dw.WriteLine()
if err := dw.Flush(); err != nil {
return err
}
}

// Condition info
commands.WriteConditions(dw, cjSource.Status.Conditions, printDetails)
commands.WriteConditions(dw, pingSource.Status.Conditions, printDetails)
if err := dw.Flush(); err != nil {
return err
}
Expand Down Expand Up @@ -107,3 +116,15 @@ func writePingSource(dw printers.PrefixWriter, source *v1alpha2.PingSource, prin
dw.WriteAttribute("Schedule", source.Spec.Schedule)
dw.WriteAttribute("Data", source.Spec.JsonData)
}

func writeCeOverrides(dw printers.PrefixWriter, ceOverrides map[string]string) {
subDw := dw.WriteAttribute("CloudEvent Overrides", "")
var keys []string
for k := range ceOverrides {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
subDw.WriteAttribute(k, ceOverrides[k])
}
}
30 changes: 4 additions & 26 deletions pkg/kn/commands/source/ping/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ func TestDescribeRef(t *testing.T) {
pingClient := clientv1alpha2.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource-ref", getPingSourceSinkRef(), nil)
pingRecorder.GetPingSource("testping",
createPingSource("testping", "*/2 * * * *", "test", "testsvc", map[string]string{"foo": "bar"}), nil)

out, err := executePingSourceCommand(pingClient, nil, "describe", "testsource-ref")
out, err := executePingSourceCommand(pingClient, nil, "describe", "testping")
assert.NilError(t, err)
assert.Assert(t, util.ContainsAll(out, "1 2 3 4 5", "honeymoon", "myservicenamespace", "mysvc", "Service", "testsource-ref"))
assert.Assert(t, util.ContainsAll(out, "*/2 * * * *", "test", "testsvc", "Service", "Overrides", "foo", "bar", "Conditions"))

pingRecorder.Validate()
}
Expand Down Expand Up @@ -68,29 +69,6 @@ func TestDescribeError(t *testing.T) {

}

func getPingSourceSinkRef() *v1alpha2.PingSource {
return &v1alpha2.PingSource{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "testsource-ref",
},
Spec: v1alpha2.PingSourceSpec{
Schedule: "1 2 3 4 5",
JsonData: "honeymoon",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Service",
Namespace: "myservicenamespace",
Name: "mysvc",
},
},
},
},
Status: v1alpha2.PingSourceStatus{},
}
}

func getPingSourceSinkURI() *v1alpha2.PingSource {
return &v1alpha2.PingSource{
TypeMeta: metav1.TypeMeta{},
Expand Down

0 comments on commit 08dacb7

Please sign in to comment.