-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add trigger update command #562
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## kn trigger update | ||
|
||
Update a trigger | ||
|
||
### Synopsis | ||
|
||
Update a trigger | ||
|
||
``` | ||
kn trigger update NAME --filter KEY=VALUE --sink SINK [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
|
||
# Update the filter which key is 'type' to value 'knative.dev.bar' in a trigger 'mytrigger' | ||
kn trigger update mytrigger --filter type=knative.dev.bar | ||
|
||
# Remove the filter which key is 'type' from a trigger 'mytrigger' | ||
kn trigger update mytrigger --filter type- | ||
|
||
# Update the sink of a trigger 'mytrigger' to 'svc:new-service' | ||
kn trigger update mytrigger --sink svc:new-service | ||
|
||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--broker string Name of the Broker which the trigger associates with. (default "default") | ||
--filter []string Key-value pair for exact CloudEvent attribute matching against incoming events, e.g type=dev.knative.foo | ||
-h, --help help for update | ||
-n, --namespace string Specify the namespace to operate in. | ||
-s, --sink string Addressable sink for events | ||
``` | ||
|
||
### 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 trigger](kn_trigger.md) - Trigger command group | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,14 @@ package v1alpha1 | |
|
||
import ( | ||
apis_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
kn_errors "knative.dev/client/pkg/errors" | ||
"knative.dev/client/pkg/util" | ||
"knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
"knative.dev/eventing/pkg/client/clientset/versioned/scheme" | ||
client_v1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
) | ||
|
||
const ( | ||
|
@@ -41,6 +43,8 @@ type KnEventingClient interface { | |
GetTrigger(name string) (*v1alpha1.Trigger, error) | ||
// ListTrigger returns list of trigger CRDs | ||
ListTriggers() (*v1alpha1.TriggerList, error) | ||
// UpdateTrigger is used to update an instance of trigger | ||
UpdateTrigger(trigger *v1alpha1.Trigger) error | ||
} | ||
|
||
// KnEventingClient is a combination of Sources client interface and namespace | ||
|
@@ -109,6 +113,15 @@ func (c *knEventingClient) ListTriggers() (*v1alpha1.TriggerList, error) { | |
return triggerListNew, nil | ||
} | ||
|
||
//CreateTrigger is used to create an instance of trigger | ||
func (c *knEventingClient) UpdateTrigger(trigger *v1alpha1.Trigger) error { | ||
trigger, err := c.client.Triggers(c.namespace).Update(trigger) | ||
if err != nil { | ||
return kn_errors.GetError(err) | ||
} | ||
return nil | ||
} | ||
|
||
// Return the client's namespace | ||
func (c *knEventingClient) Namespace() string { | ||
return c.namespace | ||
|
@@ -118,3 +131,70 @@ func (c *knEventingClient) Namespace() string { | |
func updateTriggerGvk(obj runtime.Object) error { | ||
return util.UpdateGroupVersionKindWithScheme(obj, v1alpha1.SchemeGroupVersion, scheme.Scheme) | ||
} | ||
|
||
// TriggerBuilder is for building the trigger | ||
type TriggerBuilder struct { | ||
trigger *v1alpha1.Trigger | ||
} | ||
|
||
// NewTriggerBuilder for building trigger object | ||
func NewTriggerBuilder(name string) *TriggerBuilder { | ||
return &TriggerBuilder{trigger: &v1alpha1.Trigger{ | ||
ObjectMeta: meta_v1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
}} | ||
} | ||
|
||
// NewTriggerBuilderFromExisting for building the object from existing Trigger object | ||
func NewTriggerBuilderFromExisting(tr *v1alpha1.Trigger) *TriggerBuilder { | ||
return &TriggerBuilder{trigger: tr.DeepCopy()} | ||
} | ||
|
||
// Broker to set the broker of trigger object | ||
func (b *TriggerBuilder) Broker(broker string) *TriggerBuilder { | ||
if broker != "" { | ||
b.trigger.Spec.Broker = broker | ||
} | ||
return b | ||
} | ||
|
||
// Filters to set the filters of trigger object | ||
func (b *TriggerBuilder) Filters(filters map[string]string) *TriggerBuilder { | ||
if filters != nil { | ||
triggerFilterAttributes := v1alpha1.TriggerFilterAttributes(filters) | ||
b.trigger.Spec.Filter = &v1alpha1.TriggerFilter{ | ||
Attributes: &triggerFilterAttributes, | ||
} | ||
} | ||
return b | ||
} | ||
|
||
// UpdateFilters to update the filters of trigger object | ||
func (b *TriggerBuilder) UpdateFilters(toUpdate map[string]string, toRemove []string) *TriggerBuilder { | ||
if b.trigger.Spec.Filter == nil { | ||
b.Filters(toUpdate) | ||
return b | ||
} | ||
|
||
existing := map[string]string(*b.trigger.Spec.Filter.Attributes) | ||
for key, value := range toUpdate { | ||
existing[key] = value | ||
} | ||
for _, key := range toRemove { | ||
delete(existing, key) | ||
} | ||
b.Filters(existing) | ||
return b | ||
} | ||
|
||
// Sink to set the subscriber of trigger object | ||
func (b *TriggerBuilder) Sink(sink *duckv1.Destination) *TriggerBuilder { | ||
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. Let's call it Subscriber like in the spec. |
||
b.trigger.Spec.Subscriber = sink | ||
return b | ||
} | ||
|
||
// Build to return an instance of trigger object | ||
func (b *TriggerBuilder) Build() *v1alpha1.Trigger { | ||
return b.trigger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wouldn't do any removal or change in the builder. Its about creating an immutable object, so would prefer to have just a
Filter()
method (as in my PR ;-) if you don't mind I would update that later.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.
Fine. I don't mind. Feel free to update it in a following PR.