Skip to content

Commit

Permalink
move HTTPTransport and proxy related code to its own package httpproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
cfergeau authored and praveenkumar committed Jun 9, 2023
1 parent 8e08162 commit deaf7e3
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 35 deletions.
6 changes: 3 additions & 3 deletions cmd/crc/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
crcErr "github.com/crc-org/crc/pkg/crc/errors"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/machine"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/preflight"
"github.com/crc-org/crc/pkg/crc/segment"
"github.com/crc-org/crc/pkg/crc/telemetry"
Expand Down Expand Up @@ -60,7 +60,7 @@ func init() {
}

// Initiate segment client
if segmentClient, err = segment.NewClient(config, network.HTTPTransport()); err != nil {
if segmentClient, err = segment.NewClient(config, httpproxy.HTTPTransport()); err != nil {
logging.Fatal(err.Error())
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func setProxyDefaults() error {
noProxy := config.Get(crcConfig.NoProxy).AsString()
proxyCAFile := config.Get(crcConfig.ProxyCAFile).AsString()

proxyConfig, err := network.NewProxyDefaults(httpProxy, httpsProxy, noProxy, proxyCAFile)
proxyConfig, err := httpproxy.NewProxyDefaults(httpProxy, httpsProxy, noProxy, proxyCAFile)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/machine/types"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/preflight"
"github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/crc/validation"
Expand Down Expand Up @@ -211,7 +212,7 @@ func checkIfNewVersionAvailable(noUpdateCheck bool) error {
}

func newVersionAvailable() (bool, string, string, error) {
release, err := crcversion.GetCRCLatestVersionFromMirror(network.HTTPTransport())
release, err := crcversion.GetCRCLatestVersionFromMirror(httpproxy.HTTPTransport())
if err != nil {
return false, "", "", err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/crc/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/errors"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/oc"
"github.com/crc-org/crc/pkg/crc/ssh"
crctls "github.com/crc-org/crc/pkg/crc/tls"
Expand Down Expand Up @@ -322,7 +322,7 @@ func EnsureClusterIDIsNotEmpty(ctx context.Context, ocConfig oc.Config) error {
return nil
}

func AddProxyConfigToCluster(ctx context.Context, sshRunner *ssh.Runner, ocConfig oc.Config, proxy *network.ProxyConfig) error {
func AddProxyConfigToCluster(ctx context.Context, sshRunner *ssh.Runner, ocConfig oc.Config, proxy *httpproxy.ProxyConfig) error {
type trustedCA struct {
Name string `json:"name"`
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func AddProxyConfigToCluster(ctx context.Context, sshRunner *ssh.Runner, ocConfi
return nil
}

func addProxyCACertToCluster(sshRunner *ssh.Runner, ocConfig oc.Config, proxy *network.ProxyConfig, trustedCAName string) error {
func addProxyCACertToCluster(sshRunner *ssh.Runner, ocConfig oc.Config, proxy *httpproxy.ProxyConfig, trustedCAName string) error {
proxyConfigMapFileName := fmt.Sprintf("/tmp/%s.json", trustedCAName)
proxyCABundleTemplate := `{
"apiVersion": "v1",
Expand Down Expand Up @@ -476,7 +476,7 @@ func DeleteOpenshiftAPIServerPods(ctx context.Context, ocConfig oc.Config) error
return errors.Retry(ctx, 60*time.Second, deleteOpenshiftAPIServerPods, time.Second)
}

func CheckProxySettingsForOperator(ocConfig oc.Config, proxy *network.ProxyConfig, deployment, namespace string) (bool, error) {
func CheckProxySettingsForOperator(ocConfig oc.Config, proxy *httpproxy.ProxyConfig, deployment, namespace string) (bool, error) {
if !proxy.IsEnabled() {
logging.Debugf("No proxy in use")
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/cluster/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"time"

"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
)

// WaitForClusterStable checks that the cluster is running a number of consecutive times
func WaitForClusterStable(ctx context.Context, ip string, kubeconfigFilePath string, proxy *network.ProxyConfig) error {
func WaitForClusterStable(ctx context.Context, ip string, kubeconfigFilePath string, proxy *httpproxy.ProxyConfig) error {
if ctx.Err() != nil {
return ctx.Err()
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/crc/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
crcpreset "github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/crc/validation"
"github.com/spf13/cast"
Expand Down Expand Up @@ -92,15 +92,15 @@ func validatePath(value interface{}) (bool, string) {

// validateHTTPProxy checks if given URI is valid for a HTTP proxy
func validateHTTPProxy(value interface{}) (bool, string) {
if err := network.ValidateProxyURL(cast.ToString(value), false); err != nil {
if err := httpproxy.ValidateProxyURL(cast.ToString(value), false); err != nil {
return false, err.Error()
}
return true, ""
}

// validateHTTPSProxy checks if given URI is valid for a HTTPS proxy
func validateHTTPSProxy(value interface{}) (bool, string) {
if err := network.ValidateProxyURL(cast.ToString(value), true); err != nil {
if err := httpproxy.ValidateProxyURL(cast.ToString(value), true); err != nil {
return false, err.Error()
}
return true, ""
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/machine/bundle/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/crc-org/crc/pkg/crc/gpg"
"github.com/crc-org/crc/pkg/crc/image"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
crcPreset "github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/download"
)
Expand Down Expand Up @@ -301,7 +301,7 @@ func getBundleDownloadInfo(preset crcPreset.Preset) (*download.RemoteFile, error
func getDefaultBundleVerifiedHash(preset crcPreset.Preset) (string, error) {
client := &http.Client{
Timeout: 5 * time.Second,
Transport: network.HTTPTransport(),
Transport: httpproxy.HTTPTransport(),
}
res, err := client.Get(constants.GetDefaultBundleSignedHashURL(preset))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/machine/fakemachine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/crc-org/crc/pkg/crc/machine/state"
"github.com/crc-org/crc/pkg/crc/machine/types"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/preset"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func (c *Client) GetConsoleURL() (*types.ConsoleResult, error) {
}, nil
}

func (c *Client) GetProxyConfig(machineName string) (*network.ProxyConfig, error) {
func (c *Client) GetProxyConfig(machineName string) (*httpproxy.ProxyConfig, error) {
return nil, errors.New("not implemented")
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/crc/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/machine/bundle"
"github.com/crc-org/crc/pkg/crc/machine/types"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/libmachine"
"github.com/crc-org/machine/libmachine/drivers"
)
Expand All @@ -17,7 +17,7 @@ func getClusterConfig(bundleInfo *bundle.CrcBundleInfo) (*types.ClusterConfig, e
if !bundleInfo.IsOpenShift() {
return &types.ClusterConfig{
ClusterType: bundleInfo.GetBundleType(),
ProxyConfig: &network.ProxyConfig{},
ProxyConfig: &httpproxy.ProxyConfig{},
}, nil
}

Expand Down Expand Up @@ -65,8 +65,8 @@ func createLibMachineClient() (libmachine.API, func()) {
}
}

func getProxyConfig(bundleInfo *bundle.CrcBundleInfo) (*network.ProxyConfig, error) {
proxy, err := network.NewProxyConfig()
func getProxyConfig(bundleInfo *bundle.CrcBundleInfo) (*httpproxy.ProxyConfig, error) {
proxy, err := httpproxy.NewProxyConfig()
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/crc-org/crc/pkg/crc/machine/state"
"github.com/crc-org/crc/pkg/crc/machine/types"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/oc"
"github.com/crc-org/crc/pkg/crc/podman"
crcPreset "github.com/crc-org/crc/pkg/crc/preset"
Expand Down Expand Up @@ -761,7 +762,7 @@ func copyKubeconfigFileWithUpdatedUserClientCertAndKey(selfSignedCAKey *rsa.Priv
return updateClientCrtAndKeyToKubeconfig(clientKey, clientCert, srcKubeConfigPath, dstKubeConfigPath)
}

func configurePodmanProxy(ctx context.Context, sshRunner *crcssh.Runner, proxy *network.ProxyConfig) (err error) {
func configurePodmanProxy(ctx context.Context, sshRunner *crcssh.Runner, proxy *httpproxy.ProxyConfig) (err error) {
if !proxy.IsEnabled() {
return nil
}
Expand Down Expand Up @@ -813,15 +814,15 @@ func configurePodmanProxy(ctx context.Context, sshRunner *crcssh.Runner, proxy *

}

func ensureProxyIsConfiguredInOpenShift(ctx context.Context, ocConfig oc.Config, sshRunner *crcssh.Runner, proxy *network.ProxyConfig) (err error) {
func ensureProxyIsConfiguredInOpenShift(ctx context.Context, ocConfig oc.Config, sshRunner *crcssh.Runner, proxy *httpproxy.ProxyConfig) (err error) {
if !proxy.IsEnabled() {
return nil
}
logging.Info("Adding proxy configuration to the cluster...")
return cluster.AddProxyConfigToCluster(ctx, sshRunner, ocConfig, proxy)
}

func waitForProxyPropagation(ctx context.Context, ocConfig oc.Config, proxyConfig *network.ProxyConfig) {
func waitForProxyPropagation(ctx context.Context, ocConfig oc.Config, proxyConfig *httpproxy.ProxyConfig) {
if !proxyConfig.IsEnabled() {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/machine/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"github.com/crc-org/crc/pkg/crc/cluster"
"github.com/crc-org/crc/pkg/crc/machine/state"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/preset"
crcpreset "github.com/crc-org/crc/pkg/crc/preset"
)
Expand Down Expand Up @@ -46,7 +46,7 @@ type ClusterConfig struct {
KubeAdminPass string
ClusterAPI string
WebConsoleURL string
ProxyConfig *network.ProxyConfig
ProxyConfig *httpproxy.ProxyConfig
}

type StartResult struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package httpproxy

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package httpproxy

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package httpproxy

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
crcConfig "github.com/crc-org/crc/pkg/crc/config"
"github.com/crc-org/crc/pkg/crc/constants"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/telemetry"
"github.com/crc-org/crc/pkg/crc/version"
crcos "github.com/crc-org/crc/pkg/os"
Expand Down Expand Up @@ -222,7 +222,7 @@ func addConfigTraits(c *crcConfig.Config, in analytics.Traits) analytics.Traits
}

func isProxyUsed() bool {
proxyConfig, err := network.NewProxyConfig()
proxyConfig, err := httpproxy.NewProxyConfig()
if err != nil {
return false
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/crc/services/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/crc-org/crc/pkg/crc/errors"
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/crc/services"
"github.com/crc-org/crc/pkg/crc/systemd"
"github.com/crc-org/crc/pkg/crc/systemd/states"
Expand Down Expand Up @@ -114,10 +115,10 @@ func CheckCRCLocalDNSReachable(ctx context.Context, serviceConfig services.Servi
func CheckCRCPublicDNSReachable(serviceConfig services.ServicePostStartConfig) (string, error) {
// This does not query DNS directly to account for corporate environment where external DNS resolution
// may only be done on the host running the http(s) proxies used for internet connectivity
proxyConfig, err := network.NewProxyConfig()
proxyConfig, err := httpproxy.NewProxyConfig()
if err != nil {
// try without using proxy
proxyConfig = &network.ProxyConfig{}
proxyConfig = &httpproxy.ProxyConfig{}
}
curlArgs := []string{"--head", publicDNSQueryURI}
if proxyConfig.IsEnabled() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/pkg/os/terminal"

"github.com/cavaliergopher/grab/v3"
Expand Down Expand Up @@ -61,7 +61,7 @@ func Download(uri, destination string, mode os.FileMode, sha256sum []byte) (stri
logging.Debugf("Downloading %s to %s", uri, destination)

client := grab.NewClient()
client.HTTPClient = &http.Client{Transport: network.HTTPTransport()}
client.HTTPClient = &http.Client{Transport: httpproxy.HTTPTransport()}
req, err := grab.NewRequest(destination, uri)
if err != nil {
return "", errors.Wrapf(err, "unable to get request from %s", uri)
Expand Down

0 comments on commit deaf7e3

Please sign in to comment.