Skip to content

Commit

Permalink
Create topology flag to proxy only kubectl traffic through HTTPProxy (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartbutler authored Jul 12, 2022
1 parent e4e4000 commit a933bd8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
5 changes: 5 additions & 0 deletions pkg/test/framework/components/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ type Cluster interface {
// Metadata returns the value for a given metadata key for the cluster.
// If the key is not found in the cluster metadata, an empty string is returned.
MetadataValue(key string) string

// ProxyKubectlOnly returns a boolean value to indicate whether all traffic
// should route through the HTTP proxy or only Kubectl traffic. (Useful
// in topologies where the API server is private but the ingress is public).
ProxyKubectlOnly() bool
}
1 change: 1 addition & 0 deletions pkg/test/framework/components/cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
Name string `yaml:"clusterName,omitempty"`
Network string `yaml:"network,omitempty"`
HTTPProxy string `yaml:"httpProxy,omitempty"`
ProxyKubectlOnly bool `yaml:"proxyKubectlOnly,omitempty"`
PrimaryClusterName string `yaml:"primaryClusterName,omitempty"`
ConfigClusterName string `yaml:"configClusterName,omitempty"`
Meta config.Map `yaml:"meta,omitempty"`
Expand Down
41 changes: 24 additions & 17 deletions pkg/test/framework/components/cluster/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,30 @@ type Map = map[string]Cluster

func NewTopology(config Config, allClusters Map) Topology {
return Topology{
ClusterName: config.Name,
ClusterKind: config.Kind,
Network: config.Network,
ClusterHTTPProxy: config.HTTPProxy,
PrimaryClusterName: config.PrimaryClusterName,
ConfigClusterName: config.ConfigClusterName,
AllClusters: allClusters,
Index: len(allClusters),
ConfigMetadata: config.Meta,
ClusterName: config.Name,
ClusterKind: config.Kind,
Network: config.Network,
ClusterHTTPProxy: config.HTTPProxy,
PrimaryClusterName: config.PrimaryClusterName,
ConfigClusterName: config.ConfigClusterName,
ClusterProxyKubectlOnly: config.ProxyKubectlOnly,
AllClusters: allClusters,
Index: len(allClusters),
ConfigMetadata: config.Meta,
}
}

// Topology gives information about the relationship between clusters.
// Cluster implementations can embed this struct to include common functionality.
type Topology struct {
ClusterName string
ClusterKind Kind
Network string
ClusterHTTPProxy string
PrimaryClusterName string
ConfigClusterName string
Index int
ClusterName string
ClusterKind Kind
Network string
ClusterHTTPProxy string
PrimaryClusterName string
ConfigClusterName string
ClusterProxyKubectlOnly bool
Index int
// AllClusters should contain all AllClusters in the context
AllClusters Map
ConfigMetadata config.Map
Expand All @@ -75,6 +77,10 @@ func (c Topology) HTTPProxy() string {
return c.ClusterHTTPProxy
}

func (c Topology) ProxyKubectlOnly() bool {
return c.ClusterProxyKubectlOnly
}

// knownClusterNames maintains a well-known set of cluster names. These will always be used with
// StableNames if encountered.
var knownClusterNames = map[string]struct{}{
Expand Down Expand Up @@ -195,7 +201,8 @@ func (c Topology) String() string {
_, _ = fmt.Fprintf(buf, "PrimaryCluster: %s\n", c.Primary().Name())
_, _ = fmt.Fprintf(buf, "ConfigCluster: %s\n", c.Config().Name())
_, _ = fmt.Fprintf(buf, "Network: %s\n", c.NetworkName())
_, _ = fmt.Fprintf(buf, "HTTPProxy: %s\n", c.HTTPProxy())
_, _ = fmt.Fprintf(buf, "HTTPProxy: %s\n", c.HTTPProxy())
_, _ = fmt.Fprintf(buf, "ProxyKubectlOnly: %t\n", c.ProxyKubectlOnly())

return buf.String()
}
2 changes: 1 addition & 1 deletion pkg/test/framework/components/istio/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (c *ingressImpl) callEcho(opts echo.CallOptions) (echo.CallResult, error) {
if host := opts.GetHost(); len(host) > 0 {
opts.HTTP.Headers.Set(headers.Host, host)
}
if len(c.cluster.HTTPProxy()) > 0 {
if len(c.cluster.HTTPProxy()) > 0 && !c.cluster.ProxyKubectlOnly() {
opts.HTTP.HTTPProxy = c.cluster.HTTPProxy()
}
return c.caller.CallEcho(c, opts)
Expand Down

0 comments on commit a933bd8

Please sign in to comment.