Skip to content

Commit

Permalink
update e2e to use new cluster create/destory apis
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Oct 3, 2023
1 parent 50a8043 commit 8e748b6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion e2e/basic/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/mariomac/guara/pkg/test"
"github.com/netobserv/netobserv-ebpf-agent/e2e/cluster"
"github.com/netobserv/netobserv-ebpf-agent/e2e/cluster/tester"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -26,11 +27,11 @@ import (
const (
clusterNamePrefix = "basic-test-cluster"
testTimeout = 10 * time.Minute
namespace = "default"
)

var (
testCluster *cluster.Kind
namespace = envconf.RandomName("kind-ns", 16)
)

func TestMain(m *testing.M) {
Expand All @@ -40,6 +41,7 @@ func TestMain(m *testing.M) {
testCluster = cluster.NewKind(
clusterNamePrefix+time.Now().Format("20060102-150405"),
path.Join("..", ".."),
namespace,
cluster.Deploy(cluster.Deployment{
Order: cluster.AfterAgent, ManifestFile: "manifests/pods.yml"}),
)
Expand Down
17 changes: 12 additions & 5 deletions e2e/cluster/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
rt2 "runtime"

"github.com/netobserv/netobserv-ebpf-agent/e2e/cluster/tester"

"github.com/sirupsen/logrus"
"github.com/vladimirvivien/gexe"
"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -34,6 +35,7 @@ import (
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/envfuncs"
"sigs.k8s.io/e2e-framework/support/kind"
)

// DeployOrder specifies the order in which a Deployment must be executed, from lower to higher
Expand Down Expand Up @@ -115,6 +117,7 @@ type Deployment struct {
// Kind cluster deployed by each TestMain function, prepared for a given test scenario.
type Kind struct {
clusterName string
nameSpace string
baseDir string
deployManifests map[DeployID]Deployment
testEnv env.Environment
Expand Down Expand Up @@ -153,11 +156,12 @@ func Timeout(t time.Duration) Option {
// must point to the folder where the logs are going to be stored and, in case your docker
// backend doesn't provide access to the local images, where the ebpf-agent.tar container image
// is located. Usually it will be the project root.
func NewKind(kindClusterName, baseDir string, options ...Option) *Kind {
func NewKind(kindClusterName, baseDir, nameSpace string, options ...Option) *Kind {
k := &Kind{
testEnv: env.New(),
baseDir: baseDir,
clusterName: kindClusterName,
nameSpace: nameSpace,
deployManifests: defaultBaseDeployments,
timeout: 2 * time.Minute,
}
Expand All @@ -170,9 +174,12 @@ func NewKind(kindClusterName, baseDir string, options ...Option) *Kind {
// Run the Kind cluster for the later execution of tests.
func (k *Kind) Run(m *testing.M) {
envFuncs := []env.Func{
envfuncs.CreateKindClusterWithConfig(k.clusterName,
kindImage,
path.Join(packageDir(), "base", "00-kind.yml")),
envfuncs.CreateClusterWithConfig(
kind.NewProvider(),
k.clusterName,
path.Join(packageDir(), "base", "00-kind.yml"),
kind.WithImage(kindImage)),
envfuncs.CreateNamespace(k.nameSpace),
k.loadLocalImage(),
}
// Deploy base cluster dependencies and wait for readiness (if needed)
Expand All @@ -195,7 +202,7 @@ func (k *Kind) Run(m *testing.M) {
code := k.testEnv.Setup(envFuncs...).
Finish(
k.exportLogs(),
envfuncs.DestroyKindCluster(k.clusterName),
envfuncs.DestroyCluster(k.clusterName),
).Run(m)
log.WithField("returnCode", code).Info("tests finished run")
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cluster/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestOrderManifests(t *testing.T) {
if os.Getenv("ACTIONS_RUNNER_DEBUG") == "true" {
logrus.StandardLogger().SetLevel(logrus.DebugLevel)
}
tc := NewKind("foo", ".",
tc := NewKind("foo", ".", "default",
Deploy(Deployment{ManifestFile: "pods.yml"}),
Deploy(Deployment{Order: ExternalServices, ManifestFile: "sql"}),
Override(Loki, Deployment{Order: ExternalServices, ManifestFile: "loki"}))
Expand Down
4 changes: 3 additions & 1 deletion e2e/ipfix/ipfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"github.com/netobserv/netobserv-ebpf-agent/e2e/basic"
"github.com/netobserv/netobserv-ebpf-agent/e2e/cluster"
"github.com/sirupsen/logrus"
"sigs.k8s.io/e2e-framework/pkg/envconf"
)

const (
clusterNamePrefix = "ipfix-test-cluster"
testTimeout = 20 * time.Minute
namespace = "default"
)

var (
testCluster *cluster.Kind
namespace = envconf.RandomName("kind-ns", 16)
)

func TestMain(m *testing.M) {
Expand All @@ -28,6 +29,7 @@ func TestMain(m *testing.M) {
testCluster = cluster.NewKind(
clusterNamePrefix+time.Now().Format("20060102-150405"),
path.Join("..", ".."),
namespace,
cluster.Timeout(testTimeout),
cluster.Override(cluster.FlowLogsPipeline, cluster.Deployment{
Order: cluster.NetObservServices, ManifestFile: path.Join("manifests", "20-flp-transformer.yml"),
Expand Down
4 changes: 3 additions & 1 deletion e2e/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/netobserv/netobserv-ebpf-agent/e2e/basic"
"github.com/netobserv/netobserv-ebpf-agent/e2e/cluster"

"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -24,11 +25,11 @@ import (
const (
clusterNamePrefix = "kafka-test-cluster"
testTimeout = 20 * time.Minute
namespace = "default"
)

var (
testCluster *cluster.Kind
namespace = envconf.RandomName("kind-ns", 16)
)

func TestMain(m *testing.M) {
Expand All @@ -42,6 +43,7 @@ func TestMain(m *testing.M) {
testCluster = cluster.NewKind(
clusterNamePrefix+time.Now().Format("20060102-150405"),
path.Join("..", ".."),
namespace,
cluster.Timeout(testTimeout),
cluster.Deploy(cluster.Deployment{
Order: cluster.Preconditions, ManifestFile: path.Join("manifests", "10-kafka-crd.yml"),
Expand Down

0 comments on commit 8e748b6

Please sign in to comment.