diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b24115453..ee2f25950 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -205,6 +205,19 @@ jobs: -f ${{ matrix.test-suite-path }}/values.yaml \ "${extraArgs[@]}" continue-on-error: true + + - name: Install metrics server in host cluster + uses: 'deliverybot/helm@v1' + id: install-metrics-server + with: + release: metrics-server + namespace: kube-system + chart: metrics-server + repo: https://kubernetes-sigs.github.io/metrics-server/ + version: 3.11.0 + values: |- + defaultArgs: + - --kubelet-insecure-tls - name: Wait until vcluster is ready id: wait-until-vcluster-is-ready diff --git a/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go b/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go new file mode 100644 index 000000000..8d707dbea --- /dev/null +++ b/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go @@ -0,0 +1,56 @@ +package e2emetricsproxy + +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" + // Register tests +) + +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) +} + +// TestRunE2ETargetNamespaceTests 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 TestRunE2ETargetNamespaceTests(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 e2eProxyMetricsServer suite") +} diff --git a/test/e2e_metrics_proxy/metricsProxy.go b/test/e2e_metrics_proxy/metricsProxy.go new file mode 100644 index 000000000..b54f0ae04 --- /dev/null +++ b/test/e2e_metrics_proxy/metricsProxy.go @@ -0,0 +1,36 @@ +package e2emetricsproxy + +import ( + "context" + "time" + + "github.com/loft-sh/vcluster/pkg/metricsapiservice" + "github.com/loft-sh/vcluster/test/framework" + "github.com/onsi/ginkgo/v2" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" + apiregistrationv1clientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1" +) + +var _ = ginkgo.Describe("Target Namespace", func() { + f := framework.DefaultFramework + + ginkgo.It("Make sure the metrics api service is registered and available", func() { + err := wait.PollUntilContextTimeout(f.Context, time.Second, time.Minute*1, false, func(ctx context.Context) (done bool, err error) { + apiRegistrationClient := apiregistrationv1clientset.NewForConfigOrDie(f.VclusterConfig) + apiService, err := apiRegistrationClient.APIServices().Get(f.Context, metricsapiservice.MetricsAPIServiceName, metav1.GetOptions{}) + if err != nil { + return false, nil + } + + if apiService.Status.Conditions[0].Type != apiregistrationv1.Available { + return false, nil + } + + return true, nil + }) + framework.ExpectNoError(err) + }) +}) diff --git a/test/e2e_metrics_proxy/values.yaml b/test/e2e_metrics_proxy/values.yaml new file mode 100644 index 000000000..c3d366048 --- /dev/null +++ b/test/e2e_metrics_proxy/values.yaml @@ -0,0 +1,6 @@ +proxy: + metricsServer: + nodes: + enabled: true + pods: + enabled: true \ No newline at end of file