You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/06 13:54:15 UTC

[GitHub] [apisix-ingress-controller] fgksgf opened a new pull request #667: feat: add webhooks for consumer/tls/upstream

fgksgf opened a new pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667


   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bugfix
   - [x] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   
   - Related issues
   
   ___
   ### New feature or improvement
   - Describe the details and related test reports.
   
   Add webhooks for consumer/tls/upstream.
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-925553078


   @fgksgf you can just fix the lint error. then we can move forward.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] fgksgf commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
fgksgf commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-923703549


   I just found that there is already basic validation in CRDs, so could you provide some cases that can not be validated in CRD, then I will replace the logic in webhooks with yours.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r703114882



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+
+		cs, err := client.GetConsumerSchema(ctx)
+		if err != nil {
+			msg := "failed to get consumer's schema"
+			log.Errorf("%s: %s", msg, err)

Review comment:
       Ditto.

##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)

Review comment:
       ```suggestion
   			log.Errorf("failed to get schema client: %s", err)
   ```

##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")

Review comment:
       Is this object used in other places? Or we don't have to export it.

##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+
+		cs, err := client.GetConsumerSchema(ctx)
+		if err != nil {
+			msg := "failed to get consumer's schema"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+		acSchemaLoader := gojsonschema.NewStringLoader(cs.Content)
+
+		var msg []string

Review comment:
       Why use slice? Only one place uses it.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-925602327


   @fgksgf I think, it's a GitHub Action's bug. 
   
   I have trigerd it on my fork using same env. It can be pass. https://github.com/tao12345666333/ingress-controller/runs/3684766821?check_suite_focus=true


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] fgksgf commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
fgksgf commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r703950141



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")

Review comment:
       ok




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
gxthrj commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-930648062


   Yes, I have checked the lint too, it can pass.
   
   If there is no other need to modify, we can merge this PR. cc @tao12345666333 @tokers @lingsamuel 


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tokers commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-925696985


   > We can skip the lint error.
   > WDYT? @gxthrj @tokers
   
   Agree, we already have our own lints.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj merged pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
gxthrj merged pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667


   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-913670061


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#667](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (15f7e21) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/6a8658db1788c687c70c9f235601cc8224e0b38c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6a8658d) will **decrease** coverage by `0.20%`.
   > The diff coverage is `11.27%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #667      +/-   ##
   ==========================================
   - Coverage   34.77%   34.56%   -0.21%     
   ==========================================
     Files          60       63       +3     
     Lines        5916     6027     +111     
   ==========================================
   + Hits         2057     2083      +26     
   - Misses       3608     3700      +92     
   + Partials      251      244       -7     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/api/validation/apisix\_consumer.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF9jb25zdW1lci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_tls.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF90bHMuZ28=) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_upstream.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF91cHN0cmVhbS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9hcGlzaXguZ28=) | `67.50% <ø> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9ub25leGlzdGVudGNsaWVudC5nbw==) | `41.79% <0.00%> (-0.64%)` | :arrow_down: |
   | [pkg/api/validation/apisix\_route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF9yb3V0ZS5nbw==) | `21.42% <10.00%> (-0.11%)` | :arrow_down: |
   | [pkg/api/validation/utils.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL3V0aWxzLmdv) | `32.43% <35.29%> (-13.73%)` | :arrow_down: |
   | [pkg/api/router/webhook.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS9yb3V0ZXIvd2ViaG9vay5nbw==) | `100.00% <100.00%> (ø)` | |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9zY2hlbWEuZ28=) | `64.70% <100.00%> (+1.44%)` | :arrow_up: |
   | ... and [5 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [6a8658d...15f7e21](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-938390148


   ApisixRoute v2beta2 version was introduced in #698
   The corresponding check was not covered in this PR.
   
   Let's merge this PR first, and then increase the coverage of v2beta2 in subsequent PRs.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] lingsamuel commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
lingsamuel commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-930677149


   +1 can't repro. I triggered it again, let's see if it will pass. If not, we may need to create an ignore rule.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] fgksgf commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
fgksgf commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r703950472



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)

