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
1 change: 1 addition & 0 deletions test/e2e/apisix/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
_ "github.com/apache/apisix-ingress-controller/test/e2e/ingress"
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
_ "github.com/apache/apisix-ingress-controller/test/e2e/webhook"
)

// TestAPISIXE2E runs e2e tests using the APISIX standalone mode
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 @@ -31,6 +31,7 @@ import (
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
_ "github.com/apache/apisix-ingress-controller/test/e2e/ingress"
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
_ "github.com/apache/apisix-ingress-controller/test/e2e/webhook"
)

// Run e2e tests using the Ginkgo runner.
Expand Down
63 changes: 63 additions & 0 deletions test/e2e/framework/manifests/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@ webhooks:
- gatewayproxies
failurePolicy: Fail
sideEffects: None
- name: vgrpcroute-v1.kb.io
clientConfig:
service:
name: webhook-service
namespace: {{ .Namespace }}
path: /validate-gateway-networking-k8s-io-v1-grpcroute
caBundle: {{ .CABundle }}
admissionReviewVersions:
- v1
rules:
- operations:
- CREATE
- UPDATE
apiGroups:
- gateway.networking.k8s.io
apiVersions:
- v1
resources:
- grpcroutes
failurePolicy: Fail
sideEffects: None
- name: vhttproute-v1.kb.io
clientConfig:
service:
name: webhook-service
namespace: {{ .Namespace }}
path: /validate-gateway-networking-k8s-io-v1-httproute
caBundle: {{ .CABundle }}
admissionReviewVersions:
- v1
rules:
- operations:
- CREATE
- UPDATE
apiGroups:
- gateway.networking.k8s.io
apiVersions:
- v1
resources:
- httproutes
failurePolicy: Fail
sideEffects: None
- name: vingress-v1.kb.io
clientConfig:
service:
Expand Down Expand Up @@ -188,3 +230,24 @@ webhooks:
- ingressclasses
failurePolicy: Fail
sideEffects: None
- name: vtcproute-v1alpha2.kb.io
clientConfig:
service:
name: webhook-service
namespace: {{ .Namespace }}
path: /validate-gateway-networking-k8s-io-v1alpha2-tcproute
caBundle: {{ .CABundle }}
admissionReviewVersions:
- v1
rules:
- operations:
- CREATE
- UPDATE
apiGroups:
- gateway.networking.k8s.io
apiVersions:
- v1alpha2
resources:
- tcproutes
failurePolicy: Fail
sideEffects: None
88 changes: 88 additions & 0 deletions test/e2e/webhook/apisixconsumer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 webhook

import (
"fmt"
"time"

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

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

var _ = Describe("Test ApisixConsumer Webhook", Label("webhook"), func() {
s := scaffold.NewScaffold(scaffold.Options{
Name: "apisixconsumer-webhook-test",
EnableWebhook: true,
})

BeforeEach(func() {
By("creating GatewayProxy")
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
time.Sleep(5 * time.Second)

By("creating IngressClass")
err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "")
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
time.Sleep(5 * time.Second)
})

It("should warn on missing authentication secrets", func() {
missingSecret := "missing-basic-secret"
consumerName := "webhook-apisixconsumer"
consumerYAML := `
apiVersion: apisix.apache.org/v2
kind: ApisixConsumer
metadata:
name: %s
namespace: %s
spec:
ingressClassName: %s
authParameter:
basicAuth:
secretRef:
name: %s
`

output, err := s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(consumerYAML, consumerName, s.Namespace(), s.Namespace(), missingSecret))
Expect(err).ShouldNot(HaveOccurred())
Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))

By("creating referenced secret")
secretYAML := fmt.Sprintf(`
apiVersion: v1
kind: Secret
metadata:
name: %s
stringData:
username: demo
password: demo
`, missingSecret)
err = s.CreateResourceFromString(secretYAML)
Expect(err).NotTo(HaveOccurred(), "creating basic auth secret")

time.Sleep(2 * time.Second)

output, err = s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(consumerYAML, consumerName, s.Namespace(), s.Namespace(), missingSecret))
Expect(err).ShouldNot(HaveOccurred())
Expect(output).NotTo(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))
})
})
117 changes: 117 additions & 0 deletions test/e2e/webhook/apisixroute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// 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 webhook

import (
"fmt"
"time"

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

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

var _ = Describe("Test ApisixRoute Webhook", Label("webhook"), func() {
s := scaffold.NewScaffold(scaffold.Options{
Name: "apisixroute-webhook-test",
EnableWebhook: true,
})

BeforeEach(func() {
By("creating GatewayProxy")
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
time.Sleep(5 * time.Second)

By("creating IngressClass")
err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "")
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
time.Sleep(5 * time.Second)
})

It("should warn on missing service or secret references", func() {
missingService := "missing-backend"
missingSecret := "missing-plugin-secret"
routeName := "webhook-apisixroute"
routeYAML := `
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: %s
namespace: %s
spec:
ingressClassName: %s
http:
- name: rule-webhook
match:
hosts:
- webhook.example.com
paths:
- /webhook
backends:
- serviceName: %s
servicePort: 80
plugins:
- name: echo
enable: true
secretRef: %s
`

output, err := s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(routeYAML, routeName, s.Namespace(), s.Namespace(), missingService, missingSecret))
Expect(err).ShouldNot(HaveOccurred())
Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced Service '%s/%s' not found", s.Namespace(), missingService)))
Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))

By("creating referenced Service and Secret")
serviceYAML := fmt.Sprintf(`
apiVersion: v1
kind: Service
metadata:
name: %s
spec:
selector:
app: placeholder
ports:
- name: http
port: 80
targetPort: 80
type: ClusterIP
`, missingService)
err = s.CreateResourceFromString(serviceYAML)
Expect(err).NotTo(HaveOccurred(), "creating backend service placeholder")

secretYAML := fmt.Sprintf(`
apiVersion: v1
kind: Secret
metadata:
name: %s
stringData:
config: enabled
`, missingSecret)
err = s.CreateResourceFromString(secretYAML)
Expect(err).NotTo(HaveOccurred(), "creating plugin secret placeholder")

time.Sleep(2 * time.Second)

output, err = s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(routeYAML, routeName, s.Namespace(), s.Namespace(), missingService, missingSecret))
Expect(err).ShouldNot(HaveOccurred())
Expect(output).NotTo(ContainSubstring(fmt.Sprintf("Warning: Referenced Service '%s/%s' not found", s.Namespace(), missingService)))
Expect(output).NotTo(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))
})
})
Loading
Loading