Skip to content
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

feature(source binding): Support for Sink Binding as source #625

Merged
merged 8 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions docs/cmd/kn_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kn source [flags]

* [kn](kn.md) - Knative client
* [kn source apiserver](kn_source_apiserver.md) - Kubernetes API Server Event Source command group
* [kn source binding](kn_source_binding.md) - Sink binding command group
* [kn source cronjob](kn_source_cronjob.md) - CronJob source command group
* [kn source list-types](kn_source_list-types.md) - List available source types

35 changes: 35 additions & 0 deletions docs/cmd/kn_source_binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## kn source binding

Sink binding command group

### Synopsis

Sink binding command group

```
kn source binding [flags]
```

### Options

```
-h, --help help for binding
```

### Options inherited from parent commands

```
--config string kn config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source](kn_source.md) - Event source command group
* [kn source binding create](kn_source_binding_create.md) - Create a sink binding.
* [kn source binding delete](kn_source_binding_delete.md) - Delete a sink binding.
* [kn source binding describe](kn_source_binding_describe.md) - Describe a sink binding.
* [kn source binding list](kn_source_binding_list.md) - List sink bindings.
* [kn source binding update](kn_source_binding_update.md) - Update a sink binding.

42 changes: 42 additions & 0 deletions docs/cmd/kn_source_binding_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## kn source binding create

Create a sink binding.

### Synopsis

Create a sink binding.

```
kn source binding create NAME --subject SCHEDULE --sink SINK --ce-override KEY=VALUE [flags]
```

### Examples

```

# Create a sink binding which connects a deployment 'myapp' with a Knative service 'mysvc'
kn source binding create my-binding --subject Deployemnt:apps/v1:myapp --sink svc:mysvc
```

### Options

```
--ce-override stringArray Cloud Event overrides to apply before sending event to sink in the format '--ce-override key=value'. --ce-override can be provide multiple times
-h, --help help for create
-n, --namespace string Specify the namespace to operate in.
-s, --sink string Addressable sink for events
--subject string Subject which emits cloud events. This argument takes format kind:apiVersion:name for named resources or kind:apiVersion:labelKey1=value1,labelKey2=value2 for matching via a label selector
```

### Options inherited from parent commands

```
--config string kn config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source binding](kn_source_binding.md) - Sink binding command group

39 changes: 39 additions & 0 deletions docs/cmd/kn_source_binding_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## kn source binding delete

Delete a sink binding.

### Synopsis

Delete a sink binding.

```
kn source binding delete NAME [flags]
```

### Examples

```

# Delete a sink binding with name 'my-binding'
kn source binding delete my-binding
```

### Options

```
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
```

### Options inherited from parent commands

```
--config string kn config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source binding](kn_source_binding.md) - Sink binding command group

40 changes: 40 additions & 0 deletions docs/cmd/kn_source_binding_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## kn source binding describe

Describe a sink binding.

### Synopsis

Describe a sink binding.

```
kn source binding describe NAME [flags]
```

### Examples

```

# Describe a sink binding with name 'mysinkbinding'
kn source binding describe mysinkbinding
```

### Options

```
-h, --help help for describe
-n, --namespace string Specify the namespace to operate in.
-v, --verbose More output.
```

### Options inherited from parent commands

```
--config string kn config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source binding](kn_source_binding.md) - Sink binding command group

44 changes: 44 additions & 0 deletions docs/cmd/kn_source_binding_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## kn source binding list

List sink bindings.

### Synopsis

List sink bindings.

```
kn source binding list [flags]
```

### Examples

```

# List all sink binding in YAML format
kn source binding list -o yaml
```

### Options

```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
--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
-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 config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source binding](kn_source_binding.md) - Sink binding command group

42 changes: 42 additions & 0 deletions docs/cmd/kn_source_binding_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## kn source binding update

Update a sink binding.

### Synopsis

Update a sink binding.

```
kn source binding update NAME --subject SCHEDULE --sink SINK --ce-override OVERRIDE [flags]
```

### Examples

```

# Update the subject of a sink binding 'my-binding' to a new cronjob with label selector 'app=ping'
kn source binding update my-binding --subject cronjob:batch/v1beta1:app=ping"
```

### Options

```
--ce-override stringArray Cloud Event overrides to apply before sending event to sink in the format '--ce-override key=value'. --ce-override can be provide multiple times
-h, --help help for update
-n, --namespace string Specify the namespace to operate in.
-s, --sink string Addressable sink for events
--subject string Subject which emits cloud events. This argument takes format kind:apiVersion:name for named resources or kind:apiVersion:labelKey1=value1,labelKey2=value2 for matching via a label selector
```

### Options inherited from parent commands

```
--config string kn config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn source binding](kn_source_binding.md) - Sink binding command group