Review comment:
       Why we need change it? `msg` can be reused in the return statement on line 61.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r704947142



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)

Review comment:
       OK, just ignore it.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] fgksgf commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
fgksgf commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r703107054



##########
File path: pkg/api/router/webhook.go
##########
@@ -26,5 +26,13 @@ import (
 func MountWebhooks(r *gin.Engine, co *apisix.ClusterOptions) {
 	// init the schema client, it will be used to query schema of objects.
 	_, _ = validation.GetSchemaClient(co)
-	r.POST("/validation/apisixroutes/plugin", gin.WrapH(validation.NewPluginValidatorHandler()))

Review comment:
       Nope, it's in the validation of ApisixRoute now.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-913670061


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#667](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c0f5291) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/6a8658db1788c687c70c9f235601cc8224e0b38c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6a8658d) will **decrease** coverage by `0.25%`.
   > The diff coverage is `28.42%`.
   
   > :exclamation: Current head c0f5291 differs from pull request most recent head d0b1f9e. Consider uploading reports for the commit d0b1f9e to get more accurate results
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #667      +/-   ##
   ==========================================
   - Coverage   34.77%   34.51%   -0.26%     
   ==========================================
     Files          60       63       +3     
     Lines        5916     6078     +162     
   ==========================================
   + Hits         2057     2098      +41     
   - Misses       3608     3729     +121     
     Partials      251      251              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/api/validation/apisix\_consumer.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF9jb25zdW1lci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_tls.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF90bHMuZ28=) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_upstream.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF91cHN0cmVhbS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9hcGlzaXguZ28=) | `67.50% <ø> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9ub25leGlzdGVudGNsaWVudC5nbw==) | `41.79% <0.00%> (-0.64%)` | :arrow_down: |
   | [pkg/ingress/apisix\_consumer.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvYXBpc2l4X2NvbnN1bWVyLmdv) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/apisix\_tls.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvYXBpc2l4X3Rscy5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `1.06% <0.00%> (-0.01%)` | :arrow_down: |
   | [pkg/ingress/endpoint.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvZW5kcG9pbnQuZ28=) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/endpointslice.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvZW5kcG9pbnRzbGljZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | ... and [10 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [6a8658d...d0b1f9e](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-913670061


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#667](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d2430ad) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/6a8658db1788c687c70c9f235601cc8224e0b38c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6a8658d) will **decrease** coverage by `0.52%`.
   > The diff coverage is `11.27%`.
   
   > :exclamation: Current head d2430ad differs from pull request most recent head 15f7e21. Consider uploading reports for the commit 15f7e21 to get more accurate results
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #667      +/-   ##
   ==========================================
   - Coverage   34.77%   34.24%   -0.53%     
   ==========================================
     Files          60       63       +3     
     Lines        5916     6027     +111     
   ==========================================
   + Hits         2057     2064       +7     
   - Misses       3608     3712     +104     
     Partials      251      251              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/api/validation/apisix\_consumer.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF9jb25zdW1lci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_tls.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF90bHMuZ28=) | `0.00% <0.00%> (ø)` | |
   | [pkg/api/validation/apisix\_upstream.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF91cHN0cmVhbS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9hcGlzaXguZ28=) | `67.50% <ø> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9ub25leGlzdGVudGNsaWVudC5nbw==) | `41.79% <0.00%> (-0.64%)` | :arrow_down: |
   | [pkg/api/validation/apisix\_route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL2FwaXNpeF9yb3V0ZS5nbw==) | `21.42% <10.00%> (-0.11%)` | :arrow_down: |
   | [pkg/api/validation/utils.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS92YWxpZGF0aW9uL3V0aWxzLmdv) | `32.43% <35.29%> (-13.73%)` | :arrow_down: |
   | [pkg/api/router/webhook.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaS9yb3V0ZXIvd2ViaG9vay5nbw==) | `100.00% <100.00%> (ø)` | |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9zY2hlbWEuZ28=) | `64.70% <100.00%> (+1.44%)` | :arrow_up: |
   | ... and [2 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [6a8658d...15f7e21](https://codecov.io/gh/apache/apisix-ingress-controller/pull/667?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r704947175



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+
+		cs, err := client.GetConsumerSchema(ctx)
+		if err != nil {
+			msg := "failed to get consumer's schema"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+		acSchemaLoader := gojsonschema.NewStringLoader(cs.Content)
+
+		var msg []string

Review comment:
       Got it.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] fgksgf commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
fgksgf commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-925561719


   > @fgksgf you can just fix the lint error. then we can move forward.
   
   I just didn't figure out why the linter report the error:
   ![image](https://user-images.githubusercontent.com/26627380/134468102-aadebd06-16d7-4522-af03-b4ea9fd401c6.png)
   ![image](https://user-images.githubusercontent.com/26627380/134468281-0ddf3cd1-d4bf-4d29-962c-399364d99302.png)
   
   There is no lint errors when I run `make lint` locally.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r703130955



##########
File path: pkg/api/validation/apisix_consumer.go
##########
@@ -0,0 +1,80 @@
+// 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 validation
+
+import (
+	"context"
+	"errors"
+	"strings"
+
+	kwhmodel "github.com/slok/kubewebhook/v2/pkg/model"
+	kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
+	"github.com/xeipuuv/gojsonschema"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix"
+	v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+	"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+// ErrNotApisixConsumer will be used when the validating object is not ApisixConsumer.
+var ErrNotApisixConsumer = errors.New("object is not ApisixConsumer")
+
+// ApisixConsumerValidator validates ApisixConsumer's spec.
+var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
+	func(ctx context.Context, review *kwhmodel.AdmissionReview, object metav1.Object) (result *kwhvalidating.ValidatorResult, err error) {
+		log.Debug("arrive ApisixConsumer validator webhook")
+
+		valid := true
+		var spec interface{}
+
+		switch ac := object.(type) {
+		case *v2beta1.ApisixRoute:
+			spec = ac.Spec
+		case *v2alpha1.ApisixRoute:
+			spec = ac.Spec
+		case *v1.ApisixRoute:
+			spec = ac.Spec
+		default:
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: ErrNotApisixConsumer.Error()}, ErrNotApisixConsumer
+		}
+
+		client, err := GetSchemaClient(&apisix.ClusterOptions{})
+		if err != nil {
+			msg := "failed to get the schema client"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+
+		cs, err := client.GetConsumerSchema(ctx)
+		if err != nil {
+			msg := "failed to get consumer's schema"
+			log.Errorf("%s: %s", msg, err)
+			return &kwhvalidating.ValidatorResult{Valid: false, Message: msg}, err
+		}
+		acSchemaLoader := gojsonschema.NewStringLoader(cs.Content)
+
+		var msg []string

Review comment:
       `msg` contains multiple verification results.
   BTW, `msg` -> `msgs`




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on a change in pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on a change in pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#discussion_r702993280



##########
File path: pkg/api/router/webhook.go
##########
@@ -26,5 +26,13 @@ import (
 func MountWebhooks(r *gin.Engine, co *apisix.ClusterOptions) {
 	// init the schema client, it will be used to query schema of objects.
 	_, _ = validation.GetSchemaClient(co)
-	r.POST("/validation/apisixroutes/plugin", gin.WrapH(validation.NewPluginValidatorHandler()))

Review comment:
       Is the plugin validation missing?




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-930680507


   +1 


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-925602918


   We can skip the lint error. 
   WDYT? @gxthrj @tokers  


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on pull request #667: feat: add webhooks for consumer/tls/upstream

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on pull request #667:
URL: https://github.com/apache/apisix-ingress-controller/pull/667#issuecomment-938425960


   Added a new issue for tracking #703
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org