Skip to content

Commit

Permalink
feat: nginx config for request size and timeouts (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte authored Sep 25, 2024
1 parent 1d3d48c commit 6e6dfe4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 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
8 changes: 7 additions & 1 deletion internal/cmd/local/local/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/local/local/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package local
import (
"context"
"errors"
"fmt"
"net/http"
"testing"
"time"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"}},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"}},
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 6e6dfe4

Please sign in to comment.