Skip to content

Commit

Permalink
Add flux executor plugin with GitHub support
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Aug 1, 2023
1 parent e344aa4 commit 67c8c24
Show file tree
Hide file tree
Showing 35 changed files with 1,624 additions and 115 deletions.
32 changes: 32 additions & 0 deletions .goreleaser.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ builds:
goarm:
- 7

- id: flux
main: cmd/executor/flux/main.go
binary: executor_flux_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: gh
main: cmd/executor/gh/main.go
binary: executor_gh_{{ .Os }}_{{ .Arch }}
Expand Down Expand Up @@ -122,6 +138,22 @@ builds:
goarm:
- 7

- id: github-events
main: cmd/source/github-events/main.go
binary: source_github-events_{{ .Os }}_{{ .Arch }}

no_unique_dist_dir: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
goarm:
- 7

- id: keptn
main: cmd/source/keptn/main.go
binary: source_keptn_{{ .Os }}_{{ .Arch }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gen-grpc-resources:
# Generate plugins YAML index files for both all plugins and end-user ones.
gen-plugins-index: build-plugins
go run ./hack/gen-plugin-index.go -output-path ./plugins-dev-index.yaml
go run ./hack/gen-plugin-index.go -output-path ./plugins-index.yaml -plugin-name-filter 'kubectl|helm|kubernetes|prometheus|x|doctor|keptn'
go run ./hack/gen-plugin-index.go -output-path ./plugins-index.yaml -plugin-name-filter 'kubectl|helm|kubernetes|prometheus|exec|doctor|keptn|github-events'

gen-docs-cli:
rm -f ./cmd/cli/docs/*
Expand Down
14 changes: 7 additions & 7 deletions cmd/botkube-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v53/github"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
segment "github.com/segmentio/analytics-go"
Expand All @@ -29,6 +29,7 @@ import (
"github.com/kubeshop/botkube/internal/config/reloader"
"github.com/kubeshop/botkube/internal/config/remote"
"github.com/kubeshop/botkube/internal/heartbeat"
"github.com/kubeshop/botkube/internal/httpx"
"github.com/kubeshop/botkube/internal/insights"
"github.com/kubeshop/botkube/internal/kubex"
"github.com/kubeshop/botkube/internal/lifecycle"
Expand All @@ -43,7 +44,6 @@ import (
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/controller"
"github.com/kubeshop/botkube/pkg/execute"
"github.com/kubeshop/botkube/pkg/httpsrv"
"github.com/kubeshop/botkube/pkg/notifier"
"github.com/kubeshop/botkube/pkg/sink"
"github.com/kubeshop/botkube/pkg/version"
Expand Down Expand Up @@ -367,7 +367,7 @@ func run(ctx context.Context) error {

actionProvider := action.NewProvider(logger.WithField(componentLogFieldKey, "Action Provider"), conf.Actions, executorFactory)

sourcePluginDispatcher := source.NewDispatcher(logger, bots, sinkNotifiers, pluginManager, actionProvider, reporter, auditReporter, kubeConfig)
sourcePluginDispatcher := source.NewDispatcher(logger, conf.Settings.ClusterName, bots, sinkNotifiers, pluginManager, actionProvider, reporter, auditReporter, kubeConfig)
scheduler := source.NewScheduler(logger, conf, sourcePluginDispatcher)
err = scheduler.Start(ctx)
if err != nil {
Expand Down Expand Up @@ -421,18 +421,18 @@ func run(ctx context.Context) error {
return nil
}

func newMetricsServer(log logrus.FieldLogger, metricsPort string) *httpsrv.Server {
func newMetricsServer(log logrus.FieldLogger, metricsPort string) *httpx.Server {
addr := fmt.Sprintf(":%s", metricsPort)
router := mux.NewRouter()
router.Handle("/metrics", promhttp.Handler())
return httpsrv.New(log, addr, router)
return httpx.NewServer(log, addr, router)
}

func newHealthServer(log logrus.FieldLogger, port string, healthChecker *healthChecker) *httpsrv.Server {
func newHealthServer(log logrus.FieldLogger, port string, healthChecker *healthChecker) *httpx.Server {
addr := fmt.Sprintf(":%s", port)
router := mux.NewRouter()
router.Handle(healthEndpointName, healthChecker)
return httpsrv.New(log, addr, router)
return httpx.NewServer(log, addr, router)
}

type healthChecker struct {
Expand Down
27 changes: 27 additions & 0 deletions cmd/executor/flux/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"context"
"time"

"github.com/allegro/bigcache/v3"
"github.com/hashicorp/go-plugin"

"github.com/kubeshop/botkube/internal/executor/flux"
"github.com/kubeshop/botkube/internal/loggerx"
"github.com/kubeshop/botkube/pkg/api/executor"
)

// version is set via ldflags by GoReleaser.
var version = "dev"

func main() {
cache, err := bigcache.New(context.Background(), bigcache.DefaultConfig(30*time.Minute))
loggerx.ExitOnError(err, "while creating big cache")

executor.Serve(map[string]plugin.Plugin{
flux.PluginName: &executor.Plugin{
Executor: flux.NewExecutor(cache, version),
},
})
}
77 changes: 51 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ module github.com/kubeshop/botkube
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/DanielTitkov/go-adaptive-cards v0.2.2
github.com/Delta456/box-cli-maker/v2 v2.3.0
github.com/MakeNowJust/heredoc v1.0.0
github.com/PullRequestInc/go-gpt3 v1.1.15
github.com/alexflint/go-arg v1.4.3
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/avast/retry-go/v4 v4.3.3
github.com/aws/aws-sdk-go v1.44.122
github.com/bradleyfalzon/ghinstallation/v2 v2.6.0
github.com/briandowns/spinner v1.23.0
github.com/bwmarrin/discordgo v0.25.0
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/log v0.2.2
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.13.0
github.com/fluxcd/kustomize-controller/api v1.0.1
github.com/go-playground/locales v0.14.0
github.com/go-playground/universal-translator v0.18.0
github.com/go-playground/validator/v10 v10.11.0
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
github.com/google/go-github/v44 v44.1.0
github.com/google/go-github/v53 v53.2.0
github.com/google/uuid v1.3.0
github.com/gookit/color v1.5.2
github.com/gorilla/mux v1.8.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/hashicorp/go-getter v1.7.1
github.com/hashicorp/go-hclog v1.3.1
github.com/hashicorp/go-multierror v1.1.1
Expand Down Expand Up @@ -57,53 +62,60 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0
go.szostok.io/version v1.2.0
golang.org/x/exp v0.0.0-20230307190834-24139beb5833
golang.org/x/oauth2 v0.5.0
golang.org/x/oauth2 v0.10.0
golang.org/x/sync v0.2.0
golang.org/x/text v0.9.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
golang.org/x/text v0.11.0
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.4.0
helm.sh/helm/v3 v3.12.1
k8s.io/api v0.27.2
k8s.io/apimachinery v0.27.2
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
k8s.io/cli-runtime v0.27.2
k8s.io/client-go v0.27.2
k8s.io/client-go v0.27.3
k8s.io/klog/v2 v2.90.1
k8s.io/kubectl v0.27.2
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
sigs.k8s.io/controller-runtime v0.13.1
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/yaml v1.3.0
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.29.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/allegro/bigcache/v3 v3.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/bombsimon/logrusr/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/containerd v1.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/docker/cli v20.10.21+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v20.10.24+incompatible // indirect
Expand All @@ -112,12 +124,17 @@ require (
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
github.com/eko/gocache/lib/v4 v4.1.3 // indirect
github.com/eko/gocache/store/bigcache/v4 v4.1.2 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fluxcd/pkg/apis/kustomize v1.1.1 // indirect
github.com/fluxcd/pkg/apis/meta v1.1.1 // indirect
github.com/fluxcd/source-controller/api v1.0.1 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect
Expand All @@ -133,21 +150,23 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.11.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/graph-gophers/graphql-go v1.4.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
Expand Down Expand Up @@ -183,6 +202,7 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.24 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
Expand All @@ -201,6 +221,7 @@ require (
github.com/muesli/termenv v0.15.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pborman/uuid v1.2.1 // indirect
Expand Down Expand Up @@ -228,8 +249,10 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
Expand All @@ -239,23 +262,25 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/apiextensions-apiserver v0.27.3 // indirect
k8s.io/apiserver v0.27.3 // indirect
k8s.io/component-base v0.27.3 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
nhooyr.io/websocket v1.8.7 // indirect
oras.land/oras-go v1.2.2 // indirect
Expand Down
Loading

0 comments on commit 67c8c24

Please sign in to comment.