Skip to content

Commit 74e1c4a

Browse files
authored
feat: add global.airbyteUrl Helm value for Airbyte 2.0.0+ (#187)
1 parent 4b2ecf4 commit 74e1c4a

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

internal/cmd/local/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (i *InstallCmd) installOpts(ctx context.Context, user string) (*service.Ins
209209
DisableAuth: i.DisableAuth,
210210
LocalStorage: !supportMinio,
211211
EnablePsql17: enablePsql17,
212+
Port: i.Port,
212213
}
213214

214215
if opts.DockerAuth() {

internal/cmd/local/local_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestValues_FileDoesntExist(t *testing.T) {
118118
}
119119

120120
func TestValues_BadYaml(t *testing.T) {
121-
cmd := InstallCmd{Values: "./testdata/invalid.values.yaml"}
121+
cmd := InstallCmd{Values: "./testdata/invalid.values.yaml", Port: 8000}
122122
// Does not need actual clients for tests.
123123
testFactory := func(kubeConfig, kubeContext string) (k8s.Client, goHelm.Client, error) {
124124
return nil, nil, nil
@@ -134,7 +134,7 @@ func TestValues_BadYaml(t *testing.T) {
134134
}
135135

136136
func TestInvalidHostFlag_IpAddr(t *testing.T) {
137-
cmd := InstallCmd{Host: []string{"ok", "1.2.3.4"}}
137+
cmd := InstallCmd{Host: []string{"ok", "1.2.3.4"}, Port: 8000}
138138
// Does not need actual clients for tests.
139139
testFactory := func(kubeConfig, kubeContext string) (k8s.Client, goHelm.Client, error) {
140140
return nil, nil, nil
@@ -146,7 +146,7 @@ func TestInvalidHostFlag_IpAddr(t *testing.T) {
146146
}
147147

148148
func TestInvalidHostFlag_IpAddrWithPort(t *testing.T) {
149-
cmd := InstallCmd{Host: []string{"ok", "1.2.3.4:8000"}}
149+
cmd := InstallCmd{Host: []string{"ok", "1.2.3.4:8000"}, Port: 8000}
150150
// Does not need actual clients for tests.
151151
testFactory := func(kubeConfig, kubeContext string) (k8s.Client, goHelm.Client, error) {
152152
return nil, nil, nil
@@ -162,6 +162,7 @@ func TestInstallOpts(t *testing.T) {
162162
cmd := InstallCmd{
163163
// Don't let the code dynamically resolve the latest chart version.
164164
Chart: "/test/path/to/chart",
165+
Port: 8000,
165166
}
166167
expect := &service.InstallOpts{
167168
HelmValuesYaml: string(b),

internal/helm/airbyte_values.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ValuesOpts struct {
1919
DisableAuth bool
2020
LocalStorage bool
2121
EnablePsql17 bool
22+
Port int
2223
}
2324

2425
const (
@@ -116,8 +117,21 @@ func buildAirbyteValuesV1(ctx context.Context, opts ValuesOpts) (string, error)
116117
func buildAirbyteValuesV2(ctx context.Context, opts ValuesOpts) (string, error) {
117118
span := trace.SpanFromContext(ctx)
118119

120+
// Validate port is in valid range
121+
if opts.Port <= 0 || opts.Port > 65535 {
122+
return "", fmt.Errorf("invalid port %d: must be between 1 and 65535", opts.Port)
123+
}
124+
125+
airbyteURL := fmt.Sprintf("http://localhost:%d", opts.Port)
126+
119127
vals := []string{
120-
"server.env_vars.WEBAPP_URL=http://airbyte-abctl-airbyte-server-svc:80",
128+
// WEBAPP_URL is required for backward compatibility with v2 Helm charts prior to Airbyte 2.0.0.
129+
// Starting with Airbyte 2.0.0, the platform uses AIRBYTE_URL instead (set via global.airbyteUrl).
130+
// Both are set here to support all v2 chart versions. WEBAPP_URL can be removed once all
131+
// supported chart versions are >= 2.0.0.
132+
// Port is omitted to use HTTP default (80), allowing users to override the service port via Helm values.
133+
"server.env_vars.WEBAPP_URL=http://airbyte-abctl-airbyte-server-svc",
134+
"global.airbyteUrl=" + airbyteURL,
121135
"global.env_vars.AIRBYTE_INSTALLATION_ID=" + opts.TelemetryUser,
122136
"global.jobs.resources.limits.cpu=3",
123137
"global.jobs.resources.limits.memory=4Gi",

internal/helm/airbyte_values_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ global:
212212
`,
213213
},
214214
{
215-
name: "v2: default options",
216-
opts: ValuesOpts{TelemetryUser: "test-user"},
215+
name: "v2: minimal options",
216+
opts: ValuesOpts{TelemetryUser: "test-user", Port: 8000},
217217
chartVersion: "2.0.0",
218218
want: `airbyte-bootloader:
219219
env_vars:
220220
PLATFORM_LOG_FORMAT: json
221221
global:
222+
airbyteUrl: http://localhost:8000
222223
auth:
223224
enabled: true
224225
env_vars:
@@ -230,19 +231,20 @@ global:
230231
memory: 4Gi
231232
server:
232233
env_vars:
233-
WEBAPP_URL: http://airbyte-abctl-airbyte-server-svc:80
234+
WEBAPP_URL: http://airbyte-abctl-airbyte-server-svc
234235
`,
235236
},
236237
{
237238
name: "v2: all options enabled",
238-
opts: ValuesOpts{TelemetryUser: "test-user", LocalStorage: true, EnablePsql17: true, LowResourceMode: true, InsecureCookies: true, ImagePullSecret: "mysecret", DisableAuth: false},
239+
opts: ValuesOpts{TelemetryUser: "test-user", LocalStorage: true, EnablePsql17: true, LowResourceMode: true, InsecureCookies: true, ImagePullSecret: "mysecret", DisableAuth: false, Port: 8000},
239240
chartVersion: "2.0.0",
240241
want: `airbyte-bootloader:
241242
env_vars:
242243
PLATFORM_LOG_FORMAT: json
243244
connectorBuilderServer:
244245
enabled: false
245246
global:
247+
airbyteUrl: http://localhost:8000
246248
auth:
247249
security:
248250
cookieSecureSetting: '"false"'
@@ -267,7 +269,7 @@ postgresql:
267269
server:
268270
env_vars:
269271
JOB_RESOURCE_VARIANT_OVERRIDE: lowresource
270-
WEBAPP_URL: http://airbyte-abctl-airbyte-server-svc:80
272+
WEBAPP_URL: http://airbyte-abctl-airbyte-server-svc
271273
workloadLauncher:
272274
env_vars:
273275
CHECK_JOB_MAIN_CONTAINER_CPU_REQUEST: "0"
@@ -319,19 +321,30 @@ global:
319321
`,
320322
},
321323
{
322-
name: "v2: invalid values file returns error",
324+
name: "v2: invalid values file",
323325
opts: ValuesOpts{
324326
TelemetryUser: "test-user",
325327
ValuesFile: filepath.Join(testdataDir, "invalid.values.yaml"),
328+
Port: 8000,
326329
},
327330
chartVersion: "2.0.0",
328331
wantErr: true,
329332
},
330333
{
331-
name: "v2: values file not found returns error",
334+
name: "v2: values file not found",
332335
opts: ValuesOpts{
333336
TelemetryUser: "test-user",
334337
ValuesFile: filepath.Join(testdataDir, "nonexistent.values.yaml"),
338+
Port: 8000,
339+
},
340+
chartVersion: "2.0.0",
341+
wantErr: true,
342+
},
343+
{
344+
name: "v2: invalid port",
345+
opts: ValuesOpts{
346+
TelemetryUser: "test-user",
347+
Port: 0,
335348
},
336349
chartVersion: "2.0.0",
337350
wantErr: true,

0 commit comments

Comments
 (0)