diff --git a/go.mod b/go.mod index fabdc90..a1dd8b9 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/kubevela/kube-trigger go 1.19 require ( - cuelang.org/go v0.5.0-beta.2.0.20230130095913-d573e0c2f041 + cuelang.org/go v0.5.0-beta.5 github.com/crossplane/crossplane-runtime v0.19.2 github.com/google/go-cmp v0.5.9 - github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157 + github.com/kubevela/pkg v1.8.1-0.20230411071527-ac5fa22727f7 github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.0 @@ -35,7 +35,7 @@ require ( github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect - github.com/evanphx/json-patch v4.12.0+incompatible // indirect + github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect @@ -55,12 +55,12 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect - github.com/imdario/mergo v0.3.12 // indirect + github.com/imdario/mergo v0.3.13 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.6 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect @@ -90,7 +90,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.7.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.1.0 // indirect + golang.org/x/crypto v0.4.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect golang.org/x/sys v0.6.0 // indirect diff --git a/go.sum b/go.sum index f4295ae..c486652 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.100.2 h1:t9Iw5QH5v4XtlEQaCtUY7x6sCABps8sW0acw7e2WQ6Y= cloud.google.com/go v0.100.2/go.mod h1:4Xra9TjzAeYHrl5+oeLlzbM2k3mjVhZh4UqTZ//w99A= cloud.google.com/go/compute v0.1.0/go.mod h1:GAesmwr110a34z04OlxYkATPBEfVhkymfTBXtfbBFow= cloud.google.com/go/compute v1.7.0 h1:v/k9Eueb8aAJ0vZuxKMrgm6kPhCLZU9HxFU+AFDs9Uk= -cuelang.org/go v0.5.0-beta.2.0.20230130095913-d573e0c2f041 h1:00Lo6MPqzIiVHi37+p8o+GwzpB9t83YsUGlkXQ+bC7Q= -cuelang.org/go v0.5.0-beta.2.0.20230130095913-d573e0c2f041/go.mod h1:okjJBHFQFer+a41sAe2SaGm1glWS8oEb6CmJvn5Zdws= +cuelang.org/go v0.5.0-beta.5 h1:TAV4ZjXw2M6xf6jI8XyAAXCqWJ82Y0oxhlf9w3l544A= +cuelang.org/go v0.5.0-beta.5/go.mod h1:okjJBHFQFer+a41sAe2SaGm1glWS8oEb6CmJvn5Zdws= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= @@ -70,8 +70,8 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go. github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= -github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= -github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= +github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= @@ -173,8 +173,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 h1:BZHcxBETFHIdVyhyEfOvn/RdU/QGdLI4y34qQGjGWO0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -201,16 +201,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157 h1:01SXHJZjS2CYlPY1HpcmIkFCNko59sttqC7u/PYFt7s= -github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157/go.mod h1:A6f7lQwCOt0KRPnQz511QLB4JgzPpDXYUG7bY8LJkEE= +github.com/kubevela/pkg v1.8.1-0.20230411071527-ac5fa22727f7 h1:Mz6KLtuqfIdoeIsbStI2M8PYShlxAf18S36ZeK4sCmU= +github.com/kubevela/pkg v1.8.1-0.20230411071527-ac5fa22727f7/go.mod h1:dGT23SGBw16frh5ReEYMFraxjppkX6jPCltBgTeLUhE= github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM= -github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4= github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= @@ -354,8 +354,8 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -551,6 +551,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/filter/filter.go b/pkg/filter/filter.go index 012ac6b..60dd08d 100644 --- a/pkg/filter/filter.go +++ b/pkg/filter/filter.go @@ -19,14 +19,23 @@ package filter import ( "context" "fmt" + "strings" "cuelang.org/go/cue" + "cuelang.org/go/cue/ast" + "cuelang.org/go/cue/format" + "cuelang.org/go/cue/parser" + "cuelang.org/go/tools/fix" "github.com/kubevela/pkg/cue/cuex" ) // ApplyFilter applies the given filter to an object. func ApplyFilter(ctx context.Context, contextData map[string]interface{}, filter string) (bool, error) { - filterVal, err := cuex.CompileStringWithOptions(ctx, fmt.Sprintf("filter: %s", filter), cuex.WithExtraData("context", contextData)) + template, err := BuildFilterTemplate(filter) + if err != nil { + return false, err + } + filterVal, err := cuex.CompileStringWithOptions(ctx, template, cuex.WithExtraData("context", contextData)) if err != nil { return false, err } @@ -47,3 +56,47 @@ func ApplyFilter(ctx context.Context, contextData map[string]interface{}, filter } return resultBool, nil } + +// BuildFilterTemplate build filter template +func BuildFilterTemplate(filter string) (string, error) { + f, err := parser.ParseFile("-", filter) + if err != nil { + return "", err + } + n := fix.File(f) + if n.Imports == nil { + return fmt.Sprintf("filter: %s", filter), nil + } + var importDecls, contentDecls []ast.Decl + for _, decl := range n.Decls { + if importDecl, ok := decl.(*ast.ImportDecl); ok { + importDecls = append(importDecls, importDecl) + } else { + contentDecls = append(contentDecls, decl) + } + } + importString, err := encodeDeclsToString(importDecls) + if err != nil { + return "", err + } + contentString, err := encodeDeclsToString(contentDecls) + if err != nil { + return "", err + } + return fmt.Sprintf(filterTemplate, importString, contentString), nil +} + +func encodeDeclsToString(decls []ast.Decl) (string, error) { + bs, err := format.Node(&ast.File{Decls: decls}, format.Simplify()) + if err != nil { + return "", fmt.Errorf("failed to encode cue: %w", err) + } + return strings.TrimSpace(string(bs)), nil +} + +var filterTemplate = ` +%s +filter: { + %s +} +` diff --git a/pkg/filter/filter_test.go b/pkg/filter/filter_test.go new file mode 100644 index 0000000..e252c09 --- /dev/null +++ b/pkg/filter/filter_test.go @@ -0,0 +1,57 @@ +/* +Copyright 2022 The KubeVela Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package filter + +import ( + "testing" + + "github.com/kubevela/pkg/util/stringtools" + "github.com/stretchr/testify/assert" +) + +func TestBuildFilterTemplate(t *testing.T) { + testcases := map[string]struct { + src string + result string + }{ + "build filter with a single expression": { + src: "a == 1", + result: "filter: a == 1", + }, + "build filter with import declarations": { + src: ` + import "strings" + strings.Contains("abc", "a")`, + result: ` + import "strings" + filter: { + strings.Contains("abc", "a") + }`, + }, + } + + for name, testcase := range testcases { + t.Run(name, func(t *testing.T) { + result, err := BuildFilterTemplate(testcase.src) + assert.NoError(t, err) + assert.Equal(t, + stringtools.TrimLeadingIndent(testcase.result), + stringtools.TrimLeadingIndent(result), + ) + }) + } +} diff --git a/pkg/source/builtin/k8sresourcewatcher/controller/controller.go b/pkg/source/builtin/k8sresourcewatcher/controller/controller.go index 829775d..51fe144 100644 --- a/pkg/source/builtin/k8sresourcewatcher/controller/controller.go +++ b/pkg/source/builtin/k8sresourcewatcher/controller/controller.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/kubevela/pkg/multicluster" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -55,6 +56,7 @@ type Controller struct { sourceConf types.Config listenEvents map[types.EventType]bool controllerType string + cluster string } // Setup prepares controllers @@ -91,7 +93,7 @@ func Setup(ctx context.Context, cli dynamic.Interface, mapper meta.RESTMapper, c cache.Indexers{}, ) - c := newResourceController(logger, informer, ctrlConf.Kind) + c := newResourceController(ctx, logger, informer, ctrlConf.Kind) // precheck -> c.sourceConf = ctrlConf c.eventHandlers = eh @@ -107,13 +109,17 @@ func Setup(ctx context.Context, cli dynamic.Interface, mapper meta.RESTMapper, c return c } -func newResourceController(logger *logrus.Entry, informer cache.SharedIndexInformer, kind string) *Controller { +func newResourceController(ctx context.Context, logger *logrus.Entry, informer cache.SharedIndexInformer, kind string) *Controller { queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()) var newEvent types.InformerEvent var err error + cluster, _ := multicluster.ClusterFrom(ctx) informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - newEvent.Type = types.EventTypeCreate + newEvent.Event = types.Event{ + Type: types.EventTypeCreate, + Cluster: cluster, + } newEvent.EventObj = obj meta := utils.GetObjectMetaData(obj) logger.Tracef("received add event: %v %s/%s", kind, meta.GetName(), meta.GetNamespace()) @@ -122,7 +128,10 @@ func newResourceController(logger *logrus.Entry, informer cache.SharedIndexInfor } }, UpdateFunc: func(old, new interface{}) { - newEvent.Type = types.EventTypeUpdate + newEvent.Event = types.Event{ + Type: types.EventTypeUpdate, + Cluster: cluster, + } newEvent.EventObj = new meta := utils.GetObjectMetaData(new) logger.Tracef("received update event: %v %s/%s", kind, meta.GetName(), meta.GetNamespace()) @@ -131,7 +140,10 @@ func newResourceController(logger *logrus.Entry, informer cache.SharedIndexInfor } }, DeleteFunc: func(obj interface{}) { - newEvent.Type = types.EventTypeDelete + newEvent.Event = types.Event{ + Type: types.EventTypeDelete, + Cluster: cluster, + } newEvent.EventObj = obj meta := utils.GetObjectMetaData(obj) logger.Tracef("received delete event: %v %s/%s", kind, meta.GetName(), meta.GetNamespace()) @@ -145,6 +157,7 @@ func newResourceController(logger *logrus.Entry, informer cache.SharedIndexInfor logger: logger, informer: informer, queue: queue, + cluster: cluster, } } @@ -152,19 +165,20 @@ func newResourceController(logger *logrus.Entry, informer cache.SharedIndexInfor func (c *Controller) Run(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() defer c.queue.ShutDown() - - c.logger.Info("starting...") + c.logger = c.logger.WithFields(logrus.Fields{ + "apiVersion": c.sourceConf.APIVersion, + "kind": c.sourceConf.Kind, + "cluster": c.cluster, + }) + c.logger.Info("starting watch k8s resources...") serverStartTime = time.Now().Local() go c.informer.Run(stopCh) - if !cache.WaitForCacheSync(stopCh, c.HasSynced) { utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync")) return } - - c.logger.Info("synced and ready") - + c.logger.Info("resource watcher synced resources and ready for work") wait.Until(c.runWorker, time.Second, stopCh) } @@ -238,7 +252,7 @@ func (c *Controller) processItem(newEvent types.InformerEvent) error { } func (c *Controller) callEventHandler(obj metav1.Object, e types.Event) { - c.logger.Infof("%s event %s/%s happened, calling event handlers", e.Type, obj.GetName(), obj.GetNamespace()) + c.logger.Infof("%s event %s/%s/%s happened, calling event handlers", e.Type, e.Cluster, obj.GetNamespace(), obj.GetName()) for _, fn := range c.eventHandlers { err := fn(c.controllerType, e, obj) if err != nil { diff --git a/pkg/source/builtin/k8sresourcewatcher/k8s_resource_watcher.go b/pkg/source/builtin/k8sresourcewatcher/k8s_resource_watcher.go index e55c872..bda8bd1 100644 --- a/pkg/source/builtin/k8sresourcewatcher/k8s_resource_watcher.go +++ b/pkg/source/builtin/k8sresourcewatcher/k8s_resource_watcher.go @@ -113,7 +113,7 @@ func (w *K8sResourceWatcher) Init(properties *runtime.RawExtension, eh eventhand } w.eventHandlers[ctrlConf.Key()] = append(w.eventHandlers[ctrlConf.Key()], eh) - w.logger = logrus.WithField("source", v1alpha1.SourceTypeResourceWatcher) + w.logger = logrus.WithField("source-type", v1alpha1.SourceTypeResourceWatcher) w.logger.Debugf("initialized") return nil diff --git a/pkg/source/builtin/k8sresourcewatcher/types/types.go b/pkg/source/builtin/k8sresourcewatcher/types/types.go index 8dd4670..3eedefb 100644 --- a/pkg/source/builtin/k8sresourcewatcher/types/types.go +++ b/pkg/source/builtin/k8sresourcewatcher/types/types.go @@ -67,7 +67,8 @@ const ( // Event represent an event got from k8s api server type Event struct { - Type EventType `json:"type"` + Type EventType `json:"type"` + Cluster string `json:"cluster"` } // InformerEvent indicate the informerEvent