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
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /app

RUN apt update \
&& apt install -y git \
&& git clone --branch main https://github.com/api7/adc.git \
&& git clone --depth 1 --branch main https://github.com/api7/adc.git \
&& cd adc \
&& corepack enable pnpm \
&& pnpm install \
Expand Down
10 changes: 5 additions & 5 deletions api/adc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ type ConsumerGroup struct {

// +k8s:deepcopy-gen=true
type Consumer struct {
Credentials []Credential `json:"credentials,omitempty" yaml:"credentials,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
Username string `json:"username" yaml:"username"`
Metadata `json:",inline" yaml:",inline"`

Credentials []Credential `json:"credentials,omitempty" yaml:"credentials,omitempty"`
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
Username string `json:"username" yaml:"username"`
}

// +k8s:deepcopy-gen=true
Expand Down
8 changes: 1 addition & 7 deletions api/adc/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/provider/adc/translator/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

adctypes "github.com/apache/apisix-ingress-controller/api/adc"
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/provider"
)

Expand Down Expand Up @@ -65,7 +66,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext,
credentials = append(credentials, credential)
}
consumer.Credentials = credentials

consumer.Labels = label.GenLabel(consumerV)
plugins := adctypes.Plugins{}
for _, plugin := range consumerV.Spec.Plugins {
pluginName := plugin.Name
Expand Down
267 changes: 267 additions & 0 deletions test/e2e/api7/gatewayproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
// Licensed 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 gatewayapi

import (
"fmt"
"net/http"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)

var _ = Describe("Test GatewayProxy", func() {
s := scaffold.NewDefaultScaffold()

var defaultGatewayClass = `
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: %s
spec:
controllerName: %s
`

var gatewayWithProxy = `
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: apisix
spec:
gatewayClassName: %s
listeners:
- name: http
protocol: HTTP
port: 80
infrastructure:
parametersRef:
group: apisix.apache.org
kind: GatewayProxy
name: apisix-proxy-config
`

var gatewayProxyWithEnabledPlugin = `
apiVersion: apisix.apache.org/v1alpha1
kind: GatewayProxy
metadata:
name: apisix-proxy-config
spec:
provider:
type: ControlPlane
controlPlane:
endpoints:
- %s
auth:
type: AdminKey
adminKey:
value: "%s"
plugins:
- name: response-rewrite
enabled: true
config:
headers:
X-Proxy-Test: "enabled"
`
var (
gatewayProxyWithPluginMetadata0 = `
apiVersion: apisix.apache.org/v1alpha1
kind: GatewayProxy
metadata:
name: apisix-proxy-config
spec:
provider:
type: ControlPlane
controlPlane:
endpoints:
- %s
auth:
type: AdminKey
adminKey:
value: "%s"
plugins:
- name: error-page
enabled: true
config: {}
pluginMetadata:
error-page: {
"enable": true,
"error_404": {
"body": "404 from plugin metadata",
"content-type": "text/plain"
}
}
`
gatewayProxyWithPluginMetadata1 = `
apiVersion: apisix.apache.org/v1alpha1
kind: GatewayProxy
metadata:
name: apisix-proxy-config
spec:
provider:
type: ControlPlane
controlPlane:
endpoints:
- %s
auth:
type: AdminKey
adminKey:
value: "%s"
plugins:
- name: error-page
enabled: true
config: {}
pluginMetadata:
error-page: {
"enable": false,
"error_404": {
"body": "404 from plugin metadata",
"content-type": "text/plain"
}
}
`
)

var httpRouteForTest = `
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: test-route
spec:
parentRefs:
- name: %s
hostnames:
- example.com
rules:
- matches:
- path:
type: Exact
value: /get
backendRefs:
- name: httpbin-service-e2e-test
port: 80
`

var resourceApplied = func(resourceType, resourceName, resourceRaw string, observedGeneration int) {
Expect(s.CreateResourceFromString(resourceRaw)).
NotTo(HaveOccurred(), fmt.Sprintf("creating %s", resourceType))

Eventually(func() string {
hryaml, err := s.GetResourceYaml(resourceType, resourceName)
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("getting %s yaml", resourceType))
return hryaml
}).WithTimeout(8*time.Second).ProbeEvery(2*time.Second).
Should(
SatisfyAll(
ContainSubstring(`status: "True"`),
ContainSubstring(fmt.Sprintf("observedGeneration: %d", observedGeneration)),
),
fmt.Sprintf("checking %s condition status", resourceType),
)
time.Sleep(3 * time.Second)
}

var (
gatewayClassName string
)

BeforeEach(func() {
By("Create GatewayClass")
gatewayClassName = fmt.Sprintf("apisix-%d", time.Now().Unix())
err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "")
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
time.Sleep(5 * time.Second)

By("Check GatewayClass condition")
gcYaml, err := s.GetResourceYaml("GatewayClass", gatewayClassName)
Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml")
Expect(gcYaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status")
Expect(gcYaml).To(ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), "checking GatewayClass condition message")

By("Create GatewayProxy with enabled plugin")
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithEnabledPlugin, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with enabled plugin")
time.Sleep(5 * time.Second)

By("Create Gateway with GatewayProxy")
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayWithProxy, gatewayClassName), s.Namespace())
Expect(err).NotTo(HaveOccurred(), "creating Gateway with GatewayProxy")
time.Sleep(5 * time.Second)

By("check Gateway condition")
gwyaml, err := s.GetResourceYaml("Gateway", "apisix")
Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml")
Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status")
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message")
})

AfterEach(func() {
By("Clean up resources")
_ = s.DeleteResourceFromString(fmt.Sprintf(httpRouteForTest, "apisix"))
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayWithProxy, gatewayClassName))
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayProxyWithEnabledPlugin, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
})

Context("Test Gateway with PluginMetadata", func() {
var (
err error
)

PIt("Should work OK with error-page", func() {
By("Update GatewayProxy with PluginMetadata")
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata0, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(5 * time.Second)

By("Create HTTPRoute for Gateway with GatewayProxy")
resourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "apisix"), 1)

time.Sleep(5 * time.Second)
By("Check PluginMetadata working")
s.NewAPISIXClient().
GET("/not-found").
WithHost("example.com").
Expect().
Status(http.StatusNotFound).
Body().Contains("404 from plugin metadata")

By("Update GatewayProxy with PluginMetadata")
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata1, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(5 * time.Second)

By("Check PluginMetadata working")
s.NewAPISIXClient().
GET("/not-found").
WithHost("example.com").
Expect().
Status(http.StatusNotFound).
Body().Contains(`{"error_msg":"404 Route Not Found"}`)

By("Delete GatewayProxy")
err = s.DeleteResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata0, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(5 * time.Second)

By("Check PluginMetadata is not working")
s.NewAPISIXClient().
GET("/not-found").
WithHost("example.com").
Expect().
Status(http.StatusNotFound).
Body().Contains(`{"error_msg":"404 Route Not Found"}`)
})
})
})
2 changes: 1 addition & 1 deletion test/e2e/crds/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)

var _ = PDescribe("Test Consumer", func() {
var _ = Describe("Test Consumer", func() {
s := scaffold.NewDefaultScaffold()

var defaultGatewayProxy = `
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

_ "github.com/apache/apisix-ingress-controller/test/e2e/api7"
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds"
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
Expand Down
Loading