Skip to content

Commit

Permalink
update grouped binding naming (#647)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz authored Aug 29, 2024
1 parent e3c0a46 commit 22aa2b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions docs/src/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Temporary files have unique names to prevent collisions between queues and are d

Binging context is a JSON-array of structures with the following fields:

- `binding` — a string from the `name` or `group` parameters. If these parameters has not been set in the binding configuration, then strings "schedule" or "kubernetes" are used. For a hook executed at startup, this value is always "onStartup".
- `binding` — a string from the `name` parameter. If this parameter has not been set in the binding configuration, then strings "schedule" or "kubernetes" are used. For a hook executed at startup, this value is always "onStartup".
- `type` — "Schedule" for `schedule` bindings. "Synchronization" or "Event" for `kubernetes` bindings. "Group" if `group` is defined.

The hook receives "Event"-type binding context on Kubernetes event and it contains more fields:
Expand Down Expand Up @@ -708,8 +708,8 @@ Adjacent tasks for `kubernetes` and `schedule` bindings with the same `group` an

`group` parameter is compatible with `includeSnapshotsFrom` parameter. `includeSnapshotsFrom` can be used to include additional snapshots into binding context.

Binding context for group contains:
- `binding` field with the group name.
Binding context for a group contains:
- `binding` field with the original binding name or, if the name field wasn't set in the binding configuration, then strings "schedule" or "kubernetes" are used.
- `type` field with the value "Group".
- `snapshots` field if there is at least one `kubernetes` binding in the group or `includeSnapshotsFrom` is not empty.

Expand Down Expand Up @@ -752,12 +752,12 @@ Grouped bindings is used when only the occurrence of an event is important. So,
- Data field is changed in ConfigMap/settings-for-my-hook.
- Every 3 hours.

Binding context for these events will be the same:
Binding contexts for these events will be pretty the same, except for the `binding` field, as it will be equal to the corresponding `name` field of the binding:

```yaml
[
{
"binding": "pods",
"binding": "monitor-pods",
"type": "Group",
"snapshots": {
"monitor-pods": [
Expand Down
1 change: 0 additions & 1 deletion pkg/hook/binding_context/binding_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (bc BindingContext) MapV1() map[string]interface{} {

// Group is always has "type: Group", even for Synchronization.
if bc.Metadata.Group != "" {
res["binding"] = bc.Metadata.Group
res["type"] = "Group"
return res
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/hook/binding_context/binding_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
{`.[0] | length`, `3`}, // Only 3 fields
{`.[0].snapshots | has("monitor_pods")`, `true`},
{`.[0].snapshots."monitor_pods" | length`, `1`},
{`.[0].binding`, `"pods"`},
{`.[0].binding`, `"monitor_pods"`},
{`.[0].type`, `"Group"`},

// JSON dump should has only 4 fields: binding, type, watchEvent and object.
Expand Down Expand Up @@ -311,7 +311,7 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {

g.Expect(bcList[0]).Should(HaveLen(3))
g.Expect(bcList[0]).Should(HaveKey("binding"))
g.Expect(bcList[0]["binding"]).Should(Equal("pods"))
g.Expect(bcList[0]["binding"]).Should(Equal("monitor_config_maps"))
g.Expect(bcList[0]).Should(HaveKey("type"))
g.Expect(bcList[0]["type"]).Should(Equal("Group"))
g.Expect(bcList[0]).Should(HaveKey("snapshots"))
Expand All @@ -329,7 +329,7 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {

// grouped binding context contains binding==group, type and snapshots
{`.[0] | length`, `3`}, // Only 3 fields
{`.[0].binding`, `"pods"`},
{`.[0].binding`, `"monitor_config_maps"`},
{`.[0].type`, `"Group"`},
{`.[0].snapshots | has("monitor_config_maps")`, `true`},
{`.[0].snapshots."monitor_config_maps" | length`, `1`},
Expand Down

0 comments on commit 22aa2b0

Please sign in to comment.