Skip to content

Commit

Permalink
test: improve e2e test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Jan 30, 2024
1 parent b6f2c20 commit 1c31ae4
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:
cancel-in-progress: true

env:
VCLUSTER_VERSION: v0.19.0-alpha.3
VCLUSTER_VERSION: v0.19.0-alpha.4
VCLUSTER_SUFFIX: vcluster
VCLUSTER_NAME: vcluster
VCLUSTER_NAMESPACE: vcluster
Expand Down
3 changes: 3 additions & 0 deletions e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/loft-sh/log"
examplev1 "github.com/loft-sh/vcluster-sdk/e2e/test_plugin/apis/v1"
"github.com/loft-sh/vcluster/pkg/scheme"
"github.com/loft-sh/vcluster/test/framework"
ginkgo "github.com/onsi/ginkgo/v2"
Expand All @@ -23,6 +24,8 @@ import (
// generated in this directory, and cluster logs will also be saved.
// This function is called on each Ginkgo node in parallel mode.
func TestRunE2ETests(t *testing.T) {
_ = examplev1.AddToScheme(scheme.Scheme)

gomega.RegisterFailHandler(ginkgo.Fail)
err := framework.CreateFramework(context.Background(), scheme.Scheme)
if err != nil {
Expand Down
90 changes: 89 additions & 1 deletion e2e/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package plugin
import (
"time"

examplev1 "github.com/loft-sh/vcluster-sdk/e2e/test_plugin/apis/v1"
"github.com/loft-sh/vcluster/pkg/util/translate"
"github.com/loft-sh/vcluster/test/framework"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

const (
Expand All @@ -33,13 +36,98 @@ var _ = ginkgo.Describe("Plugin test", func() {
Should(gomega.Equal(1))

// wait for pod to become ready
var podList *corev1.PodList
gomega.Eventually(func() bool {
podList, err := f.VclusterClient.CoreV1().Pods("default").List(f.Context, metav1.ListOptions{})
podList, err = f.VclusterClient.CoreV1().Pods("default").List(f.Context, metav1.ListOptions{})
framework.ExpectNoError(err)
return len(podList.Items) == 1 && podList.Items[0].Status.Phase == corev1.PodRunning
}).
WithPolling(pollingInterval).
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())

// get pod in host cluster
pod := &podList.Items[0]
hostPod := &corev1.Pod{}
err = f.HostCRClient.Get(f.Context, types.NamespacedName{Name: translate.Default.PhysicalName(pod.Name, pod.Namespace), Namespace: translate.Default.PhysicalNamespace(pod.Namespace)}, hostPod)
framework.ExpectNoError(err)

// check if hook worked
framework.ExpectEqual(hostPod.Labels["created-by-plugin"], "pod-hook")
})

ginkgo.It("check crd sync", func() {
car := &examplev1.Car{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "kube-system",
},
Spec: examplev1.CarSpec{
Type: "Audi",
Seats: 4,
},
}

// create car in vcluster
gomega.Eventually(func() bool {
err := f.VclusterCRClient.Create(f.Context, car)
return err == nil
}).
WithPolling(pollingInterval).
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())

// wait for car to become synced
hostCar := &examplev1.Car{}
carName := types.NamespacedName{Name: translate.Default.PhysicalName(car.Name, car.Namespace), Namespace: translate.Default.PhysicalNamespace(car.Namespace)}
gomega.Eventually(func() bool {
err := f.HostCRClient.Get(f.Context, carName, hostCar)
return err == nil
}).
WithPolling(pollingInterval).
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())

// check if car is synced correctly
framework.ExpectEqual(car.Spec.Seats, hostCar.Spec.Seats)
framework.ExpectEqual(car.Spec.Type, hostCar.Spec.Type)
})

ginkgo.It("check hooks work correctly", func() {
// create a new service
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "test123",
Namespace: "default",
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
Ports: []corev1.ServicePort{
{
Name: "test",
Port: int32(1000),
},
},
},
}

// create service
err := f.VclusterCRClient.Create(f.Context, service)
framework.ExpectNoError(err)

// wait for service to become synced
hostService := &corev1.Service{}
gomega.Eventually(func() bool {
err := f.HostCRClient.Get(f.Context, types.NamespacedName{Name: translate.Default.PhysicalName(service.Name, service.Namespace), Namespace: f.VclusterNamespace}, hostService)
return err == nil
}).
WithPolling(pollingInterval).
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())

