From a7592d705d9628ee3a7142cf28790a53f87ec5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Gardfj=C3=A4ll?= Date: Thu, 11 Jan 2024 10:55:08 +0100 Subject: [PATCH] add Test_InterceptMountReplace integration test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter GardfjÀll --- integration_test/intercept_mount_test.go | 39 ++++++++++++++++++++++++ pkg/agentconfig/container.go | 4 --- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/integration_test/intercept_mount_test.go b/integration_test/intercept_mount_test.go index 8b74036dc2..cb84ae3358 100644 --- a/integration_test/intercept_mount_test.go +++ b/integration_test/intercept_mount_test.go @@ -134,6 +134,45 @@ func (s *singleServiceSuite) Test_InterceptMountRelative() { require.True(st.IsDir(), "/var is not a directory") } +// Verifies proper forwarding of volume mounts when running a telepresence intercept with the +// "--replace" flag. +func (s *singleServiceSuite) Test_InterceptMountReplace() { + if runtime.GOOS == "darwin" { + s.T().Skip("Mount tests don't run on darwin due to macFUSE issues") + } + if runtime.GOOS == "windows" { + s.T().Skip("Windows mount on driver letters. Relative mounts are not possible") + } + require := s.Require() + + ctx := s.Context() + port, cancel := itest.StartLocalHttpEchoServer(ctx, s.ServiceName()) + defer cancel() + + mountPoint, err := os.MkdirTemp("", "mount-") // Don't use the testing.Tempdir() because deletion is delayed. + require.NoError(err) + ctx = itest.WithWorkingDir(ctx, mountPoint) + stdout := itest.TelepresenceOk(ctx, + "intercept", "--replace", s.ServiceName(), "--mount", mountPoint, "--port", strconv.Itoa(port)) + defer func() { + itest.TelepresenceOk(ctx, "leave", s.ServiceName()) + }() + s.Contains(stdout, "Using Deployment "+s.ServiceName()) + + s.Eventually(func() bool { + stdout, _, err := itest.Telepresence(ctx, "list", "--intercepts") + return err == nil && regexp.MustCompile(s.ServiceName()+`\s*: intercepted`).MatchString(stdout) + }, 10*time.Second, time.Second) + + time.Sleep(200 * time.Millisecond) // List is really fast now, so give the mount some time to become effective + st, err := os.Stat(mountPoint) + require.NoError(err, "Stat on failed") + require.True(st.IsDir(), "Mount point is not a directory") + st, err = os.Stat(filepath.Join(mountPoint, "var")) + require.NoError(err, "Stat on /var failed") + require.True(st.IsDir(), "/var is not a directory") +} + func (s *singleServiceSuite) Test_InterceptDetailedOutput() { ctx := s.Context() port, cancel := itest.StartLocalHttpEchoServer(ctx, s.ServiceName()) diff --git a/pkg/agentconfig/container.go b/pkg/agentconfig/container.go index 00883f5678..38c1e26f26 100644 --- a/pkg/agentconfig/container.go +++ b/pkg/agentconfig/container.go @@ -73,13 +73,9 @@ func AgentContainer( dlog.Errorf(ctx, "unable to parse agent version from image name %s", config.AgentImage) } } - // TODO could this be where we get volumes wrong? - dlog.Debugf(ctx, "looking for volume mounts on pod %s.%s ...", pod.Name, pod.Namespace) EachContainer(pod, config, func(app *core.Container, cc *Container) { var volPaths []string - dlog.Debugf(ctx, "looking for volume mounts on container %s ...", cc.Name) volPaths, mounts = appendAppContainerVolumeMounts(app, cc, mounts, pod.ObjectMeta.Annotations, agentVersion) - dlog.Debugf(ctx, "found %d volume mounts on container %s: %v", len(volPaths), cc.Name, volPaths) if len(volPaths) > 0 { evs = append(evs, core.EnvVar{ Name: cc.EnvPrefix + EnvInterceptMounts,