Copilot commented on code in PR #2572: URL: https://github.com/apache/apisix-ingress-controller/pull/2572#discussion_r2371417699
########## test/e2e/gatewayapi/webhook.go: ########## @@ -0,0 +1,94 @@ +// 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 gatewayapi + +import ( + "fmt" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" +) + +var _ = Describe("Test Gateway Webhook", Label("networking.k8s.io", "gateway"), func() { + s := scaffold.NewScaffold(scaffold.Options{ + Name: "gateway-webhook-test", + EnableWebhook: true, + }) + + It("should warn when referenced GatewayProxy does not exist on create and update", func() { + By("creating GatewayClass with controller name") + err := s.CreateResourceFromString(s.GetGatewayClassYaml()) + Expect(err).ShouldNot(HaveOccurred()) + + time.Sleep(2 * time.Second) + + By("creating Gateway referencing a missing GatewayProxy") + missingName := "missing-proxy" + gwYAML := ` +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: %s +spec: + gatewayClassName: %s + listeners: + - name: http1 + protocol: HTTP + port: 80 + infrastructure: + parametersRef: + group: apisix.apache.org + kind: GatewayProxy + name: %s +` + + output, err := s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(gwYAML, s.Namespace(), s.Namespace(), missingName)) + Expect(err).ShouldNot(HaveOccurred()) + Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced GatewayProxy '%s/%s' not found.", s.Namespace(), missingName))) + + time.Sleep(2 * time.Second) + + By("updating Gateway to reference another missing GatewayProxy") + missingName2 := "missing-proxy-2" + output, err = s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(gwYAML, s.Namespace(), s.Namespace(), missingName2)) Review Comment: This appears to be creating a new resource with the same name rather than updating the existing Gateway. Consider using an update operation or a different resource name to make the test intention clearer. ```suggestion output, err = s.ApplyResourceFromStringAndGetOutput(fmt.Sprintf(gwYAML, s.Namespace(), s.Namespace(), missingName2)) ``` ########## test/e2e/ingress/ingressclass_webhook.go: ########## @@ -0,0 +1,83 @@ +// 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 ingress + +import ( + "fmt" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" +) + +var _ = Describe("Test IngressClass Webhook", Label("networking.k8s.io", "ingressclass"), func() { + s := scaffold.NewScaffold(scaffold.Options{ + Name: "ingressclass-webhook-test", + EnableWebhook: true, + }) + + Context("IngressClass Validation", func() { + It("should warn when referenced GatewayProxy does not exist on create and update", func() { + By("creating IngressClass referencing a missing GatewayProxy") + missingName := "missing-proxy" + icYAML := ` +apiVersion: networking.k8s.io/v1 +kind: IngressClass +metadata: + name: apisix-with-missing +spec: + controller: "%s" + parameters: + apiGroup: "apisix.apache.org" + kind: "GatewayProxy" + name: "%s" + namespace: "%s" + scope: "Namespace" +` + + output, err := s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(icYAML, s.GetControllerName(), missingName, s.Namespace())) + Expect(err).ShouldNot(HaveOccurred()) + Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced GatewayProxy '%s/%s' not found.", s.Namespace(), missingName))) + + time.Sleep(2 * time.Second) + + By("updating IngressClass to reference another missing GatewayProxy") + missingName2 := "missing-proxy-2" + output, err = s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(icYAML, s.GetControllerName(), missingName2, s.Namespace())) Review Comment: This appears to be creating a new resource with the same name 'apisix-with-missing' rather than updating the existing one. Consider using an update operation or a different resource name to make the test intention clearer. ```suggestion output, err = s.UpdateResourceFromStringAndGetOutput(fmt.Sprintf(icYAML, s.GetControllerName(), missingName2, s.Namespace())) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
