mirror of
https://github.com/gravitational/teleport
synced 2024-10-21 09:44:51 +00:00
0136f8a0ab
Following on from #13658, this patch removes more (but unfortunately not all) usages of the deprecated, list-based port-allocation scheme. This patch: 1. Updates the integration test `TeleInstance` fixture to use injected listeners rather than static ports when creating a new proxy node in a cluster, 2. Updates tests affected by (1) to pre-allocate and inject listeners, including handling caching the listener FDs between proxy restarts 3. Removed unnecessary port allocations when creating LoadBalancer fixtures, and 4. Moved the remaining list-base port allocation functions out of helpers and back into integrations and made private. These functions should never be used by more than one test package concurrently or there is a very high chance of a port collision. Rather than just write that rule down in the comments, I have contained the deprecated code into the affected package made the compiler enforce the rule for us. See-Also: #12421 See-Also: #13658 See-Also: #14408
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
// Copyright 2022 Gravitational, Inc
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gravitational/teleport/lib/utils"
|
|
)
|
|
|
|
// ports contains tcp ports allocated for all integration tests.
|
|
// TODO: Replace all usage of `Ports` with FD-injected sockets as per
|
|
//
|
|
// https://github.com/gravitational/teleport/pull/13346
|
|
var ports utils.PortList
|
|
|
|
func init() {
|
|
// Allocate tcp ports for all integration tests. 5000 should be plenty.
|
|
var err error
|
|
ports, err = utils.GetFreeTCPPorts(5000, utils.PortStartingNumber)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed to allocate tcp ports for tests: %v", err))
|
|
}
|
|
}
|
|
|
|
// newPortValue fetches a port from the pool.
|
|
// Deprecated: Use helpers.NewListener() and friends instead.
|
|
func newPortValue() int {
|
|
return ports.PopInt()
|
|
}
|
|
|
|
// newPortStr fetches aport from the pool as a string.
|
|
// Deprecated: Use helpers.NewListener() and friends instead.
|
|
func newPortStr() string {
|
|
return ports.Pop()
|
|
}
|