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 9b283aa..874faac 100644 --- a/internal/cmd/local/local/install.go +++ b/internal/cmd/local/local/install.go @@ -261,6 +261,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, @@ -269,7 +275,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. diff --git a/internal/cmd/local/local/install_test.go b/internal/cmd/local/local/install_test.go index 3b7d0f6..0d715b3 100644 --- a/internal/cmd/local/local/install_test.go +++ b/internal/cmd/local/local/install_test.go @@ -3,7 +3,6 @@ package local import ( "context" "errors" - "fmt" "net/http" "testing" "time" @@ -13,7 +12,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/uuid" helmclient "github.com/mittwald/go-helm-client" - "github.com/mittwald/go-helm-client/values" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/release" @@ -33,6 +31,7 @@ func testChartLocator(chartName, chartVersion, chartFlag string) string { } func TestCommand_Install(t *testing.T) { + expNginxValues, _ := getNginxValuesYaml(9999) expChartRepoCnt := 0 expChartRepo := []struct { name string @@ -85,7 +84,7 @@ func TestCommand_Install(t *testing.T) { CreateNamespace: true, Wait: true, Timeout: 30 * time.Minute, - ValuesOptions: values.Options{Values: []string{fmt.Sprintf("controller.service.ports.http=%d", portTest)}}, + ValuesYaml: expNginxValues, }, release: release.Release{ Chart: &chart.Chart{Metadata: &chart.Metadata{Version: "4.3.2.1"}}, @@ -214,6 +213,7 @@ func TestCommand_Install_HelmValues(t *testing.T) { userID := uuid.New() expChartCnt := 0 + expNginxValues, _ := getNginxValuesYaml(9999) expChart := []struct { chart helmclient.ChartSpec release release.Release @@ -254,7 +254,7 @@ func TestCommand_Install_HelmValues(t *testing.T) { CreateNamespace: true, Wait: true, Timeout: 30 * time.Minute, - ValuesOptions: values.Options{Values: []string{fmt.Sprintf("controller.service.ports.http=%d", portTest)}}, + ValuesYaml: expNginxValues, }, release: release.Release{ Chart: &chart.Chart{Metadata: &chart.Metadata{Version: "4.3.2.1"}}, 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 +}