Skip to content

Commit 6c84577

Browse files
jcansecok8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
Fix issue with starting multiple test envs
When starting a single test environment [1], the control plane start-up logic [2] launches an etcd and kube-apiserver process. The start-up logic needs to bind these processes to multiple ports, and when none are configured in advance, the logic looks for unused ports, and then creates files in the user cache directory to reserve them (for example, [3]). However, the same logic used to reserve ports also has logic that deletes files corresponding to "outdated" ports [4]. Therefore, if there are multiple processes/threads starting a test environment, they may sometimes end up trying to delete the same file which causes a "file not found" error. This commit adds logic so that trying to start multiple test environments does not fail if more than one tries to delete the same file corresponding to an outdated port. [1] https://github.com/kubernetes-sigs/controller-runtime/blob/7fb8534b80339a5b8158cee3dc9e5f9439d679dc/pkg/envtest/server.go#L197 [2] https://github.com/kubernetes-sigs/controller-runtime/blob/7fb8534b80339a5b8158cee3dc9e5f9439d679dc/pkg/internal/testing/controlplane/plane.go#L49 [3] https://github.com/kubernetes-sigs/controller-runtime/blob/7fb8534b80339a5b8158cee3dc9e5f9439d679dc/pkg/internal/testing/controlplane/etcd.go#L120 [4] https://github.com/kubernetes-sigs/controller-runtime/blob/7fb8534b80339a5b8158cee3dc9e5f9439d679dc/pkg/internal/testing/addr/manager.go#L64
1 parent 1efdbd7 commit 6c84577

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/internal/testing/addr/manager.go

+10
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,20 @@ func (c *portCache) add(port int) (bool, error) {
7171
}
7272
info, err := d.Info()
7373
if err != nil {
74+
// No-op if file no longer exists; may have been deleted by another
75+
// process/thread trying to allocate ports.
76+
if errors.Is(err, fs.ErrNotExist) {
77+
return nil
78+
}
7479
return err
7580
}
7681
if time.Since(info.ModTime()) > portReserveTime {
7782
if err := os.Remove(filepath.Join(cacheDir, path)); err != nil {
83+
// No-op if file no longer exists; may have been deleted by another
84+
// process/thread trying to allocate ports.
85+
if os.IsNotExist(err) {
86+
return nil
87+
}
7888
return err
7989
}
8090
}

0 commit comments

Comments
 (0)