-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp_dispatch.go
More file actions
104 lines (96 loc) · 3 KB
/
app_dispatch.go
File metadata and controls
104 lines (96 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"context"
"flag"
"fmt"
"net/url"
"strings"
"time"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/coder/coder-k8s/internal/app/allapp"
"github.com/coder/coder-k8s/internal/app/apiserverapp"
"github.com/coder/coder-k8s/internal/app/controllerapp"
"github.com/coder/coder-k8s/internal/app/mcpapp"
)
const supportedAppModes = "all, controller, aggregated-apiserver, mcp-http"
var (
runAllApp func(context.Context, time.Duration) error = allapp.Run
runControllerApp = controllerapp.Run
runAggregatedAPIServerApp = func(ctx context.Context, opts apiserverapp.Options) error {
return apiserverapp.RunWithOptions(ctx, opts)
}
runMCPHTTPApp = mcpapp.RunHTTP
setupSignalHandler = ctrl.SetupSignalHandler
)
func run(args []string) error {
fs := flag.NewFlagSet("coder-k8s", flag.ContinueOnError)
var (
appMode string
coderURL string
coderSessionToken string
coderNamespace string
coderRequestTimeout time.Duration
)
fs.StringVar(&appMode, "app", "all", "Application mode (all, controller, aggregated-apiserver, mcp-http)")
fs.StringVar(
&coderSessionToken,
"coder-session-token",
"",
"Admin session token for the backing Coder deployment",
)
fs.StringVar(
&coderURL,
"coder-url",
"",
"Coder deployment URL (fallback when CoderControlPlane status URL is unavailable)",
)
fs.StringVar(
&coderNamespace,
"coder-namespace",
"",
"Restrict the aggregated API server to serve only this Kubernetes namespace",
)
fs.DurationVar(
&coderRequestTimeout,
"coder-request-timeout",
30*time.Second,
"Timeout for Coder SDK API requests",
)
if err := fs.Parse(args); err != nil {
return err
}
if coderURL != "" {
parsedCoderURL, err := url.Parse(coderURL)
if err != nil {
return fmt.Errorf("assertion failed: invalid --coder-url %q: %w", coderURL, err)
}
if parsedCoderURL.Scheme == "" || parsedCoderURL.Host == "" {
return fmt.Errorf(
"assertion failed: invalid --coder-url %q: must include scheme and host (for example, https://coder.example.com)",
coderURL,
)
}
scheme := strings.ToLower(parsedCoderURL.Scheme)
if scheme != "http" && scheme != "https" {
return fmt.Errorf("assertion failed: invalid --coder-url %q: scheme must be http or https", coderURL)
}
}
switch appMode {
case "all":
return runAllApp(setupSignalHandler(), coderRequestTimeout)
case "controller":
return runControllerApp(setupSignalHandler())
case "aggregated-apiserver":
opts := apiserverapp.Options{
CoderURL: coderURL,
CoderSessionToken: coderSessionToken,
CoderNamespace: coderNamespace,
CoderRequestTimeout: coderRequestTimeout,
}
return runAggregatedAPIServerApp(setupSignalHandler(), opts)
case "mcp-http":
return runMCPHTTPApp(setupSignalHandler())
default:
return fmt.Errorf("assertion failed: unsupported --app value %q; must be one of: %s", appMode, supportedAppModes)
}
}