Skip to content
Merged
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
99 changes: 99 additions & 0 deletions .github/workflows/gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

name: gateway

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
pull_request:
branches:
- main
- "release-*"
paths-ignore:
- 'docs/**'
- 'java/**'
- 'proposals/**'
- '**.adoc'
- '**.md'
- 'KEYS'
- 'LICENSE'
- 'NOTICE'
push:
branches:
- main
- "release-*"
paths-ignore:
- 'docs/**'
- 'java/**'
- 'proposals/**'
- '**.adoc'
- '**.md'
- 'KEYS'
- 'LICENSE'
- 'NOTICE'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
submodules: recursive

- name: Infra setting
uses: ./.github/actions/infra-setting

- name: Install Envoy
shell: bash
run: |
./e2e/gateway/setup/setup.sh

- name: Install operator
shell: bash
run: |
kubectl create ns camel-k
make install-k8s-global
kubectl wait --for=jsonpath='{.status.phase}'=Ready itp camel-k -n camel-k --timeout=60s

- name: Run test
shell: bash
run: |
set -euo pipefail
# Cleanup function to stop tunnel
cleanup() {
echo "** Stopping Minikube tunnel"
if [[ -n "${TUNNEL_PID-}" ]]; then
kill "$TUNNEL_PID" || true
fi
}
trap cleanup EXIT

echo "** Starting Minikube tunnel (requires sudo)"
minikube tunnel &
TUNNEL_PID=$!

DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-gateway
41 changes: 41 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6043,6 +6043,13 @@ The configuration of Error Handler trait.

Deprecated: no longer in use.

|`gateway` +
*xref:#_camel_apache_org_v1_trait_GatewayTrait[GatewayTrait]*
|


The configuration of Istio trait

|`gc` +
*xref:#_camel_apache_org_v1_trait_GCTrait[GCTrait]*
|
Expand Down Expand Up @@ -7325,6 +7332,39 @@ Discovery client cache to be used, either `disabled`, `disk` or `memory` (defaul
Deprecated: no longer in use.


|===

[#_camel_apache_org_v1_trait_GatewayTrait]
=== GatewayTrait

*Appears on:*

* <<#_camel_apache_org_v1_Traits, Traits>>

The Gateway trait can be used to expose the service associated with the integration
to the outside world with a Kubernetes Gateway API.


[cols="2,2a",options="header"]
|===
|Field
|Description

|`Trait` +
*xref:#_camel_apache_org_v1_trait_Trait[Trait]*
|(Members of `Trait` are embedded into this type.)




|`className` +
string
|


The class name to use for the gateway configuration.


|===

[#_camel_apache_org_v1_trait_GitOpsTrait]
Expand Down Expand Up @@ -9685,6 +9725,7 @@ The list of taints to tolerate, in the form `Key[=Value]:Effect[:Seconds]`
* <<#_camel_apache_org_v1_trait_AffinityTrait, AffinityTrait>>
* <<#_camel_apache_org_v1_trait_CronTrait, CronTrait>>
* <<#_camel_apache_org_v1_trait_GCTrait, GCTrait>>
* <<#_camel_apache_org_v1_trait_GatewayTrait, GatewayTrait>>
* <<#_camel_apache_org_v1_trait_GitOpsTrait, GitOpsTrait>>
* <<#_camel_apache_org_v1_trait_HealthTrait, HealthTrait>>
* <<#_camel_apache_org_v1_trait_IngressTrait, IngressTrait>>
Expand Down
26 changes: 26 additions & 0 deletions e2e/gateway/files/PlatformHttpServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.camel.builder.RouteBuilder;

public class PlatformHttpServer extends RouteBuilder {
@Override
public void configure() throws Exception {
from("platform-http:/hello?httpMethodRestrict=GET")
.setBody(simple("Hello ${header.name}"));
}
}
74 changes: 74 additions & 0 deletions e2e/gateway/gateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//go:build integration
// +build integration

// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"

/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gateway

import (
"context"
"os/exec"
"testing"

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
)

func TestGatewayTrait(t *testing.T) {
t.Parallel()
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java",
"-t", "gateway.enabled=true",
"-t", "gateway.class-name=envoy",
).Execute()).To(Succeed())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "platform-http-server",
v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
g.Eventually(Gateway(t, ctx, ns, "platform-http-server"), TestTimeoutShort).Should(Not(BeNil()))
// Wait for the address to be assigned
var gwAddress string

// IMPORTANT NOTE: this test would likely fail if the Envoy gateway is not able
// to assign an address correctly. In our case we need to make sure to run
// `minikube tunnel` before running this test. It requires sudo.

g.Eventually(func() string {
gw := Gateway(t, ctx, ns, "platform-http-server")()
if gw == nil || len(gw.Status.Addresses) == 0 {
return ""
}
gwAddress = string(gw.Status.Addresses[0].Value)

return gwAddress
}, TestTimeoutShort).ShouldNot(BeEmpty(), "expected gateway to have an assigned address")

g.Eventually(func() (string, error) {
cmd := exec.Command("curl",
"-s",
"-H", "name: test!",
"http://"+gwAddress+":8080/hello",
)
out, err := cmd.CombinedOutput()

return string(out), err
}, TestTimeoutMedium).Should(ContainSubstring("Hello test!"))
})
}
23 changes: 23 additions & 0 deletions e2e/gateway/setup/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: envoy
spec:
controllerName: gateway.envoyproxy.io/gatewayclass-controller
28 changes: 28 additions & 0 deletions e2e/gateway/setup/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

TIMEOUT="150s"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml --server-side
kubectl apply -f https://github.com/envoyproxy/gateway/releases/latest/download/install.yaml --server-side
kubectl wait --for=condition=available deployment/envoy-gateway -n envoy-gateway-system --timeout=$TIMEOUT

# Install gateway classname (not available by default in envoy installation)
kubectl apply -f $SCRIPT_DIR/gateway.yaml
Loading
Loading