Skip to content

Commit

Permalink
test: fix user namespace test, TPM2 fixes
Browse files Browse the repository at this point in the history
Make sure the test runs on a specific node, wait for swtpm to be up.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Dec 9, 2024
1 parent c3537b2 commit 707a77b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/integration/k8s/testdata/usernamespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
namespace: default
spec:
hostUsers: false
nodeName: $NODE$
containers:
- name: userns
command: ["/bin/sh", "-c", "--"]
Expand Down
8 changes: 7 additions & 1 deletion internal/integration/k8s/usernamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ func (suite *UserNamespaceSuite) TestUserNamespace() {
}
}

usernamespacePodManifest := suite.ParseManifests(userNamespacePodSpec)
k8sNode, err := suite.GetK8sNodeByInternalIP(ctx, node)
suite.Require().NoError(err)

suite.T().Logf("testing k8s user namespace on node %q (%q)", node, k8sNode.Name)

// bind the pod to the node
usernamespacePodManifest := suite.ParseManifests(bytes.ReplaceAll(userNamespacePodSpec, []byte("$NODE$"), []byte(k8sNode.Name)))

suite.T().Cleanup(func() {
cleanUpCtx, cleanupCancel := context.WithTimeout(context.Background(), time.Minute)
Expand Down
23 changes: 23 additions & 0 deletions pkg/provision/providers/qemu/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/alexflint/go-filemutex"
"github.com/containernetworking/cni/libcni"
Expand Down Expand Up @@ -428,6 +429,10 @@ func launchVM(config *LaunchConfig) error {
return err
}

if err := waitForFileToExist(tpm2SocketPath, 5*time.Second); err != nil {
return err
}

args = append(args,
config.ArchitectureData.TPMDeviceArgs(tpm2SocketPath)...,
)
Expand Down Expand Up @@ -565,3 +570,21 @@ func Launch() error {
}
})
}

func waitForFileToExist(path string, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

for {
select {
case <-ctx.Done():
return ctx.Err()
default:
if _, err := os.Stat(path); err == nil {
return nil
}
}

time.Sleep(100 * time.Millisecond)
}
}

0 comments on commit 707a77b

Please sign in to comment.