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

Chore: refactor filter and action with cuex #22

Merged
merged 2 commits into from
Feb 1, 2023

Conversation

FogDong
Copy link
Member

@FogDong FogDong commented Jan 30, 2023

Signed-off-by: FogDong dongtianxin.tx@alibaba-inc.com

Description of your changes

This PR refactors the filter and action with cuex.

The trigger is as below:

# A trigger is a group of Source, Filters, and Actions.
# You can add multiple triggers.
triggers:
  - source:
      type: resource-watcher
      properties:
        # We are interested in ConfigMap events.
        apiVersion: "v1"
        kind: ConfigMap
        namespace: default
        # Only watch update event.
        events:
          - update
    filter: |
      context: data: metadata: name: =~"this-will-trigger-update-.*"
    action:
      # Bump Application Revision to update Application.
      type: bump-application-revision
      properties:
        namespace: default
        # Select Applications to bump using labels.
        matchingLabels:
          my-label: my-value

I have:

  • Read and followed KubeVela's contribution process.
  • Add related tests.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Special notes for your reviewer

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
.gitignore Show resolved Hide resolved
pkg/cmd/cmd.go Outdated Show resolved Hide resolved

// ApplyFilter applies the given filter to an object.
func ApplyFilter(ctx context.Context, contextData map[string]interface{}, filter string) (bool, error) {
contextByte, err := json.Marshal(contextData)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can probably make some common functions in kubevela/pkg which accept template and contextData as input and generate cue.Value. It is commonly used across trigger/workflowstep/component/trait, etc.

pkg/filter/filter.go Outdated Show resolved Hide resolved
pkg/filter/filter.go Show resolved Hide resolved
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
@FogDong FogDong merged commit 500d545 into kubevela:main Feb 1, 2023
semmet95 pushed a commit to semmet95/kube-trigger that referenced this pull request May 10, 2023
* Chore: refactor filter and action with cuex

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

* resolve comments

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

---------

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: Amit Singh <singhamitch@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants