Skip to content

Commit b768168

Browse files
committed
[tmpnet] Refactor in preparation for kube
1 parent 465cd68 commit b768168

25 files changed

+447
-371
lines changed

flake.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
# Kube tools
4141
kubectl # Kubernetes CLI
42+
k9s # Kubernetes TUI
4243
kind # Kubernetes-in-Docker
4344
kubernetes-helm # Helm CLI (Kubernetes package manager)
4445
self.packages.${system}.kind-with-registry # Script installing kind configured with a local registry

scripts/build_antithesis_images.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ else
8787
"${AVALANCHE_PATH}/build/antithesis/xsvm" \
8888
"AVALANCHEGO_PATH=${AVALANCHE_PATH}/build/avalanchego AVAGO_PLUGIN_DIR=${AVALANCHE_PATH}/build/plugins"
8989

90-
build_antithesis_images_for_avalanchego "${TEST_SETUP}" "${IMAGE_PREFIX}" "${AVALANCHE_PATH}/vms/example/xsvm/Dockerfile"
90+
build_antithesis_images_for_avalanchego "${TEST_SETUP}" "${IMAGE_PREFIX}" "${AVALANCHE_PATH}/tests/antithesis/xsvm/Dockerfile.node"
9191
fi

scripts/tests.e2e.bootstrap_monitor.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ if ! [[ "$0" =~ scripts/tests.e2e.bootstrap_monitor.sh ]]; then
99
exit 255
1010
fi
1111

12+
export KUBECONFIG="$HOME/.kube/config"
13+
1214
./bin/tmpnetctl start-kind-cluster
1315

14-
KUBECONFIG="$HOME/.kube/config" ./bin/ginkgo -v ./tests/fixture/bootstrapmonitor/e2e
16+
./bin/ginkgo -v ./tests/fixture/bootstrapmonitor/e2e

scripts/tests.e2e.sh

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ fi
2020
# the instructions to build non-portable BLST.
2121
source ./scripts/constants.sh
2222

23-
# Enable subnet testing by building xsvm
24-
./scripts/build_xsvm.sh
25-
echo ""
26-
2723
# Ensure an absolute path to avoid dependency on the working directory
2824
# of script execution.
29-
AVALANCHEGO_PATH="$(realpath "${AVALANCHEGO_PATH:-./build/avalanchego}")"
30-
E2E_ARGS="--avalanchego-path=${AVALANCHEGO_PATH}"
25+
E2E_ARGS="${*:-}"
26+
if ! [[ "${E2E_ARGS}" =~ "--runtime=kube" ]]; then
27+
# If not running in kubernetes, use the local avalanchego binary
28+
AVALANCHEGO_PATH="$(realpath "${AVALANCHEGO_PATH:-./build/avalanchego}")"
29+
E2E_ARGS+=" --avalanchego-path=${AVALANCHEGO_PATH}"
30+
31+
# Enable subnet testing by building the xsvm binary
32+
./scripts/build_xsvm.sh
33+
fi
3134

3235
#################################
3336
# Determine ginkgo args
@@ -58,5 +61,5 @@ else
5861
fi
5962

6063
#################################
61-
# shellcheck disable=SC2086
62-
./bin/ginkgo ${GINKGO_ARGS} -v ./tests/e2e -- "${E2E_ARGS[@]}" "${@}"
64+
# shellcheck disable=SC2086,SC2068
65+
./bin/ginkgo ${GINKGO_ARGS} -v ./tests/e2e -- ${E2E_ARGS[@]}

tests/antithesis/compose.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
174174
}
175175

