Skip to content

Commit e6c986f

Browse files
authored
allow configuring https_proxy and no_proxy (#335)
* allow configuring https_proxy and no_proxy * do not proxy requests made with the k8s clientset * helm requests should not use the proxy either * improve noproxy comments
1 parent dbd8b8f commit e6c986f

File tree

6 files changed

+100
-1
lines changed

6 files changed

+100
-1
lines changed

chart/templates/_helpers.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,28 @@ Get daemonset names from status informers
363363
{{- range $daemonsets }}
364364
- {{ . }}
365365
{{- end -}}
366+
{{- end -}}
367+
368+
{{/*
369+
Get HTTPS proxy value
370+
Checks local proxy.httpsProxy first, then falls back to global.replicated.httpsProxy
371+
*/}}
372+
{{- define "replicated.httpsProxy" -}}
373+
{{- if .Values.proxy.httpsProxy -}}
374+
{{- .Values.proxy.httpsProxy -}}
375+
{{- else if and .Values.global .Values.global.replicated .Values.global.replicated.httpsProxy -}}
376+
{{- .Values.global.replicated.httpsProxy -}}
377+
{{- end -}}
378+
{{- end -}}
379+
380+
{{/*
381+
Get NO_PROXY value
382+
Checks local proxy.noProxy first, then falls back to global.replicated.noProxy
383+
*/}}
384+
{{- define "replicated.noProxy" -}}
385+
{{- if .Values.proxy.noProxy -}}
386+
{{- .Values.proxy.noProxy -}}
387+
{{- else if and .Values.global .Values.global.replicated .Values.global.replicated.noProxy -}}
388+
{{- .Values.global.replicated.noProxy -}}
389+
{{- end -}}
366390
{{- end -}}

chart/templates/replicated-deployment.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ spec:
123123
{{- with .Values.extraEnv }}
124124
{{- toYaml . | nindent 8 }}
125125
{{- end }}
126+
{{- $httpsProxy := include "replicated.httpsProxy" . }}
127+
{{- if $httpsProxy }}
128+
- name: HTTPS_PROXY
129+
value: {{ $httpsProxy | quote }}
130+
{{- end }}
131+
{{- $noProxy := include "replicated.noProxy" . }}
132+
{{- if $noProxy }}
133+
- name: NO_PROXY
134+
value: {{ $noProxy | quote }}
135+
{{- end }}
126136
{{- if or .Values.privateCAConfigmap .Values.privateCASecret }}
127137
- name: SSL_CERT_DIR
128138
value: /certs

chart/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,13 @@ minimalRBAC: false
305305
# When true, the SDK will report every image+digest in the cluster regardless of the releaseImages filter
306306
# When false (default), only images matching the releaseImages list will be reported
307307
reportAllImages: false
308+
309+
# Proxy configuration for outbound connections
310+
# Configure HTTPS proxy settings for the Replicated SDK
311+
# These values can also be set via global.replicated.httpsProxy and global.replicated.noProxy
312+
# when used as a subchart. Local values take precedence over global values.
313+
# Configuring noProxy should not be required in normal usage, as the SDK will
314+
# automatically bypass the proxy when making requests to cluster APIs.
315+
proxy:
316+
httpsProxy: "" # HTTPS proxy URL (e.g., "https://proxy.example.com:8080")
317+
noProxy: "" # Comma-separated list of hosts to bypass proxy (e.g., "localhost,127.0.0.1")

pkg/helm/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func init() {
1515
}
1616

1717
cfg = new(action.Configuration)
18-
if err := cfg.Init(k8sutil.KubernetesConfigFlags, GetReleaseNamespace(), GetHelmDriver(), logger.Debugf); err != nil {
18+
if err := cfg.Init(k8sutil.ProxyBypassRESTClientGetter(k8sutil.KubernetesConfigFlags), GetReleaseNamespace(), GetHelmDriver(), logger.Debugf); err != nil {
1919
panic(errors.Wrap(err, "failed to init helm action config"))
2020
}
2121
}

pkg/k8sutil/clientset.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package k8sutil
22

33
import (
4+
"net/http"
5+
"net/url"
46
"regexp"
57
"strconv"
68

@@ -60,6 +62,9 @@ func GetClusterConfig() (*rest.Config, error) {
6062
cfg.QPS = DEFAULT_K8S_CLIENT_QPS
6163
cfg.Burst = DEFAULT_K8S_CLIENT_BURST
6264

65+
// Never proxy Kubernetes API requests, regardless of environment
66+
cfg.Proxy = func(*http.Request) (*url.URL, error) { return nil, nil }
67+
6368
return cfg, nil
6469
}
6570

pkg/k8sutil/rest_getter.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package k8sutil
2+
3+
import (
4+
"net/http"
5+
"net/url"
6+
7+
meta "k8s.io/apimachinery/pkg/api/meta"
8+
"k8s.io/cli-runtime/pkg/genericclioptions"
9+
"k8s.io/client-go/discovery"
10+
"k8s.io/client-go/rest"
11+
"k8s.io/client-go/tools/clientcmd"
12+
)
13+
14+
// proxyBypassFlags wraps ConfigFlags to force-disable HTTP proxy usage
15+
// for Kubernetes API requests by setting rest.Config.Proxy to nil.
16+
type proxyBypassFlags struct {
17+
base *genericclioptions.ConfigFlags
18+
}
19+
20+
func ProxyBypassRESTClientGetter(base *genericclioptions.ConfigFlags) genericclioptions.RESTClientGetter {
21+
return &proxyBypassFlags{base: base}
22+
}
23+
24+
func (p *proxyBypassFlags) ToRESTConfig() (*rest.Config, error) {
25+
cfg, err := p.base.ToRESTConfig()
26+
if err != nil {
27+
return nil, err
28+
}
29+
// Ensure QPS/Burst defaults and disable proxy
30+
if cfg.QPS == 0 {
31+
cfg.QPS = DEFAULT_K8S_CLIENT_QPS
32+
}
33+
if cfg.Burst == 0 {
34+
cfg.Burst = DEFAULT_K8S_CLIENT_BURST
35+
}
36+
cfg.Proxy = func(*http.Request) (*url.URL, error) { return nil, nil }
37+
return cfg, nil
38+
}
39+
40+
func (p *proxyBypassFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
41+
return p.base.ToDiscoveryClient()
42+
}
43+
44+
func (p *proxyBypassFlags) ToRESTMapper() (meta.RESTMapper, error) {
45+
return p.base.ToRESTMapper()
46+
}
47+
48+
func (p *proxyBypassFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
49+
return p.base.ToRawKubeConfigLoader()
50+
}

0 commit comments

Comments
 (0)