4 changes: 2 additions & 2 deletions docs/cmd/kn_source_cronjob_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ kn source cronjob describe NAME [flags]

```

# Describe a cronjob source with name 'my-cron-trigger'
kn source cronjob describe my-cron-trigger
# Describe a cronjob source with name 'mycronjob'
kn source cronjob describe mycronjob
```

### Options
Expand Down
5 changes: 3 additions & 2 deletions pkg/eventing/legacysources/v1alpha1/apiserver_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ func newAPIServerSource(name, resource string) *v1alpha1.ApiServerSource {
b := NewAPIServerSourceBuilder(name).ServiceAccount("testsa").Mode("Ref")
b.Sink(&v1beta1.Destination{
Ref: &v1.ObjectReference{
Kind: "Service",
Name: "foosvc",
Kind: "Service",
Name: "foosvc",
Namespace: "default",
}})

if resource != "" {
Expand Down
5 changes: 3 additions & 2 deletions pkg/eventing/legacysources/v1alpha1/cronjob_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ func newCronJobSource(name string, sink string) *v1alpha1.CronJobSource {
b.Sink(
&v1beta1.Destination{
Ref: &v1.ObjectReference{
Kind: "Service",
Name: sink,
Kind: "Service",
Name: sink,
Namespace: "default",
},
})
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/eventing/v1alpha1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import (
"knative.dev/client/pkg/util"
)

const (
nameFieldKey = "metadata.name"
)

// KnEventingClient to Eventing Sources. All methods are relative to the
// namespace specified during construction
type KnEventingClient interface {
Expand Down
3 changes: 2 additions & 1 deletion pkg/eventing/v1alpha1/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package v1alpha1
import (
"testing"

"knative.dev/client/pkg/util/mock"
"knative.dev/eventing/pkg/apis/eventing/v1alpha1"

"knative.dev/client/pkg/util/mock"
)

// MockKnEventingClient is a combine of test object and recorder
Expand Down
6 changes: 3 additions & 3 deletions pkg/kn/commands/flags/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func (i *SinkFlags) ResolveSink(knclient kn_dynamic.KnDynamicClient, namespace s
return nil, err
}

return &duckv1beta1.Destination{
destination := &duckv1beta1.Destination{
Ref: &v1.ObjectReference{
Kind: obj.GetKind(),
APIVersion: obj.GetAPIVersion(),
Name: obj.GetName(),
Namespace: namespace,
},
}, nil

}
return destination, nil
}

// parseSink takes the string given by the user into the prefix and the name of
Expand Down
11 changes: 5 additions & 6 deletions pkg/kn/commands/flags/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,19 @@ func TestResolve(t *testing.T) {
{"svc:mysvc", &duckv1beta1.Destination{
Ref: &v1.ObjectReference{Kind: "Service",
APIVersion: "serving.knative.dev/v1alpha1",
Name: "mysvc",
Namespace: "default"}}, ""},
Namespace: "default",
Name: "mysvc"}}, ""},
{"service:mysvc", &duckv1beta1.Destination{
Ref: &v1.ObjectReference{Kind: "Service",
APIVersion: "serving.knative.dev/v1alpha1",
Name: "mysvc",
Namespace: "default"}}, ""},
Namespace: "default",
Name: "mysvc"}}, ""},
{"svc:absent", nil, "\"absent\" not found"},
{"broker:default", &duckv1beta1.Destination{
Ref: &v1.ObjectReference{Kind: "Broker",
APIVersion: "eventing.knative.dev/v1alpha1",
Name: "default",
Namespace: "default",
}}, ""},
Name: "default"}}, ""},
{"http://target.example.com", &duckv1beta1.Destination{
URI: targetExampleCom,
}, ""},
Expand Down
2 changes: 0 additions & 2 deletions pkg/kn/commands/human_readable_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func (f *HumanPrintFlags) EnsureWithNamespace() {
f.WithNamespace = true
}

// Private functions

// conditionsValue returns the True conditions count among total conditions
func ConditionsValue(conditions duckv1.Conditions) string {
var ok int
Expand Down
3 changes: 3 additions & 0 deletions pkg/kn/commands/source/apiserver/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func printSource(source *v1alpha1.ApiServerSource, options hprinters.PrintOption
resources = append(resources, fmt.Sprintf("%s:%s:%s", resource.Kind, resource.APIVersion, strconv.FormatBool(resource.Controller)))
}

// Not moving to SinkToString() as it references v1beta1.Destination
// This source is going to be moved/removed soon to v1, so no need to move
// it now
var sink string
if source.Spec.Sink != nil {
if source.Spec.Sink.Ref != nil {
Expand Down
Loading