Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit af76f69

Browse files
committedFeb 28, 2023
Fix issues with IgnoreLocalhost on Podman upon local file changes
This makes sure we pass the value of the IgnoreLocalhost flag to the watch handler
1 parent 006885b commit af76f69

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed
 

‎pkg/dev/podmandev/podmandev.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (o *DevClient) Start(
107107
DevfileRunCmd: options.RunCommand,
108108
Variables: options.Variables,
109109
RandomPorts: options.RandomPorts,
110+
IgnoreLocalhost: options.IgnoreLocalhost,
110111
WatchFiles: options.WatchFiles,
111112
WatchCluster: false,
112113
Out: out,
@@ -188,13 +189,14 @@ func (o *DevClient) watchHandler(ctx context.Context, pushParams adapters.PushPa
188189
printWarningsOnDevfileChanges(ctx, watchParams)
189190

190191
startOptions := dev.StartOptions{
191-
IgnorePaths: watchParams.FileIgnores,
192-
Debug: watchParams.Debug,
193-
BuildCommand: watchParams.DevfileBuildCmd,
194-
RunCommand: watchParams.DevfileRunCmd,
195-
RandomPorts: watchParams.RandomPorts,
196-
WatchFiles: watchParams.WatchFiles,
197-
Variables: watchParams.Variables,
192+
IgnorePaths: watchParams.FileIgnores,
193+
Debug: watchParams.Debug,
194+
BuildCommand: watchParams.DevfileBuildCmd,
195+
RunCommand: watchParams.DevfileRunCmd,
196+
RandomPorts: watchParams.RandomPorts,
197+
IgnoreLocalhost: watchParams.IgnoreLocalhost,
198+
WatchFiles: watchParams.WatchFiles,
199+
Variables: watchParams.Variables,
198200
}
199201
return o.reconcile(ctx, watchParams.Out, watchParams.ErrOut, startOptions, componentStatus)
200202
}

‎pkg/watch/watch.go

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ type WatchParameters struct {
9090
Variables map[string]string
9191
// RandomPorts is true to forward containers ports on local random ports
9292
RandomPorts bool
93+
// IgnoreLocalhost indicates whether to proceed with port-forwarding regardless of any container ports being bound to the container loopback interface.
94+
// Applicable to Podman only.
95+
IgnoreLocalhost bool
9396
// WatchFiles indicates to watch for file changes and sync changes to the container
9497
WatchFiles bool
9598
// WatchCluster indicates to watch Cluster-related objects (Deployment, Pod, etc)

‎tests/integration/cmd_dev_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -3466,6 +3466,36 @@ CMD ["npm", "start"]
34663466
}).Should(HaveOccurred())
34673467
})
34683468
})
3469+
3470+
When("making changes in the project source code during the dev session", func() {
3471+
BeforeEach(func() {
3472+
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "Hello from", "Hiya from the updated")
3473+
var err error
3474+
var bErr []byte
3475+
_, bErr, ports, err = devSession.WaitSync()
3476+
Expect(err).ShouldNot(HaveOccurred())
3477+
stderr = string(bErr)
3478+
})
3479+
3480+
It("should port-forward successfully", func() {
3481+
By("displaying warning message for loopback port", func() {
3482+
Expect(stderr).Should(ContainSubstring("Detected that the following port(s) can be reached only via the container loopback interface: admin (3001)"))
3483+
})
3484+
By("reaching the local port for the non-loopback interface", func() {
3485+
Eventually(func(g Gomega) {
3486+
g.Expect(ports["3000"]).Should(haveHttpResponse(http.StatusOK, "Hiya from the updated Node.js Application!"))
3487+
}).WithTimeout(60 * time.Second).WithPolling(3 * time.Second).Should(Succeed())
3488+
})
3489+
By("not succeeding to reach the local port for the loopback interface", func() {
3490+
// By design, Podman will not forward to container apps listening on localhost.
3491+
// See https://github.com/redhat-developer/odo/issues/6510 and https://github.com/containers/podman/issues/17353
3492+
Consistently(func() error {
3493+
_, err := http.Get("http://" + ports["3001"])
3494+
return err
3495+
}).Should(HaveOccurred())
3496+
})
3497+
})
3498+
})
34693499
})
34703500
})
34713501

0 commit comments

Comments
 (0)
Please sign in to comment.