Skip to content

Commit

Permalink
🐛 route container resolving via http proxy (#1078)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Mar 28, 2024
1 parent d106522 commit 2fc0368
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions controllers/mondoooperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ package controllers
import (
"context"
"fmt"
"net"
"net/http"
"net/url"
"time"

"github.com/google/go-containerregistry/pkg/v1/remote"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -54,6 +59,27 @@ func (r *MondooOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl
return ctrl.Result{}, nil
}

if config.Spec.HttpProxy != nil {
urlParsed, err := url.Parse(*config.Spec.HttpProxy)
if err != nil {
return ctrl.Result{}, err
}
remote.DefaultTransport = &http.Transport{
Proxy: http.ProxyURL(urlParsed),
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
// We usually are dealing with 2 hosts (at most), split MaxIdleConns between them.
MaxIdleConnsPerHost: 50,
}
}

namespace, err := k8s.GetRunningNamespace()
if err != nil {
configLog.Error(err, "failed to know which namespace to target")
Expand Down

0 comments on commit 2fc0368

Please sign in to comment.