176176
// Apply configuration appropriate to a test network
177-
for k, v := range tmpnet.DefaultTestFlags() {
177+
for k, v := range tmpnet.DefaultTmpnetFlags() {
178178
switch value := v.(type) {
179179
case string:
180180
env[k] = value

tests/e2e/e2e_test.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,27 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
6161
require.NoError(tc, err)
6262

6363
upgradeBase64 := base64.StdEncoding.EncodeToString(upgradeJSON)
64+
65+
defaultFlags := tmpnet.FlagsMap{
66+
config.UpgradeFileContentKey: upgradeBase64,
67+
// Ensure a min stake duration compatible with testing staking logic
68+
config.MinStakeDurationKey: "1s",
69+
}
70+
defaultFlags.SetDefaults(tmpnet.DefaultE2EFlags())
71+
6472
return e2e.NewTestEnvironment(
6573
tc,
6674
flagVars,
6775
&tmpnet.Network{
68-
Owner: flagVars.NetworkOwner(),
69-
DefaultFlags: tmpnet.FlagsMap{
70-
config.UpgradeFileContentKey: upgradeBase64,
71-
// Ensure a min stake duration compatible with testing staking logic
72-
config.MinStakeDurationKey: tmpnet.DefaultMinStakeDuration,
73-
},
74-
Nodes: nodes,
75-
Subnets: subnets,
76+
Owner: flagVars.NetworkOwner(),
77+
DefaultFlags: defaultFlags,
78+
Nodes: nodes,
79+
Subnets: subnets,
7680
},
7781
).Marshal()
7882
}, func(envBytes []byte) {
7983
// Run in every ginkgo process
8084

8185
// Initialize the local test environment from the global state
82-
e2e.InitSharedTestEnvironment(ginkgo.GinkgoT(), envBytes)
86+
e2e.InitSharedTestEnvironment(e2e.NewTestContext(), envBytes)
8387
})

tests/e2e/faultinjection/duplicate_node_id.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
4444
_ = e2e.AddEphemeralNode(tc, network, node2)
4545

4646
tc.By("checking that the second new node fails to become healthy before timeout")
47-
err := tmpnet.WaitForHealthy(tc.DefaultContext(), node2)
47+
err := tmpnet.WaitForHealthyNode(tc.DefaultContext(), tc.Log(), node2)
4848
require.ErrorIs(err, context.DeadlineExceeded)
4949

5050
tc.By("stopping the first new node")

tests/fixture/bootstrapmonitor/e2e/e2e_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
2626
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
2727
"github.com/ava-labs/avalanchego/utils/constants"
28+
"github.com/ava-labs/avalanchego/utils/logging"
2829

2930
appsv1 "k8s.io/api/apps/v1"
3031
corev1 "k8s.io/api/core/v1"
@@ -282,7 +283,15 @@ func newNodeStatefulSet(name string, flags map[string]string) *appsv1.StatefulSe
282283
}
283284

284285
func defaultPodFlags() map[string]string {
285-
return tmpnet.DefaultPodFlags(constants.LocalName, nodeDataDir)
286+
return map[string]string{
287+
config.DataDirKey: nodeDataDir,
288+
config.NetworkNameKey: constants.LocalName,
289+
config.SybilProtectionEnabledKey: "false",
290+
config.HealthCheckFreqKey: "500ms", // Ensure rapid detection of a healthy state
291+
config.LogDisplayLevelKey: logging.Info.String(),
292+
config.LogLevelKey: logging.Off.String(),
293+
config.HTTPHostKey: "0.0.0.0", // Need to bind to pod IP to ensure kubelet can access the http port for the readiness check
294+
}
286295
}
287296

288297
// waitForPodCondition waits until the specified pod reports the specified condition

