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

Revise port-forward behaviour #5554

Merged

Conversation

briandealwis
Copy link
Member

@briandealwis briandealwis commented Mar 16, 2021

Fixes #4163
Related: #4832
Merge after: #5548, #5632 (support for SliceValue)

Description
This PR refactors our port-forward behaviour to implement the design in #4832. At its heart:

  • Skaffold introduces classes of port-forwards: user for user-defined port-forwards as expressed in the skaffold.yaml, services for deployed services, debug for debug ports, and pods for all container ports on pods.
  • --port-forward=off disables all port-forwarding (or any boolean value accepted by Go)
  • Skaffold now forwards user-defined port-forwards by default for dev and debug (vs previously required --port-forward). run and deploy default to off as before.
  • --port-forward forwards user, and services like before. When used with debug, it will also forward debugging ports too. aka --port-forward=true or =compat.
  • --port-forward=a,b,c allows a combination of classes to include

This is mostly refactoring work in the port-forwarding implementation:

  • I separated the NewResourceForwarder into a NewUserDefinedForwarder and NewServicesForwarder
  • debug is a subset of pods so I switched up NewWatchingPodForwarder to take a port filter for filtering the containerPorts.

User facing changes (remove if N/A)
Skaffold now enables user-defined port-forwards in skaffold.yaml by default; use --port-forward=off to disable entirely.

Follow-up Work (remove if N/A)
Provide a way to configure this with the global config.

Turns out pflag supports a NoOptDefValue flag to provide a default
value when there is no flag value (e.g., `--port-forward`) which
means we can support all of our changes into `--port-forward` and
avoid a new flag.

Split out resource-forwarding and user-defined forwarding.
@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #5554 (8d47638) into master (365b6d4) will decrease coverage by 0.00%.
The diff coverage is 68.80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5554      +/-   ##
==========================================
- Coverage   70.64%   70.63%   -0.01%     
==========================================
  Files         410      411       +1     
  Lines       15676    15773      +97     
==========================================
+ Hits        11074    11142      +68     
- Misses       3790     3811      +21     
- Partials      812      820       +8     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/debug.go 100.00% <ø> (ø)
cmd/skaffold/app/cmd/flags.go 88.60% <ø> (ø)
pkg/skaffold/config/options.go 100.00% <ø> (ø)
pkg/skaffold/runner/portforwarder.go 20.00% <0.00%> (-2.23%) ⬇️
...affold/kubernetes/portforward/forwarder_manager.go 33.33% <33.33%> (+6.66%) ⬆️
...ffold/kubernetes/portforward/resource_forwarder.go 87.27% <80.00%> (+1.55%) ⬆️
pkg/skaffold/config/portforward.go 80.30% <80.30%> (ø)
...g/skaffold/kubernetes/portforward/pod_forwarder.go 82.35% <100.00%> (+0.35%) ⬆️
pkg/skaffold/runner/runcontext/context.go 79.46% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 365b6d4...8d47638. Read the comment docs.

Copy link
Contributor

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

Changes look good to me except for a couple of suggestions and nits.

I found compat very hard for me to understand. Is it a known shorthand for backward compatibility?
I see you don't have compat in the flag help but except it as a valid arg the Validate() function.
Exposing compat to user is a bit odd if you do plan to.

func debugPorts(pod *v1.Pod, c v1.Container) []v1.ContainerPort {
var ports []v1.ContainerPort

annot, found := pod.ObjectMeta.Annotations[debugging.DebugConfigAnnotation]
Copy link
Contributor

@tejal29 tejal29 Mar 18, 2021

Choose a reason for hiding this comment

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

Not related to this PR, but curious about why are we using pod annotations to store debug configurations?
Is it only for IDEs? DO you know if IDES do use this metadata and if yes is can we instead stick debug metadata in the new proposed metadata API.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's there for tooling to consume. Funnily enough, the major consumer is Skaffold itself which monitors for debuggable pods and turns them into DebuggingContainerEvent:

func (d *ContainerManager) checkPod(pod *v1.Pod) {
debugConfigString, found := pod.Annotations[debug.DebugConfigAnnotation]

(what's the new metadata api?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry missed responding to this.
re: whats is the new metadata API.

For event API V2, there are some changes suggested by VSC to add additional metadata for driving the proposed new view. Skaffold does have a MetaData or GetState endpoint which we are thinking of revamping.

@briandealwis briandealwis added kokoro:force-run forces a kokoro re-run on a PR and removed kokoro:force-run forces a kokoro re-run on a PR labels Apr 12, 2021
@briandealwis
Copy link
Member Author

Committing: Kokoro is having some issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes kokoro:force-run forces a kokoro re-run on a PR size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the default behavior to forward ports?
4 participants