// check if car is synced correctly
framework.ExpectEqual(len(hostService.Spec.Ports), 2)
framework.ExpectEqual(hostService.Spec.Ports[1].Name, "plugin")
framework.ExpectEqual(hostService.Spec.Ports[1].Port, int32(19000))
})
})
4 changes: 2 additions & 2 deletions e2e/test_plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ func main() {
_ = examplev1.AddToScheme(scheme.Scheme)

ctx := plugin.MustInit()
plugin.MustRegister(syncers.NewMyDeploymentSyncer(ctx))
plugin.MustRegister(syncers.NewCarSyncer(ctx))
plugin.MustRegister(syncers.NewServiceHook())
plugin.MustRegister(syncers.NewPodHook())
plugin.MustRegister(syncers.NewSecretHook())
plugin.MustRegister(syncers.NewMyDeploymentSyncer(ctx))
plugin.MustRegister(syncers.NewCarSyncer(ctx))
plugin.MustStart()
}
2 changes: 1 addition & 1 deletion e2e/test_plugin/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugin:
extraRules:
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "watch"]
verbs: ["create", "update", "get", "list", "watch"]

# Make sure the cluster role is enabled or otherwise the plugin won't be able to watch custom
# resource definitions.
Expand Down
2 changes: 1 addition & 1 deletion examples/bootstrap-with-deployment/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deployments:
chart:
name: vcluster
repo: https://charts.loft.sh
version: v0.19.0-alpha.3
version: v0.19.0-alpha.4
values:
serviceAccount:
create: false
Expand Down
2 changes: 1 addition & 1 deletion examples/bootstrap-with-deployment/devspace_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COLOR_RESET="\033[0m"
if [ ! -f "/vcluster/syncer" ]; then
echo "Downloading vCluster syncer..."
mkdir -p /vcluster
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.3/syncer-linux-$(go env GOARCH)"
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.4/syncer-linux-$(go env GOARCH)"
chmod +x /vcluster/syncer
echo "Successfully downloaded syncer"
fi
Expand Down
4 changes: 2 additions & 2 deletions examples/bootstrap-with-deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/loft-sh/vcluster-mydeployment-example
go 1.21.5

