Skip to content

Commit

Permalink
Remove deprecated selfLink dependency (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Aug 14, 2020
1 parent 6e17185 commit 37915d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/authproxy/auth_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (u *AuthProxy) Do(ctx context.Context, o Option) error {
portForwarderOption: portforwarder.Option{
Config: o.Config,
SourcePort: transitPort,
TargetPodURL: pod.GetSelfLink(),
TargetNamespace: pod.Namespace,
TargetPodName: pod.Name,
TargetContainerPort: containerPort,
},
reverseProxyOption: reverseproxy.Option{
Expand Down
19 changes: 12 additions & 7 deletions pkg/authproxy/auth_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func newTransport(t *testing.T) transport.NewFunc {
func TestAuthProxy_Do(t *testing.T) {
const containerPort = 18888
const transitPort = 28888
const podURL = "/api/v1/namespaces/kube-system/pods/kubernetes-dashboard-xxxxxxxx-xxxxxxxx"
pod := &v1.Pod{
ObjectMeta: v1meta.ObjectMeta{
SelfLink: podURL,
Name: "kubernetes-dashboard-12345678-12345678",
Namespace: "kubernetes-dashboard",
},
}

Expand Down Expand Up @@ -83,7 +83,8 @@ func TestAuthProxy_Do(t *testing.T) {
Run(portforwarder.Option{
Config: &restConfig,
SourcePort: transitPort,
TargetPodURL: podURL,
TargetNamespace: "kubernetes-dashboard",
TargetPodName: "kubernetes-dashboard-12345678-12345678",
TargetContainerPort: containerPort,
}, notNil, notNil).
DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
Expand Down Expand Up @@ -147,7 +148,8 @@ func TestAuthProxy_Do(t *testing.T) {
Run(portforwarder.Option{
Config: &restConfig,
SourcePort: transitPort,
TargetPodURL: podURL,
TargetNamespace: "kubernetes-dashboard",
TargetPodName: "kubernetes-dashboard-12345678-12345678",
TargetContainerPort: containerPort,
}, notNil, notNil).
DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
Expand Down Expand Up @@ -186,7 +188,8 @@ func TestAuthProxy_Do(t *testing.T) {
Run(portforwarder.Option{
Config: &restConfig,
SourcePort: transitPort,
TargetPodURL: podURL,
TargetNamespace: "kubernetes-dashboard",
TargetPodName: "kubernetes-dashboard-12345678-12345678",
TargetContainerPort: containerPort,
}, notNil, notNil).
DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
Expand Down Expand Up @@ -249,7 +252,8 @@ func TestAuthProxy_Do(t *testing.T) {
Run(portforwarder.Option{
Config: &restConfig,
SourcePort: transitPort,
TargetPodURL: podURL,
TargetNamespace: "kubernetes-dashboard",
TargetPodName: "kubernetes-dashboard-12345678-12345678",
TargetContainerPort: containerPort,
}, notNil, notNil).
DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
Expand Down Expand Up @@ -340,7 +344,8 @@ func TestAuthProxy_Do(t *testing.T) {
Run(portforwarder.Option{
Config: &restConfig,
SourcePort: transitPort,
TargetPodURL: podURL,
TargetNamespace: "kubernetes-dashboard",
TargetPodName: "kubernetes-dashboard-12345678-12345678",
TargetContainerPort: containerPort,
}, notNil, notNil).
DoAndReturn(func(o portforwarder.Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
Expand Down
5 changes: 3 additions & 2 deletions pkg/portforwarder/port_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var Set = wire.NewSet(
type Option struct {
Config *rest.Config
SourcePort int
TargetPodURL string
TargetNamespace string
TargetPodName string
TargetContainerPort int
}

Expand All @@ -44,7 +45,7 @@ type PortForwarder struct {
// It will close the readyChan when the port forwarder is ready.
// Caller can stop the port forwarder by closing the stopChan.
func (pf *PortForwarder) Run(o Option, readyChan chan struct{}, stopChan <-chan struct{}) error {
pfURL, err := url.Parse(o.Config.Host + o.TargetPodURL + "/portforward")
pfURL, err := url.Parse(fmt.Sprintf("%s/api/v1/namespaces/%s/pods/%s/portforward", o.Config.Host, o.TargetNamespace, o.TargetPodName))
if err != nil {
return xerrors.Errorf("could not build URL for portforward: %w", err)
}
Expand Down

0 comments on commit 37915d8

Please sign in to comment.