Skip to content

Commit

Permalink
add Test_InterceptMountReplace integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Gardfjäll <[email protected]>
  • Loading branch information
petergardfjall committed Jan 12, 2024
1 parent d9afc31 commit a7592d7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
39 changes: 39 additions & 0 deletions integration_test/intercept_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ func (s *singleServiceSuite) Test_InterceptMountRelative() {
require.True(st.IsDir(), "<mount point>/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 <mount point> failed")
require.True(st.IsDir(), "Mount point is not a directory")
st, err = os.Stat(filepath.Join(mountPoint, "var"))
require.NoError(err, "Stat on <mount point>/var failed")
require.True(st.IsDir(), "<mount point>/var is not a directory")
}

func (s *singleServiceSuite) Test_InterceptDetailedOutput() {
ctx := s.Context()
port, cancel := itest.StartLocalHttpEchoServer(ctx, s.ServiceName())
Expand Down
4 changes: 0 additions & 4 deletions pkg/agentconfig/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a7592d7

Please sign in to comment.