tests/fixture/e2e/env.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import (
2626
// access to the shared env to GetEnv which adds a test context.
2727
var env *TestEnvironment
2828

29-
func InitSharedTestEnvironment(t require.TestingT, envBytes []byte) {
30-
require := require.New(t)
29+
func InitSharedTestEnvironment(tc tests.TestContext, envBytes []byte) {
30+
require := require.New(tc)
3131
require.Nil(env, "env already initialized")
3232
env = &TestEnvironment{}
3333
require.NoError(json.Unmarshal(envBytes, env))
34+
env.testContext = tc
3435

3536
// Ginkgo parallelization is at the process level, so a given key
3637
// can safely be used by all tests in a given process without fear
@@ -81,6 +82,7 @@ func (te *TestEnvironment) Marshal() []byte {
8182
// Initialize a new test environment with a shared network (either pre-existing or newly created).
8283
func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork *tmpnet.Network) *TestEnvironment {
8384
require := require.New(tc)
85+
log := tc.Log()
8486

8587
var network *tmpnet.Network
8688

@@ -126,34 +128,34 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork
126128

127129
if len(networkDir) > 0 {
128130
var err error
129-
network, err = tmpnet.ReadNetwork(networkDir)
131+
network, err = tmpnet.ReadNetwork(tc.DefaultContext(), log, networkDir)
130132
require.NoError(err)
131-
tc.Log().Info("loaded a network",
133+
log.Info("loaded a network",
132134
zap.String("networkDir", networkDir),
133135
)
134136
}
135137

136138
if networkCmd == StopNetworkCmd {
137139
if len(networkSymlink) > 0 {
138140
// Remove the symlink to avoid attempts to reuse the stopped network
139-
tc.Log().Info("removing symlink",
141+
log.Info("removing symlink",
140142
zap.String("path", networkSymlink),
141143
)
142144
if err := os.Remove(networkSymlink); !errors.Is(err, os.ErrNotExist) {
143145
require.NoError(err)
144146
}
145147
}
146148
if network != nil {
147-
tc.Log().Info("stopping network")
149+
log.Info("stopping network")
148150
require.NoError(network.Stop(tc.DefaultContext()))
149151
} else {
150-
tc.Log().Warn("no network to stop")
152+
log.Warn("no network to stop")
151153
}
152154
os.Exit(0)
153155
}
154156

155157
if network != nil && networkCmd == RestartNetworkCmd {
156-
require.NoError(network.Restart(tc.DefaultContext(), tc.Log()))
158+
require.NoError(network.Restart(tc.DefaultContext()))
157159
}
158160
}
159161

@@ -194,7 +196,7 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork
194196

195197
uris := network.GetNodeURIs()
196198
require.NotEmpty(uris, "network contains no nodes")
197-
tc.Log().Info("network nodes are available",
199+
log.Info("network nodes are available",
198200
zap.Any("uris", uris),
199201
)
200202

@@ -221,8 +223,9 @@ func (te *TestEnvironment) GetRandomNodeURI() tmpnet.NodeURI {
221223

222224
// Retrieve the network to target for testing.
223225
func (te *TestEnvironment) GetNetwork() *tmpnet.Network {
224-
network, err := tmpnet.ReadNetwork(te.NetworkDir)
225-
require.NoError(te.testContext, err)
226+
tc := te.testContext
227+
network, err := tmpnet.ReadNetwork(tc.DefaultContext(), tc.Log(), te.NetworkDir)
228+
require.NoError(tc, err)
226229
return network
227230
}
228231

@@ -233,14 +236,15 @@ func (te *TestEnvironment) NewKeychain() *secp256k1fx.Keychain {
233236

234237
// Create a new private network that is not shared with other tests.
235238
func (te *TestEnvironment) StartPrivateNetwork(network *tmpnet.Network) {
236-
require := require.New(te.testContext)
239+
tc := te.testContext
240+
require := require.New(tc)
237241
// Use the same configuration as the shared network
238-
sharedNetwork, err := tmpnet.ReadNetwork(te.NetworkDir)
242+
sharedNetwork, err := tmpnet.ReadNetwork(tc.DefaultContext(), tc.Log(), te.NetworkDir)
239243
require.NoError(err)
240244
network.DefaultRuntimeConfig = sharedNetwork.DefaultRuntimeConfig
241245

242246
StartNetwork(
243-
te.testContext,
247+
tc,
244248
network,
245249
te.RootNetworkDir,
246250
te.PrivateNetworkShutdownDelay,

tests/fixture/e2e/helpers.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func NewEthClient(tc tests.TestContext, nodeURI tmpnet.NodeURI) ethclient.Client
136136
func AddEphemeralNode(tc tests.TestContext, network *tmpnet.Network, node *tmpnet.Node) *tmpnet.Node {
137137
require := require.New(tc)
138138

139-
require.NoError(network.StartNode(tc.DefaultContext(), tc.Log(), node))
139+
require.NoError(network.StartNode(tc.DefaultContext(), node))
140140

141141
tc.DeferCleanup(func() {
142142
tc.Log().Info("shutting down ephemeral node",
@@ -150,11 +150,11 @@ func AddEphemeralNode(tc tests.TestContext, network *tmpnet.Network, node *tmpne
150150
}
151151

152152
// Wait for the given node to report healthy.
153-
func WaitForHealthy(t require.TestingT, node *tmpnet.Node) {
153+
func WaitForHealthy(tc tests.TestContext, node *tmpnet.Node) {
154154
// Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup
155155
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
156156
defer cancel()
157-
require.NoError(t, tmpnet.WaitForHealthy(ctx, node))
157+
require.NoError(tc, tmpnet.WaitForHealthyNode(ctx, tc.Log(), node))
158158
}
159159

160160
// Sends an eth transaction and waits for the transaction receipt from the
@@ -236,7 +236,7 @@ func CheckBootstrapIsPossible(tc tests.TestContext, network *tmpnet.Network) *tm
236236
}
237237

238238
node := tmpnet.NewEphemeralNode(flags)
239-
require.NoError(network.StartNode(tc.DefaultContext(), tc.Log(), node))
239+
require.NoError(network.StartNode(tc.DefaultContext(), node))
240240
// StartNode will initiate node stop if an error is encountered during start,
241241
// so no further cleanup effort is required if an error is seen here.
242242

@@ -248,7 +248,7 @@ func CheckBootstrapIsPossible(tc tests.TestContext, network *tmpnet.Network) *tm
248248
})
249249

250250
// Check that the node becomes healthy within timeout
251-
require.NoError(tmpnet.WaitForHealthy(tc.DefaultContext(), node))
251+
require.NoError(tmpnet.WaitForHealthyNode(tc.DefaultContext(), tc.Log(), node))
252252

253253
// Ensure that the primary validators are still healthy
254254
for _, node := range network.Nodes {
@@ -272,10 +272,11 @@ func StartNetwork(
272272
networkCmd NetworkCmd,
273273
) {
274274
require := require.New(tc)
275+
log := tc.Log()
275276

276277
err := tmpnet.BootstrapNewNetwork(
277278
tc.DefaultContext(),
278-
tc.Log(),
279+
log,
279280
network,
280281
rootNetworkDir,
281282
)
@@ -289,7 +290,7 @@ func StartNetwork(
289290
require.NoError(err, "failed to bootstrap network")
290291
}
291292

292-
tc.Log().Info("network started successfully")
293+
log.Info("network started successfully")
293294

294295
symlinkPath, err := tmpnet.GetReusableNetworkPathForOwner(network.Owner)
295296
require.NoError(err)
@@ -298,36 +299,36 @@ func StartNetwork(
298299
// Symlink the path of the created network to the default owner path (e.g. latest_avalanchego-e2e)
299300
// to enable easy discovery for reuse.
300301
require.NoError(os.Symlink(network.Dir, symlinkPath))
301-
tc.Log().Info("symlinked network dir for reuse",
302+
log.Info("symlinked network dir for reuse",
302303
zap.String("networkDir", network.Dir),
303304
zap.String("symlinkPath", symlinkPath),
304305
)
305306
}
306307

307308
tc.DeferCleanup(func() {
308309
if networkCmd == ReuseNetworkCmd || networkCmd == RestartNetworkCmd {
309-
tc.Log().Info("skipping shutdown for network intended for reuse",
310+
log.Info("skipping shutdown for network intended for reuse",
310311
zap.String("networkDir", network.Dir),
311312
zap.String("symlinkPath", symlinkPath),
312313
)
313314
return
314315
}
315316

316317
if networkCmd == StartNetworkCmd {
317-
tc.Log().Info("skipping shutdown for --start-network",
318+
log.Info("skipping shutdown for --start-network",
318319
zap.String("networkDir", network.Dir),
319320
)
320321
return
321322
}
322323

323324
if shutdownDelay > 0 {
324-
tc.Log().Info("delaying network shutdown to ensure final metrics scrape",
325+
log.Info("delaying network shutdown to ensure final metrics scrape",
325326
zap.Duration("delay", shutdownDelay),
326327
)
327328
time.Sleep(shutdownDelay)
328329
}
329330

330-
tc.Log().Info("shutting down network")
331+
log.Info("shutting down network")
331332
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
332333
defer cancel()
333334
require.NoError(network.Stop(ctx))

0 commit comments

Comments
 (0)