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

chore!: remove Executor from knuu #508

Merged
2 changes: 1 addition & 1 deletion e2e/assert_cleanups.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func AssertCleanupInstance(t *testing.T, instance *knuu.Instance) error {
}

// AssertCleanupInstances is a helper function that cleans up a list of instances.
func AssertCleanupInstances(t *testing.T, executor *knuu.Executor, instances []*knuu.Instance) error {
func AssertCleanupInstances(t *testing.T, executor *knuu.Instance, instances []*knuu.Instance) error {
if os.Getenv("KNUU_SKIP_CLEANUP") == "true" {
t.Log("Skipping cleanup")
return nil
Expand Down
6 changes: 4 additions & 2 deletions e2e/basic/probe_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package basic

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/knuu"
)

func TestProbe(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "prob-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -60,7 +62,7 @@ func TestProbe(t *testing.T) {
}

t.Cleanup(func() {
require.NoError(t, knuu.BatchDestroy(executor.Instance, web))
require.NoError(t, knuu.BatchDestroy(executor, web))
})

// Test logic
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *TestSuite) SetupSuite() {
ctx = context.Background()
)
s.Knuu, err = knuu.New(ctx, knuu.Options{
TestScope: "e2e-basic",
Scope: "e2e-basic",
})
s.Require().NoError(err)
s.Knuu.HandleStopSignal(ctx)
Expand Down
2 changes: 1 addition & 1 deletion e2e/bittwister/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *Suite) SetupSuite() {
ProxyEnabled: true,
})
s.Require().NoError(err)
s.T().Logf("Scope: %s", s.Knuu.Scope())
s.T().Logf("Scope: %s", s.Knuu.Scope)
s.Knuu.HandleStopSignal(ctx)
}

Expand Down
53 changes: 53 additions & 0 deletions e2e/executor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package e2e

import (
"context"

"k8s.io/apimachinery/pkg/api/resource"

"github.com/celestiaorg/knuu/pkg/knuu"
)

const (
executorDefaultImage = "docker.io/nicolaka/netshoot:latest"
sleepCommand = "sleep"
infinityArg = "infinity"
)

var (
executorMemoryLimit = resource.MustParse("100Mi")
executorCpuLimit = resource.MustParse("100m")
)

func NewExecutor(ctx context.Context, executorName string) (*knuu.Instance, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only creating this for compatibility?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, then since we want to do a breaking change, we should just leave this out as we don't want to keep it around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is not created for compatibility. It is moved to the e2e pkg to be served as a utility function to avoid redundant codes in our tests.

i, err := knuu.NewInstance(executorName)
if err != nil {
return nil, err
}

if err := i.SetImage(executorDefaultImage); err != nil {
return nil, err
}

if err := i.Commit(); err != nil {
return nil, err
}

if err := i.SetArgs(sleepCommand, infinityArg); err != nil {
return nil, err
}

if err := i.SetMemory(executorMemoryLimit.String(), executorMemoryLimit.String()); err != nil {
return nil, err
}

if err := i.SetCPU(executorCpuLimit.String()); err != nil {
return nil, err
}

if err := i.Start(); err != nil {
return nil, err
}

return i, nil
}
2 changes: 1 addition & 1 deletion e2e/system/build_from_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestBuildFromGitWithModifications(t *testing.T) {

logger := logrus.New()

k8sClient, err := k8s.NewClient(ctx, knuu.DefaultTestScope(), logger)
k8sClient, err := k8s.NewClient(ctx, knuu.DefaultScope(), logger)
require.NoError(t, err, "Error creating k8s client")

// Since we are modifying the git repo,
Expand Down
6 changes: 4 additions & 2 deletions e2e/system/env_to_json_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -10,14 +11,15 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/knuu"
)

func TestEnvToJSON(t *testing.T) {
t.Parallel()

// Setup
executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "env-to-json-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestEnvToJSON(t *testing.T) {
}

t.Cleanup(func() {
all := append(instances, executor.Instance)
all := append(instances, executor)
require.NoError(t, knuu.BatchDestroy(all...))
})

Expand Down
6 changes: 4 additions & 2 deletions e2e/system/external_file_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package system

import (
"context"
"io"
"os"
"testing"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/knuu"

"github.com/stretchr/testify/assert"
Expand All @@ -15,7 +17,7 @@ func TestExternalFile(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "external-file-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -69,7 +71,7 @@ func TestExternalFile(t *testing.T) {
}

t.Cleanup(func() {
require.NoError(t, knuu.BatchDestroy(executor.Instance, server))
require.NoError(t, knuu.BatchDestroy(executor, server))
})

// Test logic
Expand Down
5 changes: 3 additions & 2 deletions e2e/system/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/knuu"

"github.com/google/uuid"
Expand All @@ -21,7 +22,7 @@ func TestFile(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "file-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestFile(t *testing.T) {
}

t.Cleanup(func() {
require.NoError(t, knuu.BatchDestroy(executor.Instance, serverfile))
require.NoError(t, knuu.BatchDestroy(executor, serverfile))
})

// Test logic
Expand Down
3 changes: 2 additions & 1 deletion e2e/system/file_test_image_cached_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"context"
"fmt"
"sync"
"testing"
Expand All @@ -14,7 +15,7 @@ import (
func TestFileCached(t *testing.T) {
t.Parallel()
// Setup
executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "file-cached-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions e2e/system/files_to_volumes_cm_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"context"
"fmt"
"strings"
"sync"
Expand All @@ -20,7 +21,7 @@ func TestNoVolumesNoFiles(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "no-volumes-no-files-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestOneVolumeNoFiles(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "one-volume-no-files-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -147,7 +148,7 @@ func TestOneVolumeNoFiles(t *testing.T) {
func TestNoVolumesOneFile(t *testing.T) {
t.Parallel()
// Setup
executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "no-volumes-one-file-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestOneVolumeOneFile(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "one-volume-one-file-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -311,7 +312,7 @@ func TestOneVolumeTwoFiles(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "one-volume-two-files-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions e2e/system/folder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,7 +15,7 @@ func TestFolder(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "folder-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand All @@ -32,7 +33,7 @@ func TestFolder(t *testing.T) {
}

t.Cleanup(func() {
require.NoError(t, knuu.BatchDestroy(executor.Instance, web))
require.NoError(t, knuu.BatchDestroy(executor, web))
})

// Test logic
Expand Down
3 changes: 2 additions & 1 deletion e2e/system/folder_test_image_cached_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"context"
"fmt"
"sync"
"testing"
Expand All @@ -15,7 +16,7 @@ func TestFolderCached(t *testing.T) {
t.Parallel()

// Setup
executor, err := knuu.NewExecutor()
executor, err := e2e.NewExecutor(context.Background(), "folder-cached-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/tshark/tshark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestTshark(t *testing.T) {
ctx := context.Background()

logger := logrus.New()
k8sClient, err := k8s.NewClient(ctx, knuu.DefaultTestScope(), logger)
k8sClient, err := k8s.NewClient(ctx, knuu.DefaultScope(), logger)
require.NoError(t, err, "error creating k8s client")

minioClient, err := minio.New(ctx, k8sClient, logger)
Expand All @@ -50,7 +50,7 @@ func TestTshark(t *testing.T) {
}
}()

scope := kn.Scope()
scope := kn.Scope
t.Logf("Test scope: %s", scope)

target, err := kn.NewInstance("busybox")
Expand Down
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module github.com/celestiaorg/knuu

go 1.22.4
go 1.22.5

require (
github.com/celestiaorg/bittwister v0.0.0-20231213180407-65cdbaf5b8c7
github.com/docker/docker v26.1.4+incompatible
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/minio/minio-go/v7 v7.0.73
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
k8s.io/api v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
)

Expand Down Expand Up @@ -45,6 +44,7 @@ require (
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -59,8 +59,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.15.0 // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
Loading
Loading