mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-14 09:29:07 +02:00
[infrastructure] Let a suite outside this repo use the e2e harness (#7176)
e2e/harness documents itself as feature-agnostic, but three details assumed the caller lives in this repo, so the terraform provider's acceptance suite would otherwise carry a second harness for the same product. repoRoot took the first module root above the working directory as the Docker build context, which from another module is the caller's own root, with no combined/Dockerfile.multistage in it. It now requires that ancestor to be this module, and otherwise asks the go tool for the source: for a dependent, the extracted directory of the version it pins, so the server matches the client library it was compiled against. That lookup uses -mod=readonly, since automatic vendor mode otherwise reports an empty Dir. Geolocation was disabled unconditionally. Agent-network ingest does not use it, but location-based posture checks need the database, and a rule management cannot evaluate fails rather than passing. StartClient pinned one network alias and set no hostname, so a second agent could not start and a peer's name was arbitrary. Management records that hostname, making it the peer's name in the API. The client entrypoint is copied with an explicit mode: git tracks it 100755, but the module cache extracts 0444, so a dependent's build produced a container exiting with "permission denied". Adds CombinedOption, WithGeolocation, WithServerEnv, ClientOption and WithClientName.
This commit is contained in:
+32
-4
@@ -32,12 +32,36 @@ type Client struct {
|
||||
container testcontainers.Container
|
||||
}
|
||||
|
||||
// clientOptions is what the ClientOption values assemble.
|
||||
type clientOptions struct {
|
||||
name string
|
||||
}
|
||||
|
||||
// ClientOption adjusts how StartClient runs the agent.
|
||||
type ClientOption func(*clientOptions)
|
||||
|
||||
// WithClientName names the agent, which sets both its network alias and its
|
||||
// container hostname. The hostname matters beyond addressing: the agent reports
|
||||
// it to management at registration, so it is the name the peer appears under in
|
||||
// the API.
|
||||
//
|
||||
// Required to run more than one agent against the same server — the default name
|
||||
// is shared, and two containers cannot hold the same alias on one network.
|
||||
func WithClientName(name string) ClientOption {
|
||||
return func(o *clientOptions) { o.name = name }
|
||||
}
|
||||
|
||||
// StartClient builds the client image and runs it on the combined server's
|
||||
// network, joining via the given setup key. The image entrypoint brings the
|
||||
// daemon up automatically; callers wait for connectivity with WaitConnected /
|
||||
// WaitProxyPeer.
|
||||
func StartClient(ctx context.Context, c *Combined, setupKey string) (*Client, error) {
|
||||
root, err := repoRoot()
|
||||
func StartClient(ctx context.Context, c *Combined, setupKey string, opts ...ClientOption) (*Client, error) {
|
||||
o := clientOptions{name: clientAlias}
|
||||
for _, opt := range opts {
|
||||
opt(&o)
|
||||
}
|
||||
|
||||
root, err := repoRoot(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -47,9 +71,13 @@ func StartClient(ctx context.Context, c *Combined, setupKey string) (*Client, er
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: clientImage,
|
||||
Image: clientImage,
|
||||
// The agent reports the container's hostname to management, so this is
|
||||
// the name the peer is addressable by in the API as well as on the
|
||||
// network. The entrypoint takes no hostname flag of its own.
|
||||
Hostname: o.name,
|
||||
Networks: []string{c.network.Name},
|
||||
NetworkAliases: map[string][]string{c.network.Name: {clientAlias}},
|
||||
NetworkAliases: map[string][]string{c.network.Name: {o.name}},
|
||||
Env: map[string]string{
|
||||
"NB_MANAGEMENT_URL": combinedExposedURL,
|
||||
"NB_SETUP_KEY": setupKey,
|
||||
|
||||
Reference in New Issue
Block a user