require (
github.com/loft-sh/vcluster v0.19.0-alpha.3
github.com/loft-sh/vcluster v0.19.0-alpha.4
github.com/loft-sh/vcluster-sdk v0.3.2
k8s.io/klog/v2 v2.120.1
)
Expand Down Expand Up @@ -89,7 +89,7 @@ require (
github.com/loft-sh/loftctl/v3 v3.4.0-beta.11 // indirect
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a // indirect
github.com/loft-sh/utils v0.0.29 // indirect
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9 // indirect
github.com/loft-sh/vcluster-values v0.0.0-20240126141411-ad63b49fe451 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
2 changes: 2 additions & 0 deletions examples/bootstrap-with-deployment/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,10 @@ github.com/loft-sh/utils v0.0.29/go.mod h1:9hlX9cGpWHg3mNi/oBlv3X4ePGDMK66k8MbOZ
github.com/loft-sh/vcluster v0.19.0-alpha.2.0.20240126093253-c406db52b881 h1:Q5iqcMUbCTCVaaSEQsBStciGdJzdPvL+fL8NGHraPKU=
github.com/loft-sh/vcluster v0.19.0-alpha.2.0.20240126093253-c406db52b881/go.mod h1:4/gf6+uo39qRRHBXPcYnSCI2tzF/ArmN0/lMHgBLXcM=
github.com/loft-sh/vcluster v0.19.0-alpha.3/go.mod h1:4/gf6+uo39qRRHBXPcYnSCI2tzF/ArmN0/lMHgBLXcM=
github.com/loft-sh/vcluster v0.19.0-alpha.4/go.mod h1:HnsTJRLBqinDlcv+amD21NmlSexnd/yXY5B8dadbIcc=
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9 h1:DP4b3RQkAjYG4S3FiPmCCSEKj24hBabyFaXncal/yU0=
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9/go.mod h1:J34xtWyMbjM+NRgVWxO0IVDB5XYUaX52jPQNqEAhu4M=
github.com/loft-sh/vcluster-values v0.0.0-20240126141411-ad63b49fe451/go.mod h1:J34xtWyMbjM+NRgVWxO0IVDB5XYUaX52jPQNqEAhu4M=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
2 changes: 1 addition & 1 deletion examples/crd-sync/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deployments:
chart:
name: vcluster
repo: https://charts.loft.sh
version: v0.19.0-alpha.3
version: v0.19.0-alpha.4
values:
plugin:
crd-sync:
Expand Down
2 changes: 1 addition & 1 deletion examples/crd-sync/devspace_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COLOR_RESET="\033[0m"
if [ ! -f "/vcluster/syncer" ]; then
echo "Downloading vCluster syncer..."
mkdir -p /vcluster
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.3/syncer-linux-$(go env GOARCH)"
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.4/syncer-linux-$(go env GOARCH)"
chmod +x /vcluster/syncer
echo "Successfully downloaded syncer"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/hooks/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deployments:
chart:
name: vcluster
repo: https://charts.loft.sh
version: v0.19.0-alpha.3
version: v0.19.0-alpha.4
values:
serviceAccount:
create: false
Expand Down
2 changes: 1 addition & 1 deletion examples/hooks/devspace_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COLOR_RESET="\033[0m"
if [ ! -f "/vcluster/syncer" ]; then
echo "Downloading vCluster syncer..."
mkdir -p /vcluster
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.3/syncer-linux-$(go env GOARCH)"
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.4/syncer-linux-$(go env GOARCH)"
chmod +x /vcluster/syncer
echo "Successfully downloaded syncer"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/pull-secret-sync/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deployments:
chart:
name: vcluster
repo: https://charts.loft.sh
version: v0.19.0-alpha.3
version: v0.19.0-alpha.4
values:
plugin:
pull-secret-sync:
Expand Down
2 changes: 1 addition & 1 deletion examples/pull-secret-sync/devspace_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COLOR_RESET="\033[0m"
if [ ! -f "/vcluster/syncer" ]; then
echo "Downloading vCluster syncer..."
mkdir -p /vcluster
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.3/syncer-linux-$(go env GOARCH)"
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.19.0-alpha.4/syncer-linux-$(go env GOARCH)"
chmod +x /vcluster/syncer
echo "Successfully downloaded syncer"
fi
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/go-plugin v1.6.0
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a
github.com/loft-sh/vcluster v0.19.0-alpha.3
github.com/loft-sh/vcluster v0.19.0-alpha.4
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
github.com/loft-sh/jspolicy v0.2.2 // indirect
github.com/loft-sh/loftctl/v3 v3.4.0-beta.11 // indirect
github.com/loft-sh/utils v0.0.29 // indirect
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9 // indirect
github.com/loft-sh/vcluster-values v0.0.0-20240126141411-ad63b49fe451 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a h1:/gqqjKpcHEdFXIX41lx
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a/go.mod h1:YImeRjXH34Yf5E79T7UHBQpDZl9fIaaFRgyZ/bkY+UQ=
github.com/loft-sh/utils v0.0.29 h1:P/MObccXToAZy2QoJSQDJ+OJx1qHitpFHEVj3QBSNJs=
github.com/loft-sh/utils v0.0.29/go.mod h1:9hlX9cGpWHg3mNi/oBlv3X4ePGDMK66k8MbOZGFMDTI=
github.com/loft-sh/vcluster v0.19.0-alpha.3 h1:lfJJyPXXzXolwMVtoLXUl613HqvUEp7DiDFBNmbJF6c=
github.com/loft-sh/vcluster v0.19.0-alpha.3/go.mod h1:4/gf6+uo39qRRHBXPcYnSCI2tzF/ArmN0/lMHgBLXcM=
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9 h1:DP4b3RQkAjYG4S3FiPmCCSEKj24hBabyFaXncal/yU0=
github.com/loft-sh/vcluster-values v0.0.0-20240111090139-51fcf51d7ba9/go.mod h1:J34xtWyMbjM+NRgVWxO0IVDB5XYUaX52jPQNqEAhu4M=
github.com/loft-sh/vcluster v0.19.0-alpha.4 h1:QGmByu+zntfEchqdrIKxwjNCyz/qRqfmrUJWkRbRl7A=
github.com/loft-sh/vcluster v0.19.0-alpha.4/go.mod h1:HnsTJRLBqinDlcv+amD21NmlSexnd/yXY5B8dadbIcc=
github.com/loft-sh/vcluster-values v0.0.0-20240126141411-ad63b49fe451 h1:HGjzE73ZU5oogI4F/ssp2y+SyPiHKpMNulNSWaWY0pU=
github.com/loft-sh/vcluster-values v0.0.0-20240126141411-ad63b49fe451/go.mod h1:J34xtWyMbjM+NRgVWxO0IVDB5XYUaX52jPQNqEAhu4M=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
2 changes: 2 additions & 0 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pkg/errors"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
)

func newManager() Manager {
Expand Down Expand Up @@ -105,6 +106,7 @@ func (m *manager) InitWithOptions(opts Options) (*synccontext.RegisterContext, e
if err != nil {
return nil, err
}
ctrl.SetLogger(logger)
ctx := klog.NewContext(context.Background(), logger)

// now create register context
Expand Down
7 changes: 4 additions & 3 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
import (
synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
syncertypes "github.com/loft-sh/vcluster/pkg/types"
"k8s.io/klog/v2"
)

var (
Expand All @@ -12,7 +13,7 @@ var (
func MustInit() *synccontext.RegisterContext {
ctx, err := defaultManager.Init()
if err != nil {
panic(err)
klog.Fatalf("plugin must init: %v", err)
}

return ctx
Expand All @@ -29,7 +30,7 @@ func InitWithOptions(opts Options) (*synccontext.RegisterContext, error) {
func MustRegister(syncer syncertypes.Base) {
err := defaultManager.Register(syncer)
if err != nil {
panic(err)
klog.Fatalf("plugin must register: %v", err)
}
}

Expand All @@ -40,7 +41,7 @@ func Register(syncer syncertypes.Base) error {
func MustStart() {
err := defaultManager.Start()
if err != nil {
panic(err)
klog.Fatalf("plugin must start: %v", err)
}
}

Expand Down
Loading

0 comments on commit 1c31ae4

Please sign in to comment.