Skip to content

Commit

Permalink
Merge branch 'fix/example-manager-and-instructions' of https://github…
Browse files Browse the repository at this point in the history
….com/semmet95/kube-trigger into fix/example-manager-and-instructions
  • Loading branch information
semmet95 committed May 10, 2023
2 parents 0303202 + 1f111d5 commit 0a617ff
Show file tree
Hide file tree
Showing 8 changed files with 748 additions and 0 deletions.
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
[![TODOs](https://img.shields.io/endpoint?url=https://api.tickgit.com/badge?repo=github.com/kubevela/kube-trigger)](https://www.tickgit.com/browse?repo=github.com/kubevela/kube-trigger)
[![Go Checks](https://github.com/kubevela/kube-trigger/actions/workflows/go-checks.yaml/badge.svg?branch=main)](https://github.com/kubevela/kube-trigger/actions/workflows/go-checks.yaml)
[![Unit Tests](https://github.com/kubevela/kube-trigger/actions/workflows/unit-test.yaml/badge.svg)](https://github.com/kubevela/kube-trigger/actions/workflows/unit-test.yaml)
[![codecov](https://codecov.io/gh/kubevela/kube-trigger/branch/main/graph/badge.svg)](https://codecov.io/gh/kubevela/kube-trigger)
![Docker Pulls](https://img.shields.io/docker/pulls/oamdev/kube-trigger)
[![TODOs](https://img.shields.io/endpoint?url=https://api.tickgit.com/badge?repo=github.com/kubevela/kube-trigger)](https://www.tickgit.com/browse?repo=github.com/kubevela/kube-trigger)
[![Go Checks](https://github.com/kubevela/kube-trigger/actions/workflows/go-checks.yaml/badge.svg?branch=main)](https://github.com/kubevela/kube-trigger/actions/workflows/go-checks.yaml)
[![Unit Tests](https://github.com/kubevela/kube-trigger/actions/workflows/unit-test.yaml/badge.svg)](https://github.com/kubevela/kube-trigger/actions/workflows/unit-test.yaml)

kube-trigger is a workflow based trigger that combines listeners, filter events and action triggers in a programmable way with CUElang.
kube-trigger is a workflow based trigger that combines listeners, filter events and action triggers in a programmable way with CUElang.

![kube-trigger overview](docs/img/overview.svg)
Expand Down Expand Up @@ -40,6 +46,15 @@ source:
- update
```
```yaml
source:
type: resource-watcher
properties:
apiVersion: apps/v1
kind: Deployment
events:
- update
```
```yaml
source:
type: resource-watcher
Expand Down Expand Up @@ -257,6 +272,33 @@ triggers:
fromLabel: "watch-this"
```

See [examples](https://github.com/kubevela/kube-trigger/tree/main/examples) directory for more instructions.
And the trigger config file will look like:

```yaml
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.
nameSelector:
fromLabel: "watch-this"
```

See [examples](https://github.com/kubevela/kube-trigger/tree/main/examples) directory for more instructions.

## Usage
Expand Down Expand Up @@ -309,18 +351,27 @@ An example config file looks like this:
```yaml
# A trigger is a group of Source, Filters, and Actions.
# You can add multiple triggers.
triggers:
# A trigger is a group of Source, Filters, and Actions.
# You can add multiple triggers.
triggers:
- source:
type: resource-watcher
type: resource-watcher
properties:
# We are interested in ConfigMap events.
apiVersion: "v1"
apiVersion: "v1"
kind: ConfigMap
namespace: default
# Only watch update event.
events:
- update
# Filter the events above.
filter: |
context: data: metadata: name: =~"this-will-trigger-update-.*"
action:
# Filter the events above.
filter: |
context: data: metadata: name: =~"this-will-trigger-update-.*"
action:
Expand All @@ -331,6 +382,12 @@ triggers:
# Select Applications to bump using labels.
nameSelector:
fromLabel: "watch-this"
type: bump-application-revision
properties:
namespace: default
# Select Applications to bump using labels.
nameSelector:
fromLabel: "watch-this"
```

Let's assume your config file is `config.yaml`, to run kube-trigger:
Expand All @@ -345,16 +402,21 @@ We have one CRD called *TriggerService*. *TriggerInstance* is what creates a kub

```yaml
# You can find this file in config/samples/standard_v1alpha1_triggerservice.yaml
# You can find this file in config/samples/standard_v1alpha1_triggerservice.yaml
apiVersion: standard.oam.dev/v1alpha1
kind: TriggerService
kind: TriggerService
metadata:
name: kubetrigger-sample-config
namespace: default
spec:
selector:
instance: kubetrigger-sample
triggers:
instance: kubetrigger-sample
triggers:
- source:
type: resource-watcher
type: resource-watcher
properties:
apiVersion: "v1"
Expand All @@ -371,6 +433,15 @@ spec:
# Select Applications to bump using labels.
nameSelector:
fromLabel: "watch-this"
filter: |
context: data: metadata: name: =~"this-will-trigger-update-.*"
action:
type: bump-application-revision
properties:
namespace: default
# Select Applications to bump using labels.
nameSelector:
fromLabel: "watch-this"
```

## Advanced kube-trigger Configuration
Expand Down Expand Up @@ -530,3 +601,62 @@ Observability
- [ ] Remove cache informer, make it with no catch but list watch events with unique queue.



## Roadmap

### v0.0.1-alpha.x

- [x] Basic build infrastructure
- [x] Complete a basic proof-of-concept sample
- [x] linters, license checker
- [x] GitHub Actions
- [x] Rate-limited worker
- [x] Make the configuration as CRD, launch new process/pod for new watcher
- [x] Notification for more than one app: selector from compose of Namespace; Labels; Name
- [x] Refine README, quick starts
- [x] Refactor CRD according to [#2](https://github.com/kubevela/kube-trigger/issues/2)

### v0.0.1-beta.x

Code enhancements

- [ ] Add missing unit tests
- [ ] Add missing integration tests

### v0.0.x

User experience

- [ ] Refine health status of CRs
- [ ] Make it run as Addon, build component definition, and examples
- [ ] Kubernetes dynamic admission control with validation webhook
- [ ] Auto-generate usage docs of Sources, Filters, and Actions from CUE markers
- [ ] Show available Sources, Filters, and Actions in cli

### v0.1.x

Webhook support

- [ ] Contribution Guide
- [ ] New Action: webhook
- [ ] New Source: webhook

### v0.2.x

Observability

- [ ] New Action: execute VelaQL(CUE and K8s operations)
- [ ] New Source: cron
- [ ] New Action: notifications(email, dingtalk, slack, telegram)
- [ ] New Action: log (loki, clickhouse)

### Planned for later releases

- [ ] Allow user set custom RBAC for each TriggerInstance
- [ ] New Action: workflow-run
- [ ] New Action: execute-command
- [ ] New Action: metric (prometheus)
- [ ] Refine controller logic
- [ ] Remove cache informer, make it with no catch but list watch events with unique queue.


3 changes: 3 additions & 0 deletions examples/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
labels:
"watch-this": "this-will-be-updated-1"
"workflowrun.oam.dev/name": "imme-reconcile"
labels:
"watch-this": "this-will-be-updated-1"
"workflowrun.oam.dev/name": "imme-reconcile"
data:
content: EDIT_ME_AFTER_APPLY

Expand Down
43 changes: 43 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module github.com/kubevela/kube-trigger

go 1.19
go 1.19

require (
Expand All @@ -13,6 +14,8 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
golang.org/x/time v0.3.0
Expand All @@ -28,12 +31,17 @@ require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -49,14 +57,21 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
Expand Down Expand Up @@ -129,9 +144,12 @@ require (
google.golang.org/genproto v0.0.0-20220628213854-d9e0b6570c03 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.3 // indirect
Expand All @@ -140,11 +158,22 @@ require (
k8s.io/apiextensions-apiserver v0.26.3 // indirect
k8s.io/apiserver v0.26.3 // indirect
k8s.io/component-base v0.26.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.3 // indirect
k8s.io/apiserver v0.26.3 // indirect
k8s.io/component-base v0.26.3 // indirect
k8s.io/apiextensions-apiserver v0.26.3 // indirect
k8s.io/apiserver v0.26.3 // indirect
k8s.io/component-base v0.26.3 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/kms v0.26.3 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/kms v0.26.3 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/kms v0.26.3 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/kms v0.26.3 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
open-cluster-management.io/api v0.7.0 // indirect
sigs.k8s.io/apiserver-network-proxy v0.0.30 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36 // indirect
Expand All @@ -153,6 +182,12 @@ require (
sigs.k8s.io/apiserver-runtime v1.1.2-0.20221118041430-0a6394f6dda3 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36 // indirect
sigs.k8s.io/apiserver-runtime v1.1.2-0.20221118041430-0a6394f6dda3 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36 // indirect
sigs.k8s.io/apiserver-runtime v1.1.2-0.20221118041430-0a6394f6dda3 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

Expand All @@ -164,3 +199,11 @@ replace (
cloud.google.com/go => cloud.google.com/go v0.100.2
sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36
)
replace (
cloud.google.com/go => cloud.google.com/go v0.100.2
sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36
)
replace (
cloud.google.com/go => cloud.google.com/go v0.100.2
sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.36
)
Loading

0 comments on commit 0a617ff

Please sign in to comment.