Skip to content

Commit

Permalink
Display warnings instead if the ports are not opened
Browse files Browse the repository at this point in the history
While iterating on the application, it might feel
weird to stop the Dev Session immediately.
Plus, a lot of integration tests are not passing because
of source code not strictly matching the ports declared in the
(too many) Devfiles.
  • Loading branch information
rm3l committed Mar 31, 2023
1 parent 2683679 commit c205ece
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions pkg/dev/podmandev/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@ func (o *DevClient) reconcile(

// Check that the application is actually listening on the ports declared in the Devfile, so we are sure that port-forwarding will work
appReadySpinner := log.Spinner("Waiting for the application to be ready")
defer appReadySpinner.End(false)
err = o.checkAppPorts(pod.Name, fwPorts)
err = o.checkAppPorts(ctx, pod.Name, fwPorts)
appReadySpinner.End(err == nil)
if err != nil {
return err
log.Warningf("port-forwarding might not work correctly: %v", err)
}
appReadySpinner.End(true)

// By default, Podman will not forward to container applications listening on the loopback interface.
// So we are trying to detect such cases and act accordingly.
Expand Down Expand Up @@ -225,12 +224,12 @@ func (o *DevClient) deployPod(ctx context.Context, options dev.StartOptions) (*c
return pod, fwPorts, nil
}

func (o *DevClient) checkAppPorts(podName string, portsToFwd []api.ForwardedPort) error {
func (o *DevClient) checkAppPorts(ctx context.Context, podName string, portsToFwd []api.ForwardedPort) error {
containerPortsMapping := make(map[string][]int)
for _, p := range portsToFwd {
containerPortsMapping[p.ContainerName] = append(containerPortsMapping[p.ContainerName], p.ContainerPort)
}
return port.CheckAppPortsListening(o.execClient, podName, containerPortsMapping, 1*time.Minute)
return port.CheckAppPortsListening(ctx, o.execClient, podName, containerPortsMapping, 1*time.Minute)
}

// handleLoopbackPorts tries to detect if any of the ports to forward (in fwPorts) is actually bound to the loopback interface within the specified pod.
Expand Down
11 changes: 5 additions & 6 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,11 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c

// Check that the application is actually listening on the ports declared in the Devfile, so we are sure that port-forwarding will work
appReadySpinner := log.Spinner("Waiting for the application to be ready")
defer appReadySpinner.End(false)
err = a.checkAppPorts(pod.Name, portsToForward)
err = a.checkAppPorts(ctx, pod.Name, portsToForward)
appReadySpinner.End(err == nil)
if err != nil {
return err
log.Warningf("port-forwarding might not work correctly: %v", err)
}
appReadySpinner.End(true)

err = a.portForwardClient.StartPortForwarding(a.Devfile, a.ComponentName, parameters.Debug, parameters.RandomPorts, log.GetStdout(), parameters.ErrOut, nil)
if err != nil {
Expand Down Expand Up @@ -766,14 +765,14 @@ func (a Adapter) deleteServiceBindingSecrets(serviceBindingSecretsToRemove []uns
return nil
}

func (a *Adapter) checkAppPorts(podName string, portsToFwd map[string][]devfilev1.Endpoint) error {
func (a *Adapter) checkAppPorts(ctx context.Context, podName string, portsToFwd map[string][]devfilev1.Endpoint) error {
containerPortsMapping := make(map[string][]int)
for c, ports := range portsToFwd {
for _, p := range ports {
containerPortsMapping[c] = append(containerPortsMapping[c], p.TargetPort)
}
}
return port.CheckAppPortsListening(a.execClient, podName, containerPortsMapping, 1*time.Minute)
return port.CheckAppPortsListening(ctx, a.execClient, podName, containerPortsMapping, 1*time.Minute)
}

// PushCommandsMap stores the commands to be executed as per their types.
Expand Down

0 comments on commit c205ece

Please sign in to comment.