mirror of
https://github.com/clastix/kamaji.git
synced 2026-02-14 10:00:02 +00:00
This change extends Gateway API support to Konnectivity addons. When `spec.controlPlane.gateway` is configured and Konnectivity addon is enabled, Kamaji automatically creates two TLSRoutes: 1. A Control plane TLSRoute (port 6443, sectionName "kube-apiserver") 2. A Konnectivity TLSRoute (port 8132, sectionName "konnectivity-server") Both routes use the hostname specified in `gateway.hostname` and reference the same Gateway resource via `parentRefs`, with `port` and `sectionName` set automatically by Kamaji. This patch also adds CEL validation to prevent users from specifying `port` or `sectionName` in Gateway `parentRefs`, as these fields are now managed automatically by Kamaji. Signed-off-by: Parth Yadav <parth@coredge.io>
110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
// Copyright 2022 Clastix Labs
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
"k8s.io/client-go/rest"
|
|
pointer "k8s.io/utils/ptr"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
|
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
|
|
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
|
|
|
|
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
|
|
)
|
|
|
|
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
|
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
|
|
|
var (
|
|
cfg *rest.Config
|
|
k8sClient client.Client
|
|
testEnv *envtest.Environment
|
|
)
|
|
|
|
func TestAPIs(t *testing.T) {
|
|
RegisterFailHandler(Fail)
|
|
|
|
RunSpecs(t, "Controller Suite")
|
|
}
|
|
|
|
var _ = AfterEach(func() {
|
|
PrintTenantControlPlaneInfo()
|
|
PrintKamajiLogs()
|
|
})
|
|
|
|
var _ = BeforeSuite(func() {
|
|
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
|
|
|
|
By("bootstrapping test environment")
|
|
testEnv = &envtest.Environment{
|
|
UseExistingCluster: pointer.To(true),
|
|
}
|
|
|
|
var err error
|
|
|
|
cfg, err = testEnv.Start()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(cfg).NotTo(BeNil())
|
|
|
|
err = kamajiv1alpha1.AddToScheme(scheme.Scheme)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = gatewayv1.Install(scheme.Scheme)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = gatewayv1alpha2.Install(scheme.Scheme)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
//+kubebuilder:scaffold:scheme
|
|
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(k8sClient).NotTo(BeNil())
|
|
|
|
By("creating GatewayClass for Gateway API tests")
|
|
gatewayClass := &gatewayv1.GatewayClass{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "envoy-gw-class",
|
|
},
|
|
Spec: gatewayv1.GatewayClassSpec{
|
|
ControllerName: "gateway.envoyproxy.io/gatewayclass-controller",
|
|
},
|
|
}
|
|
Expect(k8sClient.Create(context.Background(), gatewayClass)).NotTo(HaveOccurred())
|
|
|
|
By("creating Gateway with kube-apiserver and konnectivity-server listeners")
|
|
CreateGatewayWithListeners("test-gateway", "default", "envoy-gw-class", "*.example.com")
|
|
})
|
|
|
|
var _ = AfterSuite(func() {
|
|
By("deleting Gateway resources")
|
|
gateway := &gatewayv1.Gateway{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-gateway",
|
|
Namespace: "default",
|
|
},
|
|
}
|
|
_ = k8sClient.Delete(context.Background(), gateway)
|
|
|
|
gatewayClass := &gatewayv1.GatewayClass{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "envoy-gw-class",
|
|
},
|
|
}
|
|
_ = k8sClient.Delete(context.Background(), gatewayClass)
|
|
|
|
By("tearing down the test environment")
|
|
err := testEnv.Stop()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
})
|