Skip to content

Commit

Permalink
test: add e2e_plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Jan 12, 2024
1 parent 0f3446a commit 8e8b322
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ jobs:
- distribution: "k3s"
multinamespace-mode: "true"
test-suite-path: "./test/e2e_target_namespace"
- distribution: "k3s"
multinamespace-mode: "true"
test-suite-path: "./test/e2e_plugin"
- distribution: "k3s"
multinamespace-mode: "true"
test-suite-path: "./test/e2e_isolation_mode"
Expand Down Expand Up @@ -279,8 +282,12 @@ jobs:
echo "======================================================================================================================"
kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp'
echo "======================================================================================================================"
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=500
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1
echo "======================================================================================================================"
if [[ "${{ matrix.test-suite-path }}" = "./test/e2e_plugin" ]]; then
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c bootstrap-with-deployment --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c bootstrap-with-deployment --tail=-1
echo "======================================================================================================================"
fi
kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }}
exit 1
Expand All @@ -294,6 +301,10 @@ jobs:
sudo chmod +x $(echo "${{ matrix.test-suite-path }}" | sed "s#./test/##g").test
VCLUSTER_SUFFIX=${{ env.VCLUSTER_SUFFIX }} VCLUSTER_NAME=${{ env.VCLUSTER_NAME }} VCLUSTER_NAMESPACE=${{ env.VCLUSTER_NAMESPACE }} MULTINAMESPACE_MODE=${{ matrix.multinamespace-mode }} ./$(echo "${{ matrix.test-suite-path }}" | sed "s#./test/##g").test -test.v --ginkgo.v --ginkgo.skip='.*NetworkPolicy.*' --ginkgo.fail-fast
if kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p >/dev/null 2>/dev/null; then
echo "vCluster has restarted during testing, failing..."
exit 1
fi
continue-on-error: true

Expand All @@ -305,7 +316,7 @@ jobs:
echo "======================================================================================================================"
kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp'
echo "======================================================================================================================"
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=500
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1
echo "======================================================================================================================"
kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }}
exit 1
2 changes: 1 addition & 1 deletion pkg/plugin/v2/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func (p *GRPCProviderPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker,

// GRPCServer registers the gRPC provider server with the gRPC server that
// go-plugin is standing up.
func (p *GRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
func (p *GRPCProviderPlugin) GRPCServer(_ *plugin.GRPCBroker, _ *grpc.Server) error {
return errors.New("vcluster-plugin only implements gRPC clients")
}
55 changes: 55 additions & 0 deletions test/e2e_plugin/e2e_plugin_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package e2eplugin

import (
"context"
"testing"

"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/test/framework"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"

// Enable cloud provider auth
_ "k8s.io/client-go/plugin/pkg/client/auth"
)

var (
scheme = runtime.NewScheme()
)

func init() {
_ = clientgoscheme.AddToScheme(scheme)
// API extensions are not in the above scheme set,
// and must thus be added separately.
_ = apiextensionsv1beta1.AddToScheme(scheme)
_ = apiextensionsv1.AddToScheme(scheme)
_ = apiregistrationv1.AddToScheme(scheme)
}

// TestRunE2EPluginModeTests checks configuration parameters (specified through flags) and then runs
// E2E tests using the Ginkgo runner.
// If a "report directory" is specified, one or more JUnit test reports will be
// generated in this directory, and cluster logs will also be saved.
// This function is called on each Ginkgo node in parallel mode.
func TestRunE2EPluginModeTests(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
err := framework.CreateFramework(context.Background(), scheme)
if err != nil {
log.GetInstance().Fatalf("Error setting up framework: %v", err)
}

var _ = ginkgo.AfterSuite(func() {
err = framework.DefaultFramework.Cleanup()
if err != nil {
log.GetInstance().Warnf("Error executing testsuite cleanup: %v", err)
}
})

ginkgo.RunSpecs(t, "vCluster e2ePlugin suite")
}
30 changes: 30 additions & 0 deletions test/e2e_plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2eplugin

import (
"time"

"github.com/loft-sh/vcluster/test/framework"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
pollingInterval = time.Second * 2
pollingDurationLong = time.Second * 60
)

var _ = ginkgo.Describe("plugin", func() {
f := framework.DefaultFramework

ginkgo.It("test legacy vCluster plugin", func() {
// check if deployment is there
gomega.Eventually(func() bool {
_, err := f.VclusterClient.AppsV1().Deployments("default").Get(f.Context, "mydeployment", metav1.GetOptions{})
return err == nil
}).
WithPolling(pollingInterval).
WithTimeout(pollingDurationLong).
Should(gomega.BeTrue())
})
})
6 changes: 6 additions & 0 deletions test/e2e_plugin/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Plugin Definition below. This is essentially a valid helm values file that will be merged
# with the other vcluster values during vcluster create or helm install.
plugin:
bootstrap-with-deployment:
image: ghcr.io/loft-sh/vcluster-example-bootstrap-with-deployment:v2
imagePullPolicy: IfNotPresent

0 comments on commit 8e8b322

Please sign in to comment.