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

Add portName to the PortEvent payload of the event api #1855

Merged
merged 1 commit into from
Mar 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/skaffold/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func BuildComplete(imageName string) {
}

// PortForwarded notifies that a remote port has been forwarded locally.
func PortForwarded(localPort, remotePort int32, podName, containerName, namespace string) {
func PortForwarded(localPort, remotePort int32, podName, containerName, namespace string, portName string) {
handler.doHandle(&proto.Event{
EventType: &proto.Event_PortEvent{
PortEvent: &proto.PortEvent{
Expand All @@ -207,6 +207,7 @@ func PortForwarded(localPort, remotePort int32, podName, containerName, namespac
PodName: podName,
ContainerName: containerName,
Namespace: namespace,
PortName: portName,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestPortForwarded(t *testing.T) {
}

wait(t, func() bool { return handler.getState().ForwardedPorts["container"] == nil })
PortForwarded(8080, 8888, "pod", "container", "ns")
PortForwarded(8080, 8888, "pod", "container", "ns", "portname")
wait(t, func() bool { return handler.getState().ForwardedPorts["container"] != nil })
}

Expand Down
100 changes: 54 additions & 46 deletions pkg/skaffold/event/proto/skaffold.pb.go

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

1 change: 1 addition & 0 deletions pkg/skaffold/event/proto/skaffold.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ message PortEvent {
string podName = 3;
string containerName = 4;
string namespace = 5;
string portName = 6;
}

message LogEntry {
Expand Down
8 changes: 5 additions & 3 deletions pkg/skaffold/kubernetes/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type portForwardEntry struct {
podName string
namespace string
containerName string
portName string
port int32
localPort int32

Expand Down Expand Up @@ -94,7 +95,7 @@ func (*kubectlForwarder) Forward(parentCtx context.Context, pfe *portForwardEntr
return errors.Wrapf(err, "port forwarding pod: %s/%s, port: %d to local port: %d, err: %s", pfe.namespace, pfe.podName, pfe.port, pfe.localPort, buf.String())
}

event.PortForwarded(pfe.localPort, pfe.port, pfe.podName, pfe.containerName, pfe.namespace)
event.PortForwarded(pfe.localPort, pfe.port, pfe.podName, pfe.containerName, pfe.namespace, pfe.portName)

go cmd.Wait()

Expand Down Expand Up @@ -208,6 +209,7 @@ func (p *PortForwarder) getCurrentEntry(pod *v1.Pod, c v1.Container, port v1.Con
podName: pod.Name,
namespace: pod.Namespace,
containerName: c.Name,
portName: port.Name,
port: port.ContainerPort,
}
// If we have, return the current entry
Expand Down Expand Up @@ -241,10 +243,10 @@ func (p *PortForwarder) forward(ctx context.Context, entry *portForwardEntry) er

// Key is an identifier for the lock on a port during the skaffold dev cycle.
func (p *portForwardEntry) key() string {
return fmt.Sprintf("%s-%s-%s-%d", p.containerName, p.podName, p.namespace, p.port)
return fmt.Sprintf("%s-%s-%s-%s-%d", p.containerName, p.podName, p.namespace, p.portName, p.port)
}

// String is a utility function that returns the port forward entry as a user-readable string
func (p *portForwardEntry) String() string {
return fmt.Sprintf("%s/%s:%d", p.podName, p.containerName, p.port)
return fmt.Sprintf("%s/%s/%s:%d", p.podName, p.containerName, p.portName, p.port)
}
34 changes: 26 additions & 8 deletions pkg/skaffold/kubernetes/port_forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ func TestPortForwardPod(t *testing.T) {
},
availablePorts: []int{8080},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 1,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 8080,
},
Expand All @@ -110,6 +111,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -124,11 +126,12 @@ func TestPortForwardPod(t *testing.T) {
9000: true,
},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 1,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 9000,
},
Expand All @@ -148,6 +151,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand Down Expand Up @@ -176,6 +180,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -193,11 +198,12 @@ func TestPortForwardPod(t *testing.T) {
shouldErr: true,
availablePorts: []int{8080},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 1,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 8080,
},
Expand All @@ -216,6 +222,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -232,19 +239,21 @@ func TestPortForwardPod(t *testing.T) {
},
availablePorts: []int{8080, 50051},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 1,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 8080,
},
"containername2-podname2-namespace2-50051": {
"containername2-podname2-namespace2-portname2-50051": {
resourceVersion: 1,
podName: "podname2",
containerName: "containername2",
namespace: "namespace2",
portName: "portname2",
port: 50051,
localPort: 50051,
},
Expand All @@ -263,6 +272,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -282,6 +292,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 50051,
Name: "portname2",
},
},
},
Expand All @@ -298,19 +309,21 @@ func TestPortForwardPod(t *testing.T) {
},
availablePorts: []int{8080, 9000},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 1,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 8080,
},
"containername2-podname2-namespace2-8080": {
"containername2-podname2-namespace2-portname2-8080": {
resourceVersion: 1,
podName: "podname2",
containerName: "containername2",
namespace: "namespace2",
portName: "portname2",
port: 8080,
localPort: 9000,
},
Expand All @@ -329,6 +342,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -348,6 +362,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname2",
},
},
},
Expand All @@ -363,11 +378,12 @@ func TestPortForwardPod(t *testing.T) {
},
availablePorts: []int{8080},
expectedEntries: map[string]*portForwardEntry{
"containername-podname-namespace-8080": {
"containername-podname-namespace-portname-8080": {
resourceVersion: 2,
podName: "podname",
containerName: "containername",
namespace: "namespace",
portName: "portname",
port: 8080,
localPort: 8080,
},
Expand All @@ -386,6 +402,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand All @@ -405,6 +422,7 @@ func TestPortForwardPod(t *testing.T) {
Ports: []v1.ContainerPort{
{
ContainerPort: 8080,
Name: "portname",
},
},
},
Expand Down