From 624122cdbaba79784d07a002b554eadd8dc068a7 Mon Sep 17 00:00:00 2001 From: Alex Buchanan Date: Fri, 20 Sep 2024 12:38:02 -0700 Subject: [PATCH] feat: nginx config for request size and timeouts --- internal/cmd/local/k8s/provider.go | 8 ------- internal/cmd/local/k8s/provider_test.go | 11 --------- internal/cmd/local/local/install.go | 10 ++++++-- internal/cmd/local/local/nginx.go | 32 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 internal/cmd/local/local/nginx.go diff --git a/internal/cmd/local/k8s/provider.go b/internal/cmd/local/k8s/provider.go index 9439650..c385200 100644 --- a/internal/cmd/local/k8s/provider.go +++ b/internal/cmd/local/k8s/provider.go @@ -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. @@ -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 @@ -104,6 +97,5 @@ var ( ClusterName: "test-airbyte-abctl", Context: "test-airbyte-abctl", Kubeconfig: filepath.Join(os.TempDir(), "abctl", paths.FileKubeconfig), - HelmNginx: []string{}, } ) diff --git a/internal/cmd/local/k8s/provider_test.go b/internal/cmd/local/k8s/provider_test.go index 9294d29..8d576d6 100644 --- a/internal/cmd/local/k8s/provider_test.go +++ b/internal/cmd/local/k8s/provider_test.go @@ -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) { @@ -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) - } }) } diff --git a/internal/cmd/local/local/install.go b/internal/cmd/local/local/install.go index cfe8971..a821356 100644 --- a/internal/cmd/local/local/install.go +++ b/internal/cmd/local/local/install.go @@ -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, @@ -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. @@ -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) diff --git a/internal/cmd/local/local/nginx.go b/internal/cmd/local/local/nginx.go new file mode 100644 index 0000000..7a65a65 --- /dev/null +++ b/internal/cmd/local/local/nginx.go @@ -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 +}