mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
ci: migrate e2e lb test to bazel (#1892)
* ci: migrate lb e2e test to bazel * ci: disable shared bazel cache on github runners
This commit is contained in:
parent
8f21972aec
commit
b71b5103ae
2
.github/actions/e2e_lb/action.yml
vendored
2
.github/actions/e2e_lb/action.yml
vendored
@ -18,7 +18,7 @@ runs:
|
||||
run: |
|
||||
kubectl apply -f ns.yml
|
||||
kubectl apply -f lb.yml
|
||||
go test -timeout=3h ../../../e2e/internal/lb/lb_test.go -v
|
||||
bazel run //e2e/internal/lb:lb_test
|
||||
|
||||
- name: Delete deployment
|
||||
if: always()
|
||||
|
14
.github/actions/setup_bazel/action.yml
vendored
14
.github/actions/setup_bazel/action.yml
vendored
@ -69,12 +69,24 @@ runs:
|
||||
|
||||
- name: Configure Bazel (readonly)
|
||||
shell: bash
|
||||
if: inputs.useCache == 'readonly'
|
||||
env:
|
||||
WORKSPACE: ${{ github.workspace }}
|
||||
run: |
|
||||
echo "::group::Configure Bazel (readonly)"
|
||||
echo "build --remote_upload_local_results=false" >> "${WORKSPACE}/.bazeloverwriterc"
|
||||
echo "::endgroup::"
|
||||
|
||||
- name: Disable disk cache on GitHub Actions runners
|
||||
shell: bash
|
||||
env:
|
||||
WORKSPACE: ${{ github.workspace }}
|
||||
if: startsWith(runner.name , 'GitHub Actions')
|
||||
run: |
|
||||
echo "::group::Configure Bazel (disk cache)"
|
||||
echo "build --disk_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
|
||||
echo "build --repository_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
|
||||
echo "::endgroup::"
|
||||
|
||||
- name: Check bazel version
|
||||
shell: bash
|
||||
run: bazel version
|
||||
|
29
e2e/internal/lb/BUILD.bazel
Normal file
29
e2e/internal/lb/BUILD.bazel
Normal file
@ -0,0 +1,29 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("//bazel/go:go_test.bzl", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "lb",
|
||||
srcs = ["lb.go"],
|
||||
importpath = "github.com/edgelesssys/constellation/v2/e2e/internal/lb",
|
||||
visibility = ["//e2e:__subpackages__"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "lb_test",
|
||||
timeout = "eternal", # 1 hour
|
||||
srcs = ["lb_test.go"],
|
||||
# keep
|
||||
count = 1,
|
||||
embed = [":lb"],
|
||||
# keep
|
||||
gotags = ["e2e"],
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//e2e/internal/kubectl",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
"@com_github_stretchr_testify//require",
|
||||
"@io_k8s_api//core/v1:core",
|
||||
"@io_k8s_apimachinery//pkg/apis/meta/v1:meta",
|
||||
"@io_k8s_client_go//kubernetes",
|
||||
],
|
||||
)
|
8
e2e/internal/lb/lb.go
Normal file
8
e2e/internal/lb/lb.go
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
// Package lb tests that the cloud load balancer works as expected.
|
||||
package lb
|
@ -1,4 +1,4 @@
|
||||
//go:build e2elb
|
||||
//go:build e2e
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
// End-to-end tests for our cloud load balancer functionality.
|
||||
package test
|
||||
package lb
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -24,7 +24,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
coreV1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
@ -39,44 +39,6 @@ const (
|
||||
interval = time.Second * 5
|
||||
)
|
||||
|
||||
func gatherDebugInfo(t *testing.T, k *kubernetes.Clientset) {
|
||||
// Do not gather additional information on success
|
||||
if !t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
t.Log("Gathering additional debug information.")
|
||||
|
||||
pods, err := k.CoreV1().Pods(namespaceName).List(context.Background(), v1.ListOptions{
|
||||
LabelSelector: "app=whoami",
|
||||
})
|
||||
if err != nil {
|
||||
t.Logf("listing pods: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for idx := range pods.Items {
|
||||
pod := pods.Items[idx]
|
||||
req := k.CoreV1().Pods(namespaceName).GetLogs(pod.Name, &coreV1.PodLogOptions{
|
||||
LimitBytes: func() *int64 { i := int64(1024 * 1024); return &i }(),
|
||||
})
|
||||
logs, err := req.Stream(context.Background())
|
||||
if err != nil {
|
||||
t.Logf("fetching logs: %v", err)
|
||||
return
|
||||
}
|
||||
defer logs.Close()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = io.Copy(buf, logs)
|
||||
if err != nil {
|
||||
t.Logf("copying logs: %v", err)
|
||||
return
|
||||
}
|
||||
t.Logf("Logs of pod '%s':\n%s\n\n", pod.Name, buf)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadBalancer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
@ -108,7 +70,7 @@ func TestLoadBalancer(t *testing.T) {
|
||||
|
||||
t.Log("Change port of service to 8044")
|
||||
svc.Spec.Ports[0].Port = newPort
|
||||
svc, err = k.CoreV1().Services(namespaceName).Update(context.Background(), svc, v1.UpdateOptions{})
|
||||
svc, err = k.CoreV1().Services(namespaceName).Update(context.Background(), svc, metaV1.UpdateOptions{})
|
||||
require.NoError(err)
|
||||
assert.Equal(newPort, svc.Spec.Ports[0].Port)
|
||||
|
||||
@ -123,6 +85,44 @@ func TestLoadBalancer(t *testing.T) {
|
||||
assert.True(hasNUniqueStrings(allHostnames, numPods))
|
||||
}
|
||||
|
||||
func gatherDebugInfo(t *testing.T, k *kubernetes.Clientset) {
|
||||
// Do not gather additional information on success
|
||||
if !t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
t.Log("Gathering additional debug information.")
|
||||
|
||||
pods, err := k.CoreV1().Pods(namespaceName).List(context.Background(), metaV1.ListOptions{
|
||||
LabelSelector: "app=whoami",
|
||||
})
|
||||
if err != nil {
|
||||
t.Logf("listing pods: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for idx := range pods.Items {
|
||||
pod := pods.Items[idx]
|
||||
req := k.CoreV1().Pods(namespaceName).GetLogs(pod.Name, &coreV1.PodLogOptions{
|
||||
LimitBytes: func() *int64 { i := int64(1024 * 1024); return &i }(),
|
||||
})
|
||||
logs, err := req.Stream(context.Background())
|
||||
if err != nil {
|
||||
t.Logf("fetching logs: %v", err)
|
||||
return
|
||||
}
|
||||
defer logs.Close()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = io.Copy(buf, logs)
|
||||
if err != nil {
|
||||
t.Logf("copying logs: %v", err)
|
||||
return
|
||||
}
|
||||
t.Logf("Logs of pod '%s':\n%s\n\n", pod.Name, buf)
|
||||
}
|
||||
}
|
||||
|
||||
func getIPOrHostname(t *testing.T, svc *coreV1.Service) string {
|
||||
t.Helper()
|
||||
if ip := svc.Status.LoadBalancer.Ingress[0].IP; ip != "" {
|
||||
@ -183,7 +183,7 @@ func testEventuallyExternalIPAvailable(t *testing.T, k *kubernetes.Clientset) *c
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
var err error
|
||||
svc, err = k.CoreV1().Services(namespaceName).Get(context.Background(), serviceName, v1.GetOptions{})
|
||||
svc, err = k.CoreV1().Services(namespaceName).Get(context.Background(), serviceName, metaV1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Log("Getting service failed: ", err.Error())
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user