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

portforward: deprecate implicit container port behavior #5735

Merged
merged 3 commits into from
Apr 27, 2022

Conversation

milas
Copy link
Contributor

@milas milas commented Apr 26, 2022

Tilt supports a bunch of variations when defining a port forward in
a Tiltfile.

It's possible to specify a single value (a local port), and in this
case, Tilt will look for a matching exposed port to use. If none
is found, it'll use the first exposed port.

This behavior is confusing and doesn't match existing functionality
in e.g. kubectl.

Allowing a single port that will be used identically for local and
container is reasonable short-hand, but picking an implicit port
to map to adds extra complexity for questionable value.

In this latter case, a warning is now emitted along with the mapping
and instructions for the user to update their Tiltfile to make it
explicit before it breaks in a future release of Tilt.

To fully deprecate this, we can change the logic to always default
the container port to local port. However, as this will change the
behavior in the aforementioned case, it's a breaking change, so
let's provide a heads up first :)

Fixes #5728.

Tilt supports a bunch of variations when defining a port forward in
a Tiltfile.

It's possible to specify a single value (a local port), and in this
case, Tilt will look for a matching exposed port to use. If none
is found, it'll use the first exposed port.

This behavior is confusing and doesn't match existing functionality
in e.g. `kubectl`.

Allowing a single port that will be used identically for local and
container is reasonable short-hand, but picking an implicit port
to map to adds extra complexity for questionable value.

In this latter case, a warning is now emitted along with the mapping
and instructions for the user to update their `Tiltfile` to make it
explicit before it breaks in a future release of Tilt.

To fully deprecate this, we can change the logic to always default
the container port to local port. However, as this will change the
behavior in the aforementioned case, it's a breaking change, so
let's provide a heads up first :)

Fixes #5728.
@milas milas self-assigned this Apr 26, 2022
Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

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

a test would be nice, because this can be hard to reason about!

@@ -116,9 +121,12 @@ func (r *Reconciler) toDesiredPortForward(kd *v1alpha1.KubernetesDiscovery) (*v1
//
// TODO(nick): This is old legacy behavior, and I'm not totally sure it even
// makes sense. I wonder if we should just insist that ContainerPort is populated.
func populateContainerPorts(pf *v1alpha1.PortForward, pod *v1alpha1.Pod) {
func populateContainerPorts(pft *v1alpha1.PortForwardTemplateSpec, pod *v1alpha1.Pod) []v1alpha1.Forward {
Copy link
Member

Choose a reason for hiding this comment

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

do you expect that we will still want to print this warning after we change the default? is there any reason not to change the default now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, I was taking a fairly cautious approach here and adding the warning for now before changing the default. At that point, I could see an argument for keeping it to let users know that Tilt is now picking a different port than it would have in the past in this case, but that also might be overkill, e.g. when we remove deprecated functionality, we don't generally leave in a warning if someone tries to use it, we just error out.

@milas milas merged commit b15d85b into master Apr 27, 2022
@milas milas deleted the milas/implicit-pf-warning branch April 27, 2022 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing behavior with port forwards when no container port specified
3 participants