Skip to content

Commit

Permalink
add recommended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrehman107 committed Feb 10, 2025
1 parent 053e196 commit 112a460
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ test: manifests generate fmt vet envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
.PHONY: test-e2e
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
@command -v kind >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
@kind get clusters | grep -q 'kind' || { \
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
exit 1; \
}
go test ./test/e2e/

.PHONY: lint
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
args:
- --leader-elect
- --health-probe-bind-address=:8081
image: etcd-operator-controller:v0.1
image: etcd-operator-controller:current
name: manager
securityContext:
allowPrivilegeEscalation: false
Expand Down
45 changes: 39 additions & 6 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"log"
"os"
"testing"
"time"

"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/envfuncs"
Expand All @@ -33,7 +36,7 @@ import (

var (
testEnv env.Environment
dockerImage = "etcd-operator-controller:v0.1"
dockerImage = "etcd-operator-controller:current"
namespace = "etcd-operator-system"
)

Expand All @@ -45,9 +48,18 @@ func TestMain(m *testing.M) {
log.Println("Creating KinD cluster...")
origWd, _ := os.Getwd()
testEnv.Setup(
// create KinD cluster and namespace
envfuncs.CreateCluster(kindCluster, kindClusterName),
envfuncs.CreateNamespace(namespace),
// setup up environment
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
// create KinD cluster
var err error
ctx, err = envfuncs.CreateCluster(kindCluster, kindClusterName)(ctx, cfg)
if err != nil {
log.Printf("failed to create cluster: %s", err)
return ctx, err
}

return ctx, nil
},

// prepare the resources
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
Expand Down Expand Up @@ -151,6 +163,17 @@ func TestMain(m *testing.M) {
return ctx, p.Err()
}

// wait for controller to get ready
log.Println("Waiting for controller-manager deployment to be available...")
client := cfg.Client()
if err := wait.For(
conditions.New(client.Resources()).DeploymentAvailable("etcd-operator-controller-manager", "etcd-operator-system"),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(10*time.Second),
); err != nil {
log.Printf("Timed out while waiting for etcd-operator-controller-manager deployment: %s", err)
return ctx, err
}
// set working directory test/e2e
if err := os.Chdir(origWd); err != nil {
log.Printf("Unable to set working directory: %s", err)
Expand Down Expand Up @@ -222,8 +245,18 @@ func TestMain(m *testing.M) {
return ctx, nil
},

// destroy the cluster
envfuncs.DestroyCluster(kindClusterName),
// Destroy environment
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
log.Println("Destroying cluster...")

var err error
ctx, err = envfuncs.DestroyCluster(kindClusterName)(ctx, cfg)
if err != nil {
log.Printf("failed to delete cluster: %s", err)
}

return ctx, nil
},
)

// Use Environment.Run to launch the test
Expand Down

0 comments on commit 112a460

Please sign in to comment.