diff --git a/e2e/plugin/plugin.go b/e2e/plugin/plugin.go index 6159814f..a03db5ae 100644 --- a/e2e/plugin/plugin.go +++ b/e2e/plugin/plugin.go @@ -192,4 +192,14 @@ var _ = ginkgo.Describe("Plugin test", func() { WithTimeout(pollingDurationLong). Should(gomega.BeTrue()) }) + + ginkgo.It("check the interceptor", func() { + // wait for secret to become synced + vPod := &corev1.Pod{} + err := f.VclusterCRClient.Get(f.Context, types.NamespacedName{Name: "stuff", Namespace: "test"}, vPod) + framework.ExpectNoError(err) + + // check if secret is synced correctly + framework.ExpectEqual(vPod.Name, "definitelynotstuff") + }) }) diff --git a/e2e/test_plugin/main.go b/e2e/test_plugin/main.go index 3d2bb504..e71082b6 100644 --- a/e2e/test_plugin/main.go +++ b/e2e/test_plugin/main.go @@ -31,6 +31,7 @@ func main() { plugin.MustRegister(syncers.NewMyDeploymentSyncer(ctx)) plugin.MustRegister(syncers.NewCarSyncer(ctx)) plugin.MustRegister(syncers.NewImportSecrets(ctx)) + plugin.MustRegister(syncers.DummyInterceptor{}) plugin.MustStart() } diff --git a/e2e/test_plugin/syncers/interceptor.go b/e2e/test_plugin/syncers/interceptor.go new file mode 100644 index 00000000..80edfeb5 --- /dev/null +++ b/e2e/test_plugin/syncers/interceptor.go @@ -0,0 +1,52 @@ +package syncers + +import ( + "net/http" + + "github.com/loft-sh/vcluster-sdk/plugin" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/apiserver/pkg/endpoints/handlers/negotiation" + "k8s.io/apiserver/pkg/endpoints/handlers/responsewriters" + + v2 "github.com/loft-sh/vcluster/pkg/plugin/v2" + corev1 "k8s.io/api/core/v1" +) + +var _ plugin.Interceptor = DummyInterceptor{} + +type DummyInterceptor struct { +} + +func (d DummyInterceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) { + s := serializer.NewCodecFactory(runtime.NewScheme()) + responsewriters.WriteObjectNegotiated( + s, + negotiation.DefaultEndpointRestrictions, + schema.GroupVersion{ + Group: "", + Version: "v1"}, + w, + r, + 200, + &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "definitelynotstuff"}}, + false) +} + +func (d DummyInterceptor) Name() string { + return "test_interceptor" +} + +func (d DummyInterceptor) InterceptedRequests() []v2.Interceptor { + return []v2.Interceptor{ + { + HandlerName: "test_handler", + APIGroups: []string{""}, + Resources: []string{"pods"}, + ResourceNames: []string{"stuff"}, + Verbs: []string{"list"}, + }, + } +}