diff --git a/internal/local/chart/v3.go b/internal/local/chart/v3.go index 40fb373..f2e5003 100644 --- a/internal/local/chart/v3.go +++ b/internal/local/chart/v3.go @@ -3,6 +3,7 @@ package chart import ( "errors" "fmt" + "strings" config_v1 "github.com/weka/gohomecli/internal/local/config/v1" "github.com/weka/gohomecli/internal/utils" @@ -193,7 +194,12 @@ func configureCore(configuration *config_v1.Configuration) (yamlMap, error) { cfg = make(yamlMap) ) - err = writeMapEntryIfSet(cfg, "core.proxy.url", configuration.Proxy) + if configuration.Proxy.URL != "" { + err = errors.Join( + writeMapEntryIfSet(cfg, "core.proxy.url", configuration.Proxy.URL), + writeMapEntryIfSet(cfg, "core.proxy.noProxy", strings.Join(configuration.Proxy.NoProxy, ",")), + ) + } return cfg, err } diff --git a/internal/local/config/v1/v1.go b/internal/local/config/v1/v1.go index 53505e8..8507936 100644 --- a/internal/local/config/v1/v1.go +++ b/internal/local/config/v1/v1.go @@ -33,7 +33,15 @@ type ForwardingConfig struct { } type ProxyConfig struct { - URL string `json:"url,omitempty"` + URL string `json:"url,omitempty"` + NoProxy []string `json:"no_proxy,omitempty"` +} + +func (p ProxyConfig) NoProxyWithDefaults() []string { + return append([]string{ + "127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", + "cluster.local", "localhost", + }, p.NoProxy...) } // Configuration flat options for the chart, pointers are used to distinguish between empty and unset values diff --git a/internal/local/k3s/k3s.go b/internal/local/k3s/k3s.go index b2d12ae..95184f7 100644 --- a/internal/local/k3s/k3s.go +++ b/internal/local/k3s/k3s.go @@ -346,16 +346,17 @@ func k3sInstall(ctx context.Context, c Config, fi fs.FileInfo, r io.Reader) erro return fmt.Errorf("url parse: %w", err) } + // skip internal IP from proxying + noProxy := append([]string{ + fmt.Sprintf("%s/32", c.IP), + fmt.Sprintf("%s/32", c.ifaceAddr), + }, c.Proxy.NoProxyWithDefaults()...) + logger.Info(). Str("proxy", utils.URLSafe(proxyURL).String()). + Strs("no_proxy", noProxy). Msg("Using proxy") - var noProxy = []string{ - "127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", - fmt.Sprintf("%s/32", c.IP), - fmt.Sprintf("%s/32", c.ifaceAddr), - } - os.Setenv("NO_PROXY", strings.Join(noProxy, ",")) switch proxyURL.Scheme {