Skip to content

Commit

Permalink
Pass-through PROXY environment to Replicated SDK deployment (#4862)
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin authored Sep 4, 2024
1 parent fa660c6 commit 373a414
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pkg/rewrite/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func Rewrite(rewriteOptions RewriteOptions) error {
IsAirgap: rewriteOptions.IsAirgap,
KotsadmID: k8sutil.GetKotsadmID(clientset),
AppID: rewriteOptions.AppID,
HTTPProxyEnvValue: rewriteOptions.HTTPProxyEnvValue,
HTTPSProxyEnvValue: rewriteOptions.HTTPSProxyEnvValue,
NoProxyEnvValue: rewriteOptions.NoProxyEnvValue,
}
if err = upstream.WriteUpstream(u, writeUpstreamOptions); err != nil {
log.FinishSpinnerWithError()
Expand Down
18 changes: 18 additions & 0 deletions pkg/upstream/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ func buildReplicatedValues(u *types.Upstream, options types.WriteOptions) (map[s
replicatedValues["license"] = string(MustMarshalLicense(u.License))
}

replicatedValues["extraEnv"] = []struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}{
{
Name: "HTTP_PROXY",
Value: options.HTTPProxyEnvValue,
},
{
Name: "HTTPS_PROXY",
Value: options.HTTPSProxyEnvValue,
},
{
Name: "NO_PROXY",
Value: options.NoProxyEnvValue,
},
}

return replicatedValues, nil
}

Expand Down
75 changes: 66 additions & 9 deletions pkg/upstream/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func Test_configureChart(t *testing.T) {
type Test struct {
name string
isAirgap bool
httpProxy string
httpsProxy string
noProxy string
chartContent map[string]string
want map[string]string
wantErr bool
Expand Down Expand Up @@ -288,8 +291,11 @@ another: value
// Generate dynamic tests using the supported replicated chart names
for _, chartName := range testReplicatedChartNames {
tests = append(tests, Test{
name: "online - a standalone replicated chart",
isAirgap: false,
name: "online - a standalone replicated chart",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"replicated/Chart.yaml": fmt.Sprintf(`apiVersion: v1
name: %s
Expand Down Expand Up @@ -376,6 +382,13 @@ some: value
# and this comment as well
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
`,
Expand Down Expand Up @@ -459,6 +472,13 @@ some: value
# and this comment as well
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
replicatedID: kotsadm-id
global:
Expand All @@ -482,8 +502,11 @@ global:
})

tests = append(tests, Test{
name: "online - a guestbook chart with the replicated subchart",
isAirgap: false,
name: "online - a guestbook chart with the replicated subchart",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"guestbook/Chart.yaml": `apiVersion: v2
name: guestbook
Expand Down Expand Up @@ -569,6 +592,13 @@ image:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
global:
Expand Down Expand Up @@ -675,6 +705,13 @@ image:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
license: |
apiVersion: kots.io/v1beta1
Expand Down Expand Up @@ -733,8 +770,11 @@ some: value
})

tests = append(tests, Test{
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
isAirgap: false,
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"redis/Chart.yaml": `apiVersion: v1
name: redis
Expand Down Expand Up @@ -848,6 +888,13 @@ global:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
`, chartName),
Expand Down Expand Up @@ -965,6 +1012,13 @@ global:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
license: |
apiVersion: kots.io/v1beta1
Expand Down Expand Up @@ -1244,9 +1298,12 @@ some: value
}

writeOptions := types.WriteOptions{
KotsadmID: "kotsadm-id",
AppID: "app-id",
IsAirgap: tt.isAirgap,
KotsadmID: "kotsadm-id",
AppID: "app-id",
IsAirgap: tt.isAirgap,
HTTPProxyEnvValue: tt.httpProxy,
HTTPSProxyEnvValue: tt.httpsProxy,
NoProxyEnvValue: tt.noProxy,
}

got, err := configureChart(chartBytes, upstream, writeOptions)
Expand Down

0 comments on commit 373a414

Please sign in to comment.