Skip to content

Commit

Permalink
Add option to disable proxy for kubernetes forwards
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Rose committed Sep 11, 2019
1 parent e0f210b commit 9a53b83
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/config/model.go
Expand Up @@ -94,7 +94,7 @@ type Forward struct {
// IsProxified indicates if the current forward rule will use the proxy
func (f *Forward) IsProxified() bool {
if value, ok := ProxifiedForwarders[f.Type]; ok && value {
return true
return !f.Values.DisableProxy
}

return false
Expand All @@ -107,6 +107,7 @@ type ForwardValues struct {
Labels map[string]string `yaml:"labels"`
Hostname string `yaml:"hostname"`
ProxyHostname string `yaml:"proxy_hostname"`
DisableProxy bool `yaml:"disable_proxy"`
Ports []string `yaml:"ports"`
Remote string `yaml:"remote"`
Args []string `yaml:"args"`
Expand Down
27 changes: 26 additions & 1 deletion pkg/config/model_test.go
Expand Up @@ -36,7 +36,7 @@ func TestApplicationGetPathWhenGoPath(t *testing.T) {
assert.Equal(t, "/tmp/gopath/src/fake.github.com/user/repository", path)
}

func TestForwardIsProxified(t *testing.T) {
func TestForwardTypeIsProxified(t *testing.T) {
// Given
testCases := []struct {
forwardType string
Expand All @@ -57,3 +57,28 @@ func TestForwardIsProxified(t *testing.T) {
assert.Equal(t, testCase.expected, forward.IsProxified())
}
}

func TestForwardConfigIsProxified(t *testing.T) {
// Given
testCases := []struct {
forwardType string
disableProxy bool
expected bool
}{
{forwardType: ForwarderKubernetes, disableProxy: false, expected: true},
{forwardType: ForwarderKubernetes, disableProxy: true, expected: false},
}

// When - Then
for _, testCase := range testCases {
values := ForwardValues{
DisableProxy: testCase.disableProxy,
}
forward := Forward{
Type: testCase.forwardType,
Values: values,
}

assert.Equal(t, testCase.expected, forward.IsProxified())
}
}
6 changes: 5 additions & 1 deletion pkg/forwarder/forwarder.go
Expand Up @@ -138,7 +138,11 @@ func (f *Forwarder) forward(forward *config.Forward, wg *sync.WaitGroup) {
switch forward.Type {
// Kubernetes local port-forward: give proxy port as local port and forwarded port, use proxy
case config.ForwarderKubernetes:
forwarder, err := kubernetes.NewForwarder(f.view, forward.Type, forward.Name, values.Context, values.Namespace, proxifiedPorts, values.Labels)
forwardPorts := values.Ports
if forward.IsProxified() {
forwardPorts = proxifiedPorts
}
forwarder, err := kubernetes.NewForwarder(f.view, forward.Type, forward.Name, values.Context, values.Namespace, forwardPorts, values.Labels)
if err != nil {
f.view.Writef("❌ %s\n", err.Error())
return
Expand Down

0 comments on commit 9a53b83

Please sign in to comment.