Skip to content

Commit 01b9eb2

Browse files
committed
fix(thoth): avoid hairpinning by connecting directly to thoth in the cluster
Signed-off-by: Xe Iaso <me@xeiaso.net>
1 parent a124314 commit 01b9eb2

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

cmd/sponsor-panel/internal/thoth/thoth.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/prometheus/client_golang/prometheus"
1212
"google.golang.org/grpc"
1313
"google.golang.org/grpc/credentials"
14+
"google.golang.org/grpc/credentials/insecure"
1415
healthv1 "google.golang.org/grpc/health/grpc_health_v1"
1516
"google.golang.org/grpc/metadata"
1617
adminv1 "xeiaso.net/v4/gen/techaro/thoth/auth/admin/v1"
@@ -25,18 +26,26 @@ type Client struct {
2526
AdminUsers adminv1.UsersServiceClient
2627
}
2728

28-
func New(ctx context.Context, thothURL, apiToken string) (*Client, error) {
29+
func New(ctx context.Context, thothURL, apiToken string, noTLS bool) (*Client, error) {
2930
clMetrics := grpcprom.NewClientMetrics(
3031
grpcprom.WithClientHandlingTimeHistogram(
3132
grpcprom.WithHistogramBuckets([]float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}),
3233
),
3334
)
3435
prometheus.DefaultRegisterer.Register(clMetrics)
3536

37+
var transportCreds credentials.TransportCredentials
38+
39+
switch noTLS {
40+
case true:
41+
transportCreds = insecure.NewCredentials()
42+
case false:
43+
transportCreds = credentials.NewTLS(&tls.Config{})
44+
}
45+
3646
conn, err := grpc.NewClient(
3747
thothURL,
38-
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
39-
//grpc.WithTransportCredentials(insecure.NewCredentials()),
48+
grpc.WithTransportCredentials(transportCreds),
4049
grpc.WithChainUnaryInterceptor(
4150
timeout.UnaryClientInterceptor(5*time.Minute),
4251
clMetrics.UnaryClientInterceptor(),

cmd/sponsor-panel/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ var (
5959
patreonFiftyPlus = flag.String("patreon-fifty-plus", "", "Comma-separated list of Patreon usernames always treated as $50+ sponsors")
6060

6161
// Thoth settings
62-
thothToken = flag.String("thoth-token", "", "Thoth API token (use a god token)")
63-
thothURL = flag.String("thoth-url", "passthrough:///thoth.techaro.lol:443", "URL for the Thoth API server")
62+
thothInsecure = flag.Bool("thoth-insecure", false, "if true, connect to thoth without TLS")
63+
thothToken = flag.String("thoth-token", "", "Thoth API token (use a god token)")
64+
thothURL = flag.String("thoth-url", "passthrough:///thoth.techaro.lol:443", "URL for the Thoth API server")
6465

6566
//go:embed static
6667
staticFS embed.FS

docker/patreon-saasproxy.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ COPY go.mod go.sum ./
1111
RUN go mod download
1212

1313
COPY . .
14+
RUN apk -U add git
1415
RUN --mount=type=cache,target=/root/.cache GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -ldflags="-X xeiaso.net/v4.Version=$(git describe --tags --always --dirty)" -gcflags "all=-N -l" -o /app/bin/patreon-saasproxy ./cmd/patreon-saasproxy
1516

1617
FROM alpine:${ALPINE_VERSION} AS run

docker/sponsor-panel.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ COPY go.mod go.sum ./
1212
RUN go mod download
1313

1414
COPY . .
15-
RUN apk -U add nodejs npm \
15+
RUN apk -U add git nodejs npm \
1616
&& npm ci \
1717
&& cd ./cmd/sponsor-panel \
1818
&& go generate ./...

manifest/sponsor-panel/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ spec:
3737
value: ":4823"
3838
- name: SLOG_LEVEL
3939
value: "info"
40+
- name: "THOTH_INSECURE"
41+
value: "true"
4042
ports:
4143
- containerPort: 4823
4244
name: http

0 commit comments

Comments
 (0)