Skip to content

[tmpnet] Update README #4063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: tmpnet-nginx-ingress
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ jobs:
- uses: ./.github/actions/run-monitored-tmpnet-cmd
with:
run: ./scripts/run_task.sh test-load-kube
runtime: kube
artifact_prefix: load-kube
prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }}
prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }}
Expand Down
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ tasks:
env:
E2E_SERIAL: 1
cmds:
- task: test-e2e-kube
- cmd: bash -x ./scripts/tests.e2e.kube.sh {{.CLI_ARGS}}

# To use a different fuzz time, run `task test-fuzz FUZZTIME=[value in seconds]`.
# A value of `-1` will run until it encounters a failing output.
Expand Down Expand Up @@ -241,7 +241,7 @@ tasks:

test-load2:
desc: Runs second iteration of load tests
cmds:
cmds:
- task: build
- cmd: go run ./tests/load2/main --avalanchego-path=./build/avalanchego {{.CLI_ARGS}}

Expand Down
28 changes: 3 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
k9s # Kubernetes TUI
kind # Kubernetes-in-Docker
kubernetes-helm # Helm CLI (Kubernetes package manager)
self.packages.${system}.kind-with-registry # Script installing kind configured with a local registry

# Linters
shellcheck
Expand All @@ -64,32 +63,11 @@
# macOS-specific frameworks
darwin.apple_sdk.frameworks.Security
];
};
});

# Package to install the kind-with-registry script
packages = forAllSystems ({ pkgs }: {
kind-with-registry = pkgs.stdenv.mkDerivation {
pname = "kind-with-registry";
version = "1.0.0";

src = pkgs.fetchurl {
url = "https://github.com/kubernetes-sigs/kind/7cb9e6be25b48a0e248097eef29d496ab1a044d0/site/static/examples/kind-with-registry.sh";
sha256 = "0gri0x0ygcwmz8l4h6zzsvydw8rsh7qa8p5218d4hncm363i81hv";
};

phases = [ "installPhase" ];

installPhase = ''
mkdir -p $out/bin
install -m755 $src $out/bin/kind-with-registry.sh
# Add scripts/ directory to PATH so kind-with-registry.sh is accessible
shellHook = ''
export PATH="$PWD/scripts:$PATH"
'';

meta = with pkgs.lib; {
description = "Script to set up kind with a local registry";
license = licenses.mit;
maintainers = with maintainers; [ "maru-ava" ];
};
};
});
};
Expand Down
90 changes: 90 additions & 0 deletions scripts/kind-with-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh
# Based on https://github.com/kubernetes-sigs/kind/7cb9e6be25b48a0e248097eef29d496ab1a044d0/site/static/examples/kind-with-registry.sh
# Original work Copyright 2019 The Kubernetes Authors
# Modifications Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
# See the file LICENSE for licensing terms.
#
# 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.

# TODO(marun) Migrate this script to golang
set -o errexit

# 1. Create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \
registry:2
fi

# 2. Create kind cluster with containerd registry config dir enabled
# TODO: kind will eventually enable this by default and this patch will
# be unnecessary.
#
# See:
# https://github.com/kubernetes-sigs/kind/issues/2875
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
nodes:
- role: control-plane
extraPortMappings:
# Exposing a nodeport for nginx ingress is the reason this script needed to be copied and customized
# This port must match the value used to deploy the nginx controller by tests/fixture/tmpnet/start-kind-cluster.go
- containerPort: 30791
hostPort: 30791
protocol: TCP
EOF

# 3. Add the registry config to the nodes
#
# This is necessary because localhost resolves to loopback addresses that are
# network-namespace local.
# In other words: localhost in the container is not localhost on the host.
#
# We want a consistent name that works from both ends, so we tell containerd to
# alias localhost:${reg_port} to the registry container when pulling images
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
for node in $(kind get nodes); do
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
[host."http://${reg_name}:5000"]
EOF
done

# 4. Connect the registry to the cluster network if not already connected
# This allows kind to bootstrap the network but ensures they're on the same network
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

# 5. Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
15 changes: 14 additions & 1 deletion scripts/tests.e2e.kube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ else
XSVM_IMAGE="${XSVM_IMAGE}" AVALANCHEGO_IMAGE="${AVALANCHEGO_IMAGE}" bash -x ./scripts/build_xsvm_image.sh
fi

bash -x ./scripts/tests.e2e.sh --runtime=kube --kube-image="${XSVM_IMAGE}" "$@"
# Determine kubeconfig context to use
KUBECONFIG_CONTEXT=""

# Check if --kubeconfig-context is already provided in arguments
if [[ "$*" =~ --kubeconfig-context ]]; then
# User provided a context, use it as-is
echo "Using provided kubeconfig context from arguments"
else
# Default to the RBAC context
KUBECONFIG_CONTEXT="--kubeconfig-context=kind-kind-tmpnet"
echo "Defaulting to limited-permission context 'kind-kind-tmpnet' to test RBAC Role permissions"
fi

bash -x ./scripts/tests.e2e.sh --runtime=kube --kube-image="${XSVM_IMAGE}" "$KUBECONFIG_CONTEXT" "$@"
17 changes: 9 additions & 8 deletions tests/antithesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/flags"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/testenv"
)

const (
Expand All @@ -39,7 +40,7 @@ func NewConfig(tc tests.TestContext, defaultNetwork *tmpnet.Network) *Config {

func NewConfigWithSubnets(tc tests.TestContext, defaultNetwork *tmpnet.Network, getSubnets SubnetsForNodesFunc) *Config {
// tmpnet configuration
flagVars := e2e.RegisterFlags()
flagVars := flags.RegisterFlags()

var (
duration time.Duration
Expand Down Expand Up @@ -85,7 +86,7 @@ func configForNewNetwork(
tc tests.TestContext,
defaultNetwork *tmpnet.Network,
getSubnets SubnetsForNodesFunc,
flagVars *e2e.FlagVars,
flagVars *flags.FlagVars,
duration time.Duration,
) *Config {
if defaultNetwork.Nodes == nil {
Expand All @@ -97,17 +98,17 @@ func configForNewNetwork(
defaultNetwork.Subnets = getSubnets(defaultNetwork.Nodes...)
}

testEnv := e2e.NewTestEnvironment(tc, flagVars, defaultNetwork)
testEnv := testenv.NewTestEnvironment(tc, flagVars, defaultNetwork)

c := &Config{
Duration: duration,
}
localURIs := testEnv.GetNodeURIs()
c.URIs = make(CSV, len(localURIs))
for i, nodeURI := range localURIs {
network := testEnv.GetNetwork()
uris := network.GetNodeURIs()
c.URIs = make(CSV, len(uris))
for i, nodeURI := range uris {
c.URIs[i] = nodeURI.URI
}
network := testEnv.GetNetwork()
c.ChainIDs = make(CSV, len(network.Subnets))
for i, subnet := range network.Subnets {
c.ChainIDs[i] = subnet.Chains[0].ChainID.String()
Expand Down
32 changes: 6 additions & 26 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ queries](https://onsi.github.io/ginkgo/#spec-labels).

## Adding tests

Define any flags/configurations in [`flags.go`](../fixture/e2e/flags.go).
Configure test behavior using the flags defined in the [tmpnet flags package](../fixture/tmpnet/flags/). For detailed flag documentation, see the [tmpnet configuration flags documentation](../fixture/tmpnet/README.md#configuration-flags).

Create a new package to implement feature-specific tests, or add tests to an existing package. For example:

Expand Down Expand Up @@ -110,30 +110,10 @@ E2E_SKIP_BOOTSTRAP_CHECKS=1 ./bin/ginkgo -v ./tests/e2e ...

## Monitoring

It is possible to enable collection of logs and metrics from the
temporary networks used for e2e testing by:
tmpnet supports comprehensive monitoring of temporary networks through log and metric collection.
This can be enabled for e2e tests in two ways:

- Supplying `--start-metrics-collector` and `--start-logs-collector`
as arguments to the test suite
- Starting collectors in advance of a test run with `tmpnetctl
start-metrics-collector` and ` tmpnetctl start-logs-collector`
- Supply `--start-metrics-collector` and `--start-logs-collector` as arguments to the test suite
- Start collectors manually before test runs using `tmpnetctl`

Both methods require:

- Auth credentials to be supplied as env vars:
- `PROMETHEUS_USERNAME`
- `PROMETHEUS_PASSWORD`
- `LOKI_USERNAME`
- `LOKI_PASSWORD`
- The availability in the path of binaries for promtail and prometheus
- Starting a development shell with `nix develop` is one way to
ensure this and requires the installation of nix
(e.g. `./scripts/run_task.sh install-nix`).

Once started, the collectors will continue to run in the background
until stopped by `tmpnetctl stop-metrics-collector` and `tmpnetctl stop-logs-collector`.

The results of collection will be viewable at
https://grafana-poc.avax-dev.network.

For more detail, see the [tmpnet docs](../fixture/tmpnet/README.md##monitoring).
For detailed configuration and usage, see the [tmpnet monitoring documentation](../fixture/tmpnet/README.md#monitoring).
2 changes: 1 addition & 1 deletion tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
node := privateNetwork.Nodes[0]
nodeURI := tmpnet.NodeURI{
NodeID: node.NodeID,
URI: e2e.GetLocalURI(tc, node),
URI: node.GetAccessibleURI(),
}
ethClient := e2e.NewEthClient(tc, nodeURI)

Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import (
"github.com/ava-labs/avalanchego/tests/e2e/vms"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/flags"
"github.com/ava-labs/avalanchego/upgrade"
)

func TestE2E(t *testing.T) {
ginkgo.RunSpecs(t, "e2e test suites")
}

var flagVars *e2e.FlagVars
var flagVars *flags.FlagVars

func init() {
flagVars = e2e.RegisterFlagsWithDefaultOwner("avalanchego-e2e")
flagVars = flags.RegisterFlagsWithDefaultOwner("avalanchego-e2e")
}

var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
e2e.WaitForHealthy(tc, node)

tc.By("retrieving new node's id and pop")
uri := e2e.GetLocalURI(tc, node)
uri := node.GetAccessibleURI()
infoClient := info.NewClient(uri)
nodeID, nodePOP, err := infoClient.GetNodeID(tc.DefaultContext())
require.NoError(err)
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/p/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ var _ = e2e.DescribePChain("[L1]", func() {
var (
networkID = env.GetNetwork().GetNetworkID()
genesisPeerMessages = buffer.NewUnboundedBlockingDeque[p2pmessage.InboundMessage](1)
stakingAddress = e2e.GetLocalStakingAddress(tc, subnetGenesisNode)
)
stakingAddress, cancel, err := subnetGenesisNode.GetAccessibleStakingAddress(tc.DefaultContext())
require.NoError(err)
tc.DeferCleanup(cancel)
genesisPeer, err := peer.StartTestPeer(
tc.DefaultContext(),
stakingAddress,
Expand All @@ -202,7 +204,7 @@ var _ = e2e.DescribePChain("[L1]", func() {
)
require.NoError(err)

subnetGenesisNodeURI := e2e.GetLocalURI(tc, subnetGenesisNode)
subnetGenesisNodeURI := subnetGenesisNode.GetAccessibleURI()

address := []byte{}
tc.By("issuing a ConvertSubnetToL1Tx", func() {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
e2e.WaitForHealthy(tc, betaNode)

tc.By("retrieving alpha node id and pop")
alphaNodeURI := e2e.GetLocalURI(tc, alphaNode)
alphaNodeURI := alphaNode.GetAccessibleURI()
alphaInfoClient := info.NewClient(alphaNodeURI)
alphaNodeID, alphaPOP, err := alphaInfoClient.GetNodeID(tc.DefaultContext())
require.NoError(err)

tc.By("retrieving beta node id and pop")
betaNodeURI := e2e.GetLocalURI(tc, betaNode)
betaNodeURI := betaNode.GetAccessibleURI()
betaInfoClient := info.NewClient(betaNodeURI)
betaNodeID, betaPOP, err := betaInfoClient.GetNodeID(tc.DefaultContext())
require.NoError(err)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/p/validator_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ var _ = e2e.DescribePChain("[Validator Sets]", func() {
require.NoError(err)

tc.By("checking that validator sets are equal across all heights for all nodes", func() {
localURIs := env.GetNodeURIs()
pvmClients := make([]platformvm.Client, len(localURIs))
for i, nodeURI := range localURIs {
nodeURIs := network.GetNodeURIs()
pvmClients := make([]platformvm.Client, len(nodeURIs))
for i, nodeURI := range nodeURIs {
pvmClients[i] = platformvm.NewClient(nodeURI.URI)
// Ensure that the height of the target node is at least the expected height
tc.Eventually(
Expand Down
Loading
Loading