Skip to content

Commit

Permalink
feat: nginx config for request size and timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte committed Sep 20, 2024
1 parent f5b5265 commit 624122c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
8 changes: 0 additions & 8 deletions internal/cmd/local/k8s/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ type Provider struct {
Context string
// Kubeconfig location
Kubeconfig string
// HelmNginx additional helm values to pass to the nginx chart
HelmNginx []string
}

// Cluster returns a kubernetes cluster for this provider.
Expand Down Expand Up @@ -91,11 +89,6 @@ var (
ClusterName: "airbyte-abctl",
Context: "kind-airbyte-abctl",
Kubeconfig: paths.Kubeconfig,
HelmNginx: []string{
"controller.hostPort.enabled=true",
"controller.service.httpsPort.enable=false",
"controller.service.type=NodePort",
},
}

// TestProvider represents a test provider, for testing purposes
Expand All @@ -104,6 +97,5 @@ var (
ClusterName: "test-airbyte-abctl",
Context: "test-airbyte-abctl",
Kubeconfig: filepath.Join(os.TempDir(), "abctl", paths.FileKubeconfig),
HelmNginx: []string{},
}
)
11 changes: 0 additions & 11 deletions internal/cmd/local/k8s/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ func TestProvider_Defaults(t *testing.T) {
if d := cmp.Diff(paths.Kubeconfig, DefaultProvider.Kubeconfig); d != "" {
t.Errorf("Kubeconfig mismatch (-want +got):\n%s", d)
}
expHelmNginx := []string{
"controller.hostPort.enabled=true",
"controller.service.httpsPort.enable=false",
"controller.service.type=NodePort",
}
if d := cmp.Diff(expHelmNginx, DefaultProvider.HelmNginx); d != "" {
t.Errorf("HelmNginx mismatch (-want +got):\n%s", d)
}
})

t.Run("test", func(t *testing.T) {
Expand All @@ -53,9 +45,6 @@ func TestProvider_Defaults(t *testing.T) {
if d := cmp.Diff(paths.Kubeconfig, TestProvider.Kubeconfig); d == "" {
t.Errorf("Kubeconfig should differ (%s)", paths.Kubeconfig)
}
if d := cmp.Diff([]string{}, TestProvider.HelmNginx); d != "" {
t.Errorf("HelmNginx mismatch (-want +got):\n%s", d)
}
})
}

Expand Down
10 changes: 8 additions & 2 deletions internal/cmd/local/local/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ func (c *Command) Install(ctx context.Context, opts InstallOpts) error {
return c.diagnoseAirbyteChartFailure(ctx, err)
}

nginxValues, err := getNginxValuesYaml(c.portHTTP)
if err != nil {
return err
}
pterm.Debug.Printfln("nginx values:\n%s", nginxValues)

if err := c.handleChart(ctx, chartRequest{
name: "nginx",
uninstallFirst: true,
Expand All @@ -267,7 +273,7 @@ func (c *Command) Install(ctx context.Context, opts InstallOpts) error {
chartName: nginxChartName,
chartRelease: nginxChartRelease,
namespace: nginxNamespace,
values: append(c.provider.HelmNginx, fmt.Sprintf("controller.service.ports.http=%d", c.portHTTP)),
valuesYAML: nginxValues,
}); err != nil {
// If we timed out, there is a good chance it's due to an unavailable port, check if this is the case.
// As the kubernetes client doesn't return usable error types, have to check for a specific string value.
Expand Down Expand Up @@ -746,7 +752,7 @@ func determineHelmChartAction(helm helm.Client, chart *chart.Chart, releaseName
// values provided were potentially overridden by the valuesYML file.
func mergeValuesWithValuesYAML(values []string, userValues map[string]any) (string, error) {
a := maps.FromSlice(values)

maps.Merge(a, userValues)

res, err := maps.ToYAML(a)
Expand Down
32 changes: 32 additions & 0 deletions internal/cmd/local/local/nginx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package local

import (
"bytes"
"fmt"
"text/template"
)

var nginxValuesTpl = template.Must(template.New("nginx-values").Parse(`
controller:
hostPort:
enabled: true
service:
type: NodePort
ports:
http: {{ .Port }}
httpsPort:
enable: false
config:
proxy-body-size: 10m
proxy-read-timeout: "600"
proxy-send-timeout: "600"
`))

func getNginxValuesYaml(port int) (string, error) {
var buf bytes.Buffer
err := nginxValuesTpl.Execute(&buf, map[string]any{"Port": port})
if err != nil {
return "", fmt.Errorf("failed to build nginx values yaml: %w", err)
}
return buf.String(), nil
}

0 comments on commit 624122c

Please sign in to comment.