Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nginx config for request size and timeouts #129

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 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
}