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

fix shell_lib regarding grouping #665

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion frameworks/shell/hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function hook::_get_possible_handler_names() {
esac
;;
"Group")
echo __on_group::${BINDING_CONTEXT_CURRENT_BINDING}
BINDING_CONTEXT_GROUP_NAME=$(context::jq -er '.groupName')
echo __on_group::${BINDING_CONTEXT_GROUP_NAME}
;;
"Schedule")
echo __on_schedule::${BINDING_CONTEXT_CURRENT_BINDING}
Expand Down
1 change: 1 addition & 0 deletions pkg/hook/binding_context/binding_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (bc BindingContext) MapV1() map[string]interface{} {
// Group is always has "type: Group", even for Synchronization.
if bc.Metadata.Group != "" {
res["type"] = "Group"
res["groupName"] = bc.Metadata.Group
return res
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/hook/binding_context/binding_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,19 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
g.Expect(bcList[0]).Should(HaveKey("binding"))
g.Expect(bcList[0]).Should(HaveKey("snapshots"))
g.Expect(bcList[0]).Should(HaveKey("type"))
g.Expect(bcList[0]).Should(HaveKey("groupName"))
g.Expect(bcList[0]).ShouldNot(HaveKey("objects"))
},
[][]string{
{`. | length`, `2`},

// grouped binding context contains binding, type and snapshots
{`.[0] | length`, `3`}, // Only 3 fields
// grouped binding context contains binding, type, snapshots and groupName
{`.[0] | length`, `4`}, // Only 4 fields
{`.[0].snapshots | has("monitor_pods")`, `true`},
{`.[0].snapshots."monitor_pods" | length`, `1`},
{`.[0].binding`, `"monitor_pods"`},
{`.[0].type`, `"Group"`},
{`.[0].groupName`, `"pods"`},

// JSON dump should has only 4 fields: binding, type, watchEvent and object.
{`.[1] | length`, `4`},
Expand Down Expand Up @@ -309,11 +311,12 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
func() {
g.Expect(bcList).Should(HaveLen(2))

g.Expect(bcList[0]).Should(HaveLen(3))
g.Expect(bcList[0]).Should(HaveLen(4))
g.Expect(bcList[0]).Should(HaveKey("binding"))
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]["groupName"]).Should(Equal("pods"))
g.Expect(bcList[0]).Should(HaveKey("snapshots"))
g.Expect(bcList[0]["snapshots"]).Should(HaveLen(1))

Expand All @@ -327,8 +330,8 @@ func Test_ConvertBindingContextList_v1(t *testing.T) {
[][]string{
{`. | length`, `2`},

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