MergeProxyConfigs merges proxy configurations from the operator and the cluster and merges them, with the operator configuration taking precedence. Accepts nil arguments. If both arguments are nil, returns nil.
(operatorConfig, clusterConfig *controller.Proxy)
| 62 | // MergeProxyConfigs merges proxy configurations from the operator and the cluster and merges them, with the |
| 63 | // operator configuration taking precedence. Accepts nil arguments. If both arguments are nil, returns nil. |
| 64 | func MergeProxyConfigs(operatorConfig, clusterConfig *controller.Proxy) *controller.Proxy { |
| 65 | if clusterConfig == nil { |
| 66 | return removeEmptyStrings(operatorConfig) |
| 67 | } |
| 68 | if operatorConfig == nil { |
| 69 | return removeEmptyStrings(clusterConfig) |
| 70 | } |
| 71 | |
| 72 | mergedProxy := &controller.Proxy{ |
| 73 | HttpProxy: operatorConfig.HttpProxy, |
| 74 | HttpsProxy: operatorConfig.HttpsProxy, |
| 75 | NoProxy: operatorConfig.NoProxy, |
| 76 | } |
| 77 | |
| 78 | if mergedProxy.HttpProxy == nil { |
| 79 | mergedProxy.HttpProxy = clusterConfig.HttpProxy |
| 80 | } |
| 81 | if mergedProxy.HttpsProxy == nil { |
| 82 | mergedProxy.HttpsProxy = clusterConfig.HttpsProxy |
| 83 | } |
| 84 | if mergedProxy.NoProxy == nil { |
| 85 | mergedProxy.NoProxy = clusterConfig.NoProxy |
| 86 | } else if *mergedProxy.NoProxy != "" { |
| 87 | // Merge noProxy fields, joining with a comma |
| 88 | if clusterConfig.NoProxy != nil { |
| 89 | noProxy := fmt.Sprintf("%s,%s", *clusterConfig.NoProxy, *operatorConfig.NoProxy) |
| 90 | mergedProxy.NoProxy = &noProxy |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return removeEmptyStrings(mergedProxy) |
| 95 | } |
| 96 | |
| 97 | // removeEmptyStrings is a utility function for removing empty fields from a proxy configuration. This is required |
| 98 | // to allow overriding |