Skip to content

Commit

Permalink
Move HTTP proxy code to a public package
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Apr 15, 2024
1 parent 387eaee commit 540682d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion controllers/submariner/gateway_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
3 changes: 2 additions & 1 deletion controllers/submariner/globalnet_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
3 changes: 2 additions & 1 deletion controllers/submariner/metrics_proxy_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/route_agent_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)},
Expand Down
4 changes: 2 additions & 2 deletions controllers/submariner/proxy.go → pkg/httpproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 540682d

Please sign in to comment.