-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: List available channel types #1027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## kn channel list-types | ||
|
||
List channel types | ||
|
||
### Synopsis | ||
|
||
List channel types | ||
|
||
``` | ||
kn channel list-types | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
|
||
# List available channel types | ||
kn channel list-types | ||
|
||
# List available channel types in YAML format | ||
kn channel list-types -o yaml | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true) | ||
-h, --help help for list-types | ||
-n, --namespace string Specify the namespace to operate in. | ||
--no-headers When using the default output format, don't print headers (default: print headers). | ||
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file. | ||
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string kn configuration file (default: ~/.config/kn/config.yaml) | ||
--kubeconfig string kubectl configuration file (default: ~/.kube/config) | ||
--log-http log http traffic | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kn channel](kn_channel.md) - Manage event channels (alias: channels) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ import ( | |
"k8s.io/apimachinery/pkg/runtime/schema" | ||
dynamicfake "k8s.io/client-go/dynamic/fake" | ||
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" | ||
"knative.dev/eventing/pkg/apis/messaging" | ||
messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether we should already go to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets keep it at v1beta1 to also support working with earlier eventing installs? |
||
servingv1 "knative.dev/serving/pkg/apis/serving/v1" | ||
|
||
"knative.dev/client/pkg/util" | ||
|
@@ -172,7 +174,7 @@ func createFakeKnDynamicClient(testNamespace string, objects ...runtime.Object) | |
scheme := runtime.NewScheme() | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1alpha1", Kind: "Service"}, &servingv1.Service{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Broker"}, &eventingv1beta1.Broker{}) | ||
|
||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "Channel"}, &messagingv1beta1.Channel{}) | ||
client := dynamicfake.NewSimpleDynamicClient(scheme, objects...) | ||
return NewKnDynamicClient(client, testNamespace) | ||
} | ||
|
@@ -236,3 +238,126 @@ func newSourceUnstructuredObj(name, apiVersion, kind string) *unstructured.Unstr | |
}, | ||
} | ||
} | ||
|
||
func newChannelCRDObj(name string) *unstructured.Unstructured { | ||
obj := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": crdGroup + "/" + crdVersion, | ||
"kind": crdKind, | ||
"metadata": map[string]interface{}{ | ||
"namespace": testNamespace, | ||
"name": name, | ||
}, | ||
}, | ||
} | ||
obj.SetLabels(labels.Set{messaging.SubscribableDuckVersionAnnotation: channelLabelValue}) | ||
return obj | ||
} | ||
|
||
func newChannelCRDObjWithSpec(name, group, version, kind string) *unstructured.Unstructured { | ||
obj := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": crdGroup + "/" + crdVersion, | ||
"kind": crdKind, | ||
"metadata": map[string]interface{}{ | ||
"namespace": testNamespace, | ||
"name": name, | ||
}, | ||
}, | ||
} | ||
|
||
obj.Object["spec"] = map[string]interface{}{ | ||
"group": group, | ||
"version": version, | ||
"names": map[string]interface{}{ | ||
"kind": kind, | ||
"plural": strings.ToLower(kind) + "s", | ||
}, | ||
} | ||
obj.SetLabels(labels.Set{messaging.SubscribableDuckVersionAnnotation: channelLabelValue}) | ||
return obj | ||
} | ||
|
||
func newChannelUnstructuredObj(name, apiVersion, kind string) *unstructured.Unstructured { | ||
return &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": apiVersion, | ||
"kind": kind, | ||
"metadata": map[string]interface{}{ | ||
"namespace": "current", | ||
"name": name, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"sink": map[string]interface{}{ | ||
"ref": map[string]interface{}{ | ||
"name": "foo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
func TestListChannelsTypes(t *testing.T) { | ||
t.Run("List channel types", func(t *testing.T) { | ||
client := createFakeKnDynamicClient( | ||
testNamespace, | ||
newChannelCRDObjWithSpec("Channel", "messaging.knative.dev", "v1beta1", "Channel"), | ||
newChannelCRDObjWithSpec("InMemoryChannel", "messaging.knative.dev", "v1beta1", "InMemoryChannel"), | ||
) | ||
|
||
uList, err := client.ListChannelsTypes() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, len(uList.Items), 1) | ||
assert.Equal(t, uList.Items[0].GetName(), "InMemoryChannel") | ||
}) | ||
|
||
t.Run("List channel types error", func(t *testing.T) { | ||
client := createFakeKnDynamicClient( | ||
testNamespace, | ||
newChannelCRDObj("foo"), | ||
) | ||
uList, err := client.ListChannelsTypes() | ||
assert.Check(t, err == nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, len(uList.Items), 1) | ||
assert.Equal(t, uList.Items[0].GetName(), "foo") | ||
}) | ||
} | ||
|
||
func TestListChannelsUsingGVKs(t *testing.T) { | ||
t.Run("No GVKs given", func(t *testing.T) { | ||
client := createFakeKnDynamicClient(testNamespace) | ||
assert.Check(t, client.RawClient() != nil) | ||
s, err := client.ListChannelsUsingGVKs(nil) | ||
assert.NilError(t, err) | ||
assert.Check(t, s == nil) | ||
}) | ||
|
||
t.Run("channel list with given GVKs", func(t *testing.T) { | ||
client := createFakeKnDynamicClient(testNamespace, | ||
newChannelCRDObjWithSpec("InMemoryChannel", "messaging.knative.dev", "v1beta1", "InMemoryChannel"), | ||
newChannelUnstructuredObj("i1", "messaging.knative.dev/v1beta1", "InMemoryChannel"), | ||
) | ||
assert.Check(t, client.RawClient() != nil) | ||
gv := schema.GroupVersion{"messaging.knative.dev", "v1beta1"} | ||
gvks := []schema.GroupVersionKind{gv.WithKind("InMemoryChannel")} | ||
|
||
s, err := client.ListChannelsUsingGVKs(&gvks) | ||
assert.NilError(t, err) | ||
assert.Check(t, s != nil) | ||
assert.Equal(t, len(s.Items), 1) | ||
assert.DeepEqual(t, s.GroupVersionKind(), schema.GroupVersionKind{messaging.GroupName, channelListVersion, channelListKind}) | ||
|
||
// withType | ||
s, err = client.ListChannelsUsingGVKs(&gvks, WithTypeFilter("InMemoryChannel")) | ||
assert.NilError(t, err) | ||
assert.Check(t, s != nil) | ||
assert.Equal(t, len(s.Items), 1) | ||
assert.DeepEqual(t, s.GroupVersionKind(), schema.GroupVersionKind{messaging.GroupName, channelListVersion, channelListKind}) | ||
}) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While just thinking about this, why not just
kn channel types
? I know this violates the schema, but it looks imo nice (same forkn source list-types
). At the end "list-types" is also not a verb but an artificial word construct.wdyt @navidshaikh @maximilien ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked that. I'd keep it
list-types
for this PR and change for source and channel together in a subsequent PR (keeping list-types as an alias for source). cc @Kaustubh-pande