Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kong2kic/global_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func populateKICKongClusterPlugins(content *file.Content, file *KICContent) erro
kongClusterPlugin.APIVersion = ConfigurationKongHQv1
kongClusterPlugin.Kind = KongClusterPluginKind
kongClusterPlugin.Annotations = map[string]string{IngressClass: ClassName}
kongClusterPlugin.Labels = map[string]string{GlobalLabel: GlobalLabelValue}
if plugin.Name != nil {
kongClusterPlugin.PluginName = *plugin.Name
kongClusterPlugin.Name = calculateSlug(*plugin.Name)
Expand Down
99 changes: 97 additions & 2 deletions kong2kic/kong2kic_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func Test_deployManifests(t *testing.T) {
versions := []string{"2.12", "3.0", "3.1", "3.2", "3.3"}
versions := []string{"2.12", "3.0", "3.1", "3.2", "3.3", "3.4", "3.5"}
for _, version := range versions {
t.Run("KIC Version "+version, func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -75,6 +75,29 @@ func Test_deployManifests(t *testing.T) {
dynamicClient, err := dynamic.NewForConfig(config)
require.NoError(t, err)

t.Log("creating Gateway resource for HTTPRoutes")
gatewayGVR, gatewayClassGVR, err := createGatewayResources(t, dynamicClient, kindToResource)
require.NoError(t, err)
defer func() {
// Delete Gateway first
err := dynamicClient.Resource(gatewayGVR).
Namespace(apiv1.NamespaceDefault).
Delete(context.TODO(), "kong", metav1.DeleteOptions{})
if err != nil {
t.Logf("failed to delete Gateway: %v", err)
} else {
t.Log("deleted Gateway: kong")
}
// Then delete GatewayClass
err = dynamicClient.Resource(gatewayClassGVR).
Delete(context.TODO(), "kong", metav1.DeleteOptions{})
if err != nil {
t.Logf("failed to delete GatewayClass: %v", err)
} else {
t.Log("deleted GatewayClass: kong")
}
}()

t.Log("deploying manifests to the cluster")
err = deployManifestsToClusterForVersion(t, dynamicClient, kindToResource, version)
require.NoError(t, err)
Expand Down Expand Up @@ -190,10 +213,82 @@ func deployGatewayAPICRDs(t *testing.T, config *rest.Config) (*clientset.Clients
}

// Wait for CRDs to be available
time.Sleep(2 * time.Second)
time.Sleep(1 * time.Second)
return clientset, nil
}

// Helper function to create Gateway and GatewayClass resources
func createGatewayResources(
t *testing.T,
dynamicClient dynamic.Interface,
kindToResource map[string]string,
) (schema.GroupVersionResource, schema.GroupVersionResource, error) {
// Create GatewayClass first
gatewayClassManifest := `
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kong
spec:
controllerName: konghq.com/kic-gateway-controller
`
gatewayClass := &unstructured.Unstructured{}
err := yaml.Unmarshal([]byte(gatewayClassManifest), gatewayClass)
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}

gatewayClassGVR, err := getGroupVersionResource(gatewayClass, kindToResource)
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}

_, err = dynamicClient.Resource(gatewayClassGVR).
Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}
t.Logf("created GatewayClass: %s", gatewayClass.GetName())

// Then create Gateway
gatewayManifest := `
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong
spec:
gatewayClassName: kong
listeners:
- name: proxy
port: 80
protocol: HTTP
`
gateway := &unstructured.Unstructured{}
err = yaml.Unmarshal([]byte(gatewayManifest), gateway)
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}

gatewayGVR, err := getGroupVersionResource(gateway, kindToResource)
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}

setNamespaceIfNeeded(gateway)

_, err = dynamicClient.Resource(gatewayGVR).
Namespace(gateway.GetNamespace()).
Create(context.TODO(), gateway, metav1.CreateOptions{})
if err != nil {
return schema.GroupVersionResource{}, schema.GroupVersionResource{}, err
}
t.Logf("created Gateway: %s in Namespace: %s", gateway.GetName(), gateway.GetNamespace())

// Wait for the Gateway to be ready
time.Sleep(1 * time.Second)
return gatewayGVR, gatewayClassGVR, nil
}

// Helper function to get Kind to Resource mapping
func getKindToResourceMap(clientset *clientset.Clientset) (map[string]string, error) {
kindToResource := make(map[string]string)
Expand Down
2 changes: 2 additions & 0 deletions kong2kic/testdata/global-plugin-output-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ metadata:
annotations:
konghq.com/tags: cloudops-managed,metrics
kubernetes.io/ingress.class: kong
labels:
global: "true"
name: prometheus
plugin: prometheus
---
2 changes: 2 additions & 0 deletions kong2kic/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
ConfigurationKongHQv1beta1 = "configuration.konghq.com/v1beta1"
GatewayAPIVersionV1 = "gateway.networking.k8s.io/v1"
GatewayAPIVersionV1Beta1 = "gateway.networking.k8s.io/v1beta1"
GlobalLabel = "global"

Check failure on line 50 in kong2kic/utils.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
GlobalLabelValue = "true"
HTTPRouteKind = "HTTPRoute"
IngressAPIVersion = "networking.k8s.io/v1"
IngressClass = "kubernetes.io/ingress.class"
Expand Down
Loading