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 resourceType and resourceName to PortForward event #2272

Merged
merged 3 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ const (
DefaultRPCHTTPPort = 50052
)

// ResourceType describes the Kubernetes resource types used for port forwarding
type ResourceType string

var (
Pod ResourceType = "pod"
)

var (
// Images is an environment variable key, whose value is an array of fully qualified image names passed in to a custom build script.
Images = "IMAGES"
Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func BuildComplete(imageName string) {
}

// PortForwarded notifies that a remote port has been forwarded locally.
func PortForwarded(localPort, remotePort int32, podName, containerName, namespace string, portName string) {
func PortForwarded(localPort, remotePort int32, podName, containerName, namespace string, portName string, resourceType, resourceName string) {
go handler.handle(&proto.Event{
EventType: &proto.Event_PortEvent{
PortEvent: &proto.PortEvent{
Expand All @@ -195,6 +195,8 @@ func PortForwarded(localPort, remotePort int32, podName, containerName, namespac
ContainerName: containerName,
Namespace: namespace,
PortName: portName,
ResourceType: resourceType,
ResourceName: resourceName,
},
},
})
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", "portname")
PortForwarded(8080, 8888, "pod", "container", "ns", "portname", "resourceType", "resourceName")
wait(t, func() bool { return handler.getState().ForwardedPorts["container"] != nil })
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/kubernetes/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
Expand Down Expand Up @@ -95,7 +96,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, pfe.portName)
event.PortForwarded(pfe.localPort, pfe.port, pfe.podName, pfe.containerName, pfe.namespace, pfe.portName, string(constants.Pod), pfe.podName)

go cmd.Wait()

Expand Down
Loading