Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tunnel: Break dependency on k8s.io/kubernetes #376

Merged
merged 2 commits into from Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Expand Up @@ -103,10 +103,6 @@ required = [
name = "k8s.io/client-go"
branch = "release-9.0"

[[constraint]]
name = "k8s.io/kubernetes"
version = "1.15.1"

[[constraint]]
name = "github.com/json-iterator/go"
version = "1.1.5"
Expand Down
13 changes: 11 additions & 2 deletions modules/k8s/tunnel.go
Expand Up @@ -12,14 +12,14 @@ import (
"net"
"net/http"
"strconv"
"strings"
"sync"
"testing"

"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/portforward"
"k8s.io/client-go/transport/spdy"
"k8s.io/kubernetes/pkg/kubectl/generate"

"github.com/gruntwork-io/terratest/modules/logger"
)
Expand Down Expand Up @@ -47,6 +47,15 @@ func (resourceType KubeResourceType) String() string {
}
}

// makeLabels is a helper to format a map of label key and value pairs into a single string for use as a selector.
func makeLabels(labels map[string]string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment mentioning what this is doing, or alternatively point to where it is sourced from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment.

out := []string{}
for key, value := range labels {
out = append(out, fmt.Sprintf("%s=%s", key, value))
}
return strings.Join(out, ",")
}

// Tunnel is the main struct that configures and manages port forwading tunnels to Kubernetes resources.
type Tunnel struct {
out io.Writer
Expand Down Expand Up @@ -103,7 +112,7 @@ func (tunnel *Tunnel) getAttachablePodForServiceE(t *testing.T) (string, error)
if err != nil {
return "", err
}
selectorLabelsOfPods := generate.MakeLabels(service.Spec.Selector)
selectorLabelsOfPods := makeLabels(service.Spec.Selector)
servicePods, err := ListPodsE(t, tunnel.kubectlOptions, metav1.ListOptions{LabelSelector: selectorLabelsOfPods})
if err != nil {
return "", err
Expand Down