Merge pull request #23 from santhoshdaivajna/default_noproxy

add default noproxy value for non-empty http-proxy
This commit is contained in:
Rishi Anand 2023-01-24 20:58:47 -08:00 committed by GitHub
commit b0df33ec88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 22 deletions

View File

@ -5,8 +5,8 @@ ARG BASE_IMAGE=quay.io/kairos/core-opensuse:latest
ARG IMAGE_REPOSITORY=quay.io/kairos
ARG LUET_VERSION=0.33.0
ARG GOLINT_VERSION=v1.46.2
ARG GOLANG_VERSION=1.18
ARG GOLINT_VERSION=v1.50.1
ARG GOLANG_VERSION=1.19.2
ARG RKE2_VERSION=latest
ARG BASE_IMAGE_NAME=$(echo $BASE_IMAGE | grep -o [^/]*: | rev | cut -c2- | rev)

54
main.go
View File

@ -116,19 +116,32 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
func proxyEnv(userOptions []byte, proxyMap map[string]string) string {
var proxy []string
var noProxy string
var isProxyConfigured bool
httpProxy := proxyMap["HTTP_PROXY"]
httpsProxy := proxyMap["HTTPS_PROXY"]
noProxy := getNoProxy(userOptions, proxyMap["NO_PROXY"])
userNoProxy := proxyMap["NO_PROXY"]
defaultNoProxy := getDefaultNoProxy(userOptions)
if len(httpProxy) > 0 {
proxy = append(proxy, fmt.Sprintf("HTTP_PROXY=%s", httpProxy))
proxy = append(proxy, fmt.Sprintf("CONTAINERD_HTTP_PROXY=%s", httpProxy))
isProxyConfigured = true
}
if len(httpsProxy) > 0 {
proxy = append(proxy, fmt.Sprintf("HTTPS_PROXY=%s", httpsProxy))
proxy = append(proxy, fmt.Sprintf("CONTAINERD_HTTPS_PROXY=%s", httpsProxy))
isProxyConfigured = true
}
if isProxyConfigured {
noProxy = defaultNoProxy
}
if len(userNoProxy) > 0 {
noProxy = noProxy + "," + userNoProxy
}
if len(noProxy) > 0 {
@ -139,28 +152,29 @@ func proxyEnv(userOptions []byte, proxyMap map[string]string) string {
return strings.Join(proxy, "\n")
}
func getNoProxy(userOptions []byte, noProxy string) string {
func getDefaultNoProxy(userOptions []byte) string {
if len(noProxy) > 0 {
data := make(map[string]interface{})
err := json.Unmarshal(userOptions, &data)
if err != nil {
fmt.Println("error while unmarshalling user options", err)
}
var noProxy string
if data != nil {
clusterCIDR := data["cluster-cidr"].(string)
serviceCIDR := data["service-cidr"].(string)
if len(clusterCIDR) > 0 {
noProxy = noProxy + "," + clusterCIDR
}
if len(serviceCIDR) > 0 {
noProxy = noProxy + "," + serviceCIDR
}
noProxy = noProxy + "," + getNodeCIDR() + "," + K8S_NO_PROXY
}
data := make(map[string]interface{})
err := json.Unmarshal(userOptions, &data)
if err != nil {
fmt.Println("error while unmarshalling user options", err)
}
if data != nil {
clusterCIDR := data["cluster-cidr"].(string)
serviceCIDR := data["service-cidr"].(string)
if len(clusterCIDR) > 0 {
noProxy = noProxy + "," + clusterCIDR
}
if len(serviceCIDR) > 0 {
noProxy = noProxy + "," + serviceCIDR
}
noProxy = noProxy + "," + getNodeCIDR() + "," + K8S_NO_PROXY
}
return noProxy
}