Skip to content
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

test with a noproxy that doesn't include every private IP #1108

Merged
merged 3 commits into from
Sep 5, 2024
Merged
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
25 changes: 18 additions & 7 deletions e2e/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Dir struct {
// names and the cluster id.
type Output struct {
Nodes []string
IPs []string
network string
id string
T *testing.T
Expand Down Expand Up @@ -216,7 +217,7 @@ func NewTestCluster(in *Input) *Output {
}
CreateProfile(in)
CreateNetworks(in)
out.Nodes = CreateNodes(in)
out.Nodes, out.IPs = CreateNodes(in)
for _, node := range out.Nodes {
CopyFilesToNode(in, node)
CopyDirsToNode(in, node)
Expand Down Expand Up @@ -251,7 +252,6 @@ func NewTestCluster(in *Input) *Output {

const ProxyImage = "debian/12"
const HTTPProxy = "http://10.0.0.254:3128"
const NOProxy = "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"

// CreateProxy creates a node that attaches to both networks (external and internal),
// once this is done we install squid and configure it to be a proxy. We also make
Expand Down Expand Up @@ -573,18 +573,20 @@ func CopyFileFromNode(node, source, dest string) error {

// CreateNodes creats the nodes for the cluster. The amount of nodes is
// specified in the input.
func CreateNodes(in *Input) []string {
func CreateNodes(in *Input) ([]string, []string) {
nodes := []string{}
IPs := []string{}
for i := 0; i < in.Nodes; i++ {
node := CreateNode(in, i)
node, ip := CreateNode(in, i)
if !in.WithProxy {
NodeHasInternet(in, node)
} else {
NodeHasNoInternet(in, node)
}
nodes = append(nodes, node)
IPs = append(IPs, ip)
}
return nodes
return nodes, IPs
}

// NodeHasInternet checks if the node has internet access. It does this by
Expand Down Expand Up @@ -687,7 +689,7 @@ func NodeHasNoInternet(in *Input, node string) {
// CreateNode creates a single node. The i here is used to create a unique
// name for the node. Node is named as "node-<cluster id>-<i>". The node
// name is returned.
func CreateNode(in *Input, i int) string {
func CreateNode(in *Input, i int) (string, string) {
client, err := lxd.ConnectLXDUnix(lxdSocket, nil)
if err != nil {
in.T.Fatalf("Failed to connect to LXD: %v", err)
Expand Down Expand Up @@ -736,7 +738,16 @@ func CreateNode(in *Input, i int) string {
in.T.Fatalf("Failed to get node state %s: %v", name, err)
}
}
return name
ip := ""
for _, addr := range state.Network["eth0"].Addresses {
fmt.Printf("Family: %s IP: %s\n", addr.Family, addr.Address)
if addr.Family == "inet" {
ip = addr.Address
break
}
}

return name, ip
}

// CreateNetworks create two networks, one of type bridge and inside of it another one of
Expand Down
8 changes: 4 additions & 4 deletions e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestProxiedEnvironment(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}

Expand Down Expand Up @@ -130,10 +130,10 @@ func TestProxiedCustomCIDR(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
line = append(line, "--pod-cidr", "10.128.0.0/20")
line = append(line, "--service-cidr", "10.129.0.0/20")
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}

Expand Down
24 changes: 12 additions & 12 deletions e2e/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}

Expand All @@ -125,7 +125,7 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {

t.Logf("%s: checking installation state", time.Now().Format(time.RFC3339))
line = []string{"check-installation-state.sh", os.Getenv("SHORT_SHA"), k8sVersion()}
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to check installation state: %v", err)
}

Expand All @@ -143,14 +143,14 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {
line = append([]string{"restore-installation.exp"}, testArgs...)
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to restore the installation: %v", err)
}

t.Logf("%s: checking installation state", time.Now().Format(time.RFC3339))
line = []string{"check-installation-state.sh", os.Getenv("SHORT_SHA"), k8sVersion()}
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to check installation state: %v", err)
}

Expand Down Expand Up @@ -220,7 +220,7 @@ func TestSingleNodeResumeDisasterRecovery(t *testing.T) {

t.Logf("%s: checking installation state", time.Now().Format(time.RFC3339))
line = []string{"check-installation-state.sh", os.Getenv("SHORT_SHA"), k8sVersion()}
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to check installation state: %v", err)
}

Expand Down Expand Up @@ -284,7 +284,7 @@ func TestSingleNodeAirgapDisasterRecovery(t *testing.T) {
line = []string{"single-node-airgap-install.sh", "--proxy"}
line = append(line, "--pod-cidr", "10.128.0.0/20")
line = append(line, "--service-cidr", "10.129.0.0/20")
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}
if _, _, err := setupPlaywrightAndRunTest(t, tc, "deploy-app"); err != nil {
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestSingleNodeAirgapDisasterRecovery(t *testing.T) {
t.Logf("%s: restoring the installation", time.Now().Format(time.RFC3339))
testArgs = append(testArgs, "--pod-cidr", "10.128.0.0/20", "--service-cidr", "10.129.0.0/20")
line = append([]string{"restore-installation-airgap.exp"}, testArgs...)
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to restore the installation: %v", err)
}
t.Logf("%s: checking installation state after restoring app", time.Now().Format(time.RFC3339))
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestMultiNodeAirgapHADisasterRecovery(t *testing.T) {

t.Logf("%s: installing embedded-cluster on node 0", time.Now().Format(time.RFC3339))
line = []string{"single-node-airgap-install.sh", "--proxy"}
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}

Expand Down Expand Up @@ -685,7 +685,7 @@ func TestMultiNodeAirgapHADisasterRecovery(t *testing.T) {
// begin restoring the cluster
t.Logf("%s: restoring the installation: phase 1", time.Now().Format(time.RFC3339))
line = append([]string{"restore-multi-node-airgap-phase1.exp"}, testArgs...)
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to restore phase 1 of the installation: %v", err)
}

Expand Down Expand Up @@ -734,7 +734,7 @@ func TestMultiNodeAirgapHADisasterRecovery(t *testing.T) {

t.Logf("%s: restoring the installation: phase 2", time.Now().Format(time.RFC3339))
line = []string{"restore-multi-node-airgap-phase2.exp"}
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv(tc.IPs)); err != nil {
t.Fatalf("fail to restore phase 2 of the installation: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ func installTestDependenciesDebian(t *testing.T, tc *cluster.Output, node int, w
}
}

func withProxyEnv() RunCommandOption {
func withProxyEnv(nodeIPs []string) RunCommandOption {
return WithEnv(map[string]string{
"HTTP_PROXY": cluster.HTTPProxy,
"HTTPS_PROXY": cluster.HTTPProxy,
"NO_PROXY": cluster.NOProxy,
"NO_PROXY": strings.Join(nodeIPs, ","),
})
}
Loading