-
Notifications
You must be signed in to change notification settings - Fork 20
Add Slack as a TaskSpawner source (MVP) #1002
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
Open
jkahuja
wants to merge
6
commits into
kelos-dev:main
Choose a base branch
from
datagravity-ai:feat/slack-source-mvp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b12b5ad
feat(api): Add Slack as a TaskSpawner source (MVP)
jkahuja 12ab40b
fix(rbac): Remove unused update/watch verbs from slack-server Task RBAC
jkahuja 323b841
feat(api): Replace MentionUserIDs with implicit bot mention and trigg…
jkahuja 21a196b
feat(api): Add MinLength=1 validation to SlackTrigger Pattern field
jkahuja d876869
feat(api): Remove MinLength=1 validation from SlackTrigger Pattern field
jkahuja edd1133
fix(api): Address PR review feedback for Slack source
jkahuja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM gcr.io/distroless/static:nonroot | ||
| WORKDIR / | ||
| COPY bin/kelos-slack-server . | ||
| USER 65532:65532 | ||
| ENTRYPOINT ["/kelos-slack-server"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
| metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
|
|
||
| kelosv1alpha1 "github.com/kelos-dev/kelos/api/v1alpha1" | ||
| "github.com/kelos-dev/kelos/internal/logging" | ||
| kelosslack "github.com/kelos-dev/kelos/internal/slack" | ||
| ) | ||
|
|
||
| var ( | ||
| scheme = runtime.NewScheme() | ||
| setupLog = ctrl.Log.WithName("setup") | ||
| ) | ||
|
|
||
| func init() { | ||
| utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
| utilruntime.Must(kelosv1alpha1.AddToScheme(scheme)) | ||
| } | ||
|
|
||
| func main() { | ||
| var ( | ||
| metricsAddr string | ||
| probeAddr string | ||
| enableLeaderElection bool | ||
| ) | ||
|
|
||
| flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") | ||
| flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") | ||
| flag.BoolVar(&enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager.") | ||
|
|
||
| opts, applyVerbosity := logging.SetupZapOptions(flag.CommandLine) | ||
| flag.Parse() | ||
|
|
||
| if err := applyVerbosity(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| ctrl.SetLogger(zap.New(zap.UseFlagOptions(opts))) | ||
|
|
||
| botToken := os.Getenv("SLACK_BOT_TOKEN") | ||
| appToken := os.Getenv("SLACK_APP_TOKEN") | ||
| if botToken == "" || appToken == "" { | ||
| setupLog.Error(fmt.Errorf("missing tokens"), "SLACK_BOT_TOKEN and SLACK_APP_TOKEN environment variables are required") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
| Scheme: scheme, | ||
| Metrics: metricsserver.Options{BindAddress: metricsAddr}, | ||
| HealthProbeBindAddress: probeAddr, | ||
| LeaderElection: enableLeaderElection, | ||
| LeaderElectionID: "kelos-slack-server", | ||
| }) | ||
| if err != nil { | ||
| setupLog.Error(err, "Unable to start manager") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| ctx := ctrl.SetupSignalHandler() | ||
|
|
||
| // Create the Slack handler | ||
| handler, err := kelosslack.NewSlackHandler( | ||
| ctx, | ||
| mgr.GetClient(), | ||
| botToken, | ||
| appToken, | ||
| ctrl.Log.WithName("slack"), | ||
| ) | ||
| if err != nil { | ||
| setupLog.Error(err, "Unable to create Slack handler") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Register Socket Mode listener as a leader-elected runnable so that only | ||
| // one replica opens the single-connection Socket Mode WebSocket. | ||
| if err := mgr.Add(&slackRunnable{handler: handler}); err != nil { | ||
| setupLog.Error(err, "Unable to register Slack handler with manager") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Health checks | ||
| if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { | ||
| setupLog.Error(err, "Unable to set up health check") | ||
| os.Exit(1) | ||
| } | ||
| if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { | ||
| setupLog.Error(err, "Unable to set up ready check") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| setupLog.Info("Starting manager") | ||
| if err := mgr.Start(ctx); err != nil { | ||
| setupLog.Error(err, "Problem running manager") | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| // slackRunnable wraps the SlackHandler as a leader-elected manager.Runnable. | ||
| // This ensures only the leader replica opens the Socket Mode connection. | ||
| type slackRunnable struct { | ||
| handler *kelosslack.SlackHandler | ||
| } | ||
|
|
||
| func (r *slackRunnable) Start(ctx context.Context) error { | ||
| setupLog.Info("Starting Slack Socket Mode listener") | ||
| err := r.handler.Start(ctx) | ||
| if err != nil && ctx.Err() == nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (r *slackRunnable) NeedLeaderElection() bool { return true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.