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 b8e2b72 commit fa6dad2
Show file tree
Hide file tree
Showing 35 changed files with 1,506 additions and 66 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/multierror"
"github.com/kubeshop/botkube/pkg/notifier"
"github.com/kubeshop/botkube/pkg/sink"
Expand Down Expand Up @@ -390,7 +390,7 @@ func run(ctx context.Context) (err 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 @@ -444,18 +444,18 @@ func run(ctx context.Context) (err 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),
},
})
}
24 changes: 16 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ require (
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/allegro/bigcache/v3 v3.1.0
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/bombsimon/logrusr/v4 v4.0.0
github.com/briandowns/spinner v1.23.0
github.com/bwmarrin/discordgo v0.25.0
github.com/charmbracelet/log v0.2.2
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.15.0
github.com/fluxcd/kustomize-controller/api v1.0.1
github.com/fluxcd/source-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
Expand Down Expand Up @@ -64,14 +68,14 @@ require (
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.14.1
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/yaml v1.3.0
)

Expand All @@ -88,6 +92,7 @@ require (
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-20230217124315-7d5c6f04bbb8 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand All @@ -99,6 +104,7 @@ require (
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
Expand All @@ -118,6 +124,8 @@ require (
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/fortytw2/leaktest v1.3.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
Expand Down Expand Up @@ -245,9 +253,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // 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 fa6dad2

Please sign in to comment.