From 540682d885cfb1db8afa299cb7491a916614749c Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 3 Apr 2024 15:42:25 -0400 Subject: [PATCH] Move HTTP proxy code to a public package Signed-off-by: Tom Pantelis --- controllers/submariner/gateway_resources.go | 3 ++- controllers/submariner/globalnet_resources.go | 3 ++- controllers/submariner/metrics_proxy_resources.go | 3 ++- controllers/submariner/route_agent_resources.go | 5 +++-- {controllers/submariner => pkg/httpproxy}/proxy.go | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) rename {controllers/submariner => pkg/httpproxy}/proxy.go (93%) diff --git a/controllers/submariner/gateway_resources.go b/controllers/submariner/gateway_resources.go index c1ef02b70..98eb59f26 100644 --- a/controllers/submariner/gateway_resources.go +++ b/controllers/submariner/gateway_resources.go @@ -30,6 +30,7 @@ import ( "github.com/submariner-io/submariner-operator/api/v1alpha1" "github.com/submariner-io/submariner-operator/controllers/apply" "github.com/submariner-io/submariner-operator/controllers/metrics" + "github.com/submariner-io/submariner-operator/pkg/httpproxy" "github.com/submariner-io/submariner-operator/pkg/images" opnames "github.com/submariner-io/submariner-operator/pkg/names" submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1" @@ -180,7 +181,7 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe Protocol: corev1.ProtocolUDP, }, }, - Env: addHTTPProxyEnvVars([]corev1.EnvVar{ + Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace}, {Name: "SUBMARINER_CLUSTERCIDR", Value: cr.Status.ClusterCIDR}, {Name: "SUBMARINER_SERVICECIDR", Value: cr.Status.ServiceCIDR}, diff --git a/controllers/submariner/globalnet_resources.go b/controllers/submariner/globalnet_resources.go index 69a417ddb..bd0b46007 100644 --- a/controllers/submariner/globalnet_resources.go +++ b/controllers/submariner/globalnet_resources.go @@ -26,6 +26,7 @@ import ( "github.com/submariner-io/submariner-operator/api/v1alpha1" "github.com/submariner-io/submariner-operator/controllers/apply" "github.com/submariner-io/submariner-operator/controllers/metrics" + "github.com/submariner-io/submariner-operator/pkg/httpproxy" "github.com/submariner-io/submariner-operator/pkg/images" opnames "github.com/submariner-io/submariner-operator/pkg/names" appsv1 "k8s.io/api/apps/v1" @@ -90,7 +91,7 @@ func newGlobalnetDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.DaemonS VolumeMounts: []corev1.VolumeMount{ {Name: "host-run-xtables-lock", MountPath: "/run/xtables.lock"}, }, - Env: addHTTPProxyEnvVars([]corev1.EnvVar{ + Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace}, {Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID}, {Name: "SUBMARINER_METRICSPORT", Value: globalnetMetricsServerPort}, diff --git a/controllers/submariner/metrics_proxy_resources.go b/controllers/submariner/metrics_proxy_resources.go index 112f54ca6..a6213564b 100644 --- a/controllers/submariner/metrics_proxy_resources.go +++ b/controllers/submariner/metrics_proxy_resources.go @@ -26,6 +26,7 @@ import ( "github.com/submariner-io/admiral/pkg/names" "github.com/submariner-io/submariner-operator/api/v1alpha1" "github.com/submariner-io/submariner-operator/controllers/apply" + "github.com/submariner-io/submariner-operator/pkg/httpproxy" "github.com/submariner-io/submariner-operator/pkg/images" opnames "github.com/submariner-io/submariner-operator/pkg/names" appsv1 "k8s.io/api/apps/v1" @@ -85,7 +86,7 @@ func metricProxyContainer(cr *v1alpha1.Submariner, name, hostPort, podPort strin Name: name, Image: getImagePath(cr, opnames.MetricsProxyImage, names.MetricsProxyComponent), ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.MetricsProxyComponent]), - Env: addHTTPProxyEnvVars([]corev1.EnvVar{ + Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "NODE_IP", ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ FieldPath: "status.hostIP", diff --git a/controllers/submariner/route_agent_resources.go b/controllers/submariner/route_agent_resources.go index 519d637d9..8095e5cf4 100644 --- a/controllers/submariner/route_agent_resources.go +++ b/controllers/submariner/route_agent_resources.go @@ -26,6 +26,7 @@ import ( "github.com/submariner-io/admiral/pkg/names" "github.com/submariner-io/submariner-operator/api/v1alpha1" "github.com/submariner-io/submariner-operator/controllers/apply" + "github.com/submariner-io/submariner-operator/pkg/httpproxy" "github.com/submariner-io/submariner-operator/pkg/images" opnames "github.com/submariner-io/submariner-operator/pkg/names" appsv1 "k8s.io/api/apps/v1" @@ -98,7 +99,7 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.Daemon Image: getImagePath(cr, opnames.RouteAgentImage, names.RouteAgentComponent), ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.RouteAgentComponent]), Command: []string{"submariner-route-agent.sh"}, - Env: addHTTPProxyEnvVars([]corev1.EnvVar{ + Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "SUBMARINER_WAITFORNODE", Value: "true"}, {Name: "NODE_NAME", ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ @@ -128,7 +129,7 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.Daemon {Name: "host-run-openvswitch", MountPath: "/run/openvswitch"}, {Name: "host-run-ovn-ic", MountPath: "/run/ovn-ic"}, }, - Env: addHTTPProxyEnvVars([]corev1.EnvVar{ + Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace}, {Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID}, {Name: "SUBMARINER_DEBUG", Value: strconv.FormatBool(cr.Spec.Debug)}, diff --git a/controllers/submariner/proxy.go b/pkg/httpproxy/proxy.go similarity index 93% rename from controllers/submariner/proxy.go rename to pkg/httpproxy/proxy.go index cefd37ac8..abc904742 100644 --- a/controllers/submariner/proxy.go +++ b/pkg/httpproxy/proxy.go @@ -16,14 +16,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package submariner +package httpproxy import ( "golang.org/x/net/http/httpproxy" corev1 "k8s.io/api/core/v1" ) -func addHTTPProxyEnvVars(vars []corev1.EnvVar) []corev1.EnvVar { +func AddEnvVars(vars []corev1.EnvVar) []corev1.EnvVar { proxyEnv := httpproxy.FromEnvironment() vars = appendEnvVarIfValue(vars, "HTTP_PROXY", proxyEnv.HTTPProxy) vars = appendEnvVarIfValue(vars, "HTTPS_PROXY", proxyEnv.HTTPSProxy)