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/07/19 12:47:52 UTC

[GitHub] [apisix-ingress-controller] fgksgf opened a new pull request #601: feat: implement plugin schema API

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


   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.
   
   Implement plugin API for getting plugin's schema from APISIX.
   


-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       I did it but nothing updates.




-- 
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 #601: feat: implement schema API

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


   


-- 
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 #601: feat: implement schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9cbad13) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/5635652865ef965db58794b08e2fe37ddc9c08e3?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5635652) will **increase** coverage by `0.40%`.
   > The diff coverage is `44.38%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.05%   34.46%   +0.40%     
   ==========================================
     Files          55       57       +2     
     Lines        5544     5722     +178     
   ==========================================
   + Hits         1888     1972      +84     
   - Misses       3430     3504      +74     
   - Partials      226      246      +20     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/ingress/apisix\_cluster\_config.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2luZ3Jlc3MvYXBpc2l4X2NsdXN0ZXJfY29uZmlnLmdv) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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.07% <0.00%> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.20% <31.00%> (+1.87%)` | :arrow_up: |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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% <50.00%> (ø)` | |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `80.00% <80.00%> (ø)` | |
   | ... and [1 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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/601?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 [5635652...9cbad13](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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] fgksgf commented on a change in pull request #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -136,6 +138,9 @@ func newCluster(o *ClusterOptions) (Cluster, error) {
 
 	go c.syncCache()
 
+	ticker := time.NewTicker(o.SyncInterval)

Review comment:
       Where should i put the code that closing the ticker?




-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       Then the title is confusing.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       Signal processing can be unified.




-- 
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 #601: feat: implement schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e370f71) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.70%`.
   > The diff coverage is `50.29%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   35.10%   +0.70%     
   ==========================================
     Files          55       57       +2     
     Lines        5468     5635     +167     
   ==========================================
   + Hits         1881     1978      +97     
   - Misses       3362     3419      +57     
   - Partials      225      238      +13     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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.07% <ø> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `29.79% <34.61%> (+4.46%)` | :arrow_up: |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `100.00% <100.00%> (ø)` | |
   | [pkg/apisix/route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9yb3V0ZS5nbw==) | `37.76% <0.00%> (+2.09%)` | :arrow_up: |
   | ... and [1 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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/601?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 [7291212...e370f71](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 pull request #601: feat: implement schema API

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


   @fgksgf Please check out the CI failure problems, especially for the unit test cases.


-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/schema.go
##########
@@ -0,0 +1,91 @@
+// 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 apisix
+
+import (
+	"context"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix/cache"

Review comment:
       Please categorize the imports, one for 3rd parties, and one for packages in current module.

##########
File path: pkg/apisix/plugin.go
##########
@@ -0,0 +1,49 @@
+// 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 apisix
+
+import (
+	"context"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	"go.uber.org/zap"
+)
+
+type pluginClient struct {
+	url     string
+	cluster *cluster
+}
+
+func newPluginClient(c *cluster) Plugin {
+	return &pluginClient{
+		url:     c.baseURL + "/plugins",
+		cluster: c,
+	}
+}
+
+// List returns the names of all plugins.
+func (p *pluginClient) List(ctx context.Context) ([]string, error) {
+	log.Debugw("try to list plugins' names in APISIX",
+		zap.String("cluster", "default"),
+		zap.String("url", p.url),
+	)
+	pluginList, err := p.cluster.getList(ctx, p.url+"/list")
+	if err != nil {
+		log.Errorf("failed to list plugins' names: %s", err)
+		return nil, err
+	}

Review comment:
       add a debug log to show the plugin list.

##########
File path: pkg/apisix/plugin_test.go
##########
@@ -0,0 +1,104 @@
+// 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 apisix
+
+import (
+	"context"
+	"encoding/json"
+	"github.com/stretchr/testify/assert"

Review comment:
       Please categorize the imports.




-- 
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 #601: feat: implement plugin schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (93fe625) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.18%`.
   > The diff coverage is `41.55%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   34.58%   +0.18%     
   ==========================================
     Files          55       56       +1     
     Lines        5468     5545      +77     
   ==========================================
   + Hits         1881     1918      +37     
   - Misses       3362     3393      +31     
   - Partials      225      234       +9     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `70.93% <0.00%> (-3.92%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.21% <31.57%> (+1.89%)` | :arrow_up: |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `45.83% <37.50%> (-0.60%)` | :arrow_down: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `56.09% <56.09%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/601?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 [7291212...93fe625](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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] gxthrj commented on a change in pull request #601: feat: implement plugin schema API

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



##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       If you changed the types.go, Please use the `make codegen` to genrate code.
   `

##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I am not sure if this url is right. Because I can not see the prefix contains `/schema/plugins/xxx`.
   For example, if we want to get the schema of plugin `kafka-logger`. We can use this `http://127.0.0.1:9080/apisix/admin/schema/plugins/kafka-logger`.




-- 
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 #601: feat: implement schema API

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


   This PR need rebase. 


-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       @fgksgf You may tweak the cluster creation logic, and passing the context to it. Here you can listen to the ctx channel.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       All right, so this comment is about signal processing.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -301,6 +314,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(ctx context.Context, interval time.Duration) {
+	ticker := time.NewTicker(interval)
+	defer ticker.Stop()
+
+	for {
+		if err := c.syncSchemaOnce(ctx); err != nil {
+			log.Warnf("failed to sync schema: %s", err)
+		}
+
+		select {
+		case <-ticker.C:
+			continue
+		case <-ctx.Done():
+			break

Review comment:
       Not `break`, it should be `return`, `break` just let the flow jump out the `select` block but still in the `for` block.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -301,6 +314,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(ctx context.Context, interval time.Duration) {
+	ticker := time.NewTicker(interval)
+	defer ticker.Stop()
+
+	for {
+		if err := c.syncSchemaOnce(ctx); err != nil {
+			log.Warnf("failed to sync schema: %s", err)
+		}
+
+		select {
+		case <-ticker.C:
+			continue
+		case <-ctx.Done():
+			break

Review comment:
       Not `break`, it should be `return`, `break` just let the flow jump out the `select` block but still in the `for` block.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       May not handle the signal notification here.




-- 
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 #601: feat: implement plugin schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (93fe625) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.18%`.
   > The diff coverage is `41.55%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   34.58%   +0.18%     
   ==========================================
     Files          55       56       +1     
     Lines        5468     5545      +77     
   ==========================================
   + Hits         1881     1918      +37     
   - Misses       3362     3393      +31     
   - Partials      225      234       +9     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `70.93% <0.00%> (-3.92%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.21% <31.57%> (+1.89%)` | :arrow_up: |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `45.83% <37.50%> (-0.60%)` | :arrow_down: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `56.09% <56.09%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/601?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 [7291212...93fe625](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       > I think syncing the schema is a normal task to prevent the schema from changing after the APISIX upgrade, which requires a regular task to run in the background all the time. So this is not the same as syncCache.
   
   This is by no means related to the signal handling stuff. Of course, we can do it periodically. A Golang program should only have one place handling the signals.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -301,6 +314,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(ctx context.Context, interval time.Duration) {
+	ticker := time.NewTicker(interval)
+	defer ticker.Stop()
+
+	for {
+		if err := c.syncSchemaOnce(); err != nil {
+			log.Warnf("failed to sync schema: %s", err)
+		}
+
+		select {
+		case <-ticker.C:
+			continue
+		case <-ctx.Done():
+			break
+		}
+	}
+}
+
+// syncSchemaOnce syncs schema from APISIX once.
+// It firstly deletes all the schema in the cache,
+// then queries and inserts to the cache.
+func (c *cluster) syncSchemaOnce() error {

Review comment:
       then how to use 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] tokers commented on a change in pull request #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       cache sync is not an one-kick event, it will be executed once the leader changing.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -136,6 +138,9 @@ func newCluster(o *ClusterOptions) (Cluster, error) {
 
 	go c.syncCache()
 
+	ticker := time.NewTicker(o.SyncInterval)

Review comment:
       here should i put the code that closing the ticker?

##########
File path: pkg/apisix/cluster.go
##########
@@ -136,6 +138,9 @@ func newCluster(o *ClusterOptions) (Cluster, error) {
 
 	go c.syncCache()
 
+	ticker := time.NewTicker(o.SyncInterval)

Review comment:
       Where should i put the code that closing the ticker?




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       But it is different from `syncCache`, which is executed only once. However, the schema needs to be synced regularly, so where should I close the ticker?




-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cache/cache.go
##########
@@ -35,6 +35,8 @@ type Cache interface {
 	InsertGlobalRule(*v1.GlobalRule) error
 	// InsertConsumer adds or updates consumer to cache.
 	InsertConsumer(*v1.Consumer) error
+	// InsertSchema adds or updates schema to cache.
+	InsertSchema(*v1.Schema) error

Review comment:
       `v1.Schema` is the schema of APISIX objects, including plugin, route, upstream, etc. So `InsertSchema` can be reused.

##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       I will add a `Schema` client for getting schema of APISIX objects (including plugin, route, upstream, etc.) and the `Plugin` will be only used to query names of plugins.




-- 
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 #601: feat: implement schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e35a871) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.76%`.
   > The diff coverage is `51.11%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   35.16%   +0.76%     
   ==========================================
     Files          55       57       +2     
     Lines        5468     5648     +180     
   ==========================================
   + Hits         1881     1986     +105     
   - Misses       3362     3424      +62     
   - Partials      225      238      +13     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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.07% <ø> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `30.82% <38.46%> (+5.50%)` | :arrow_up: |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `100.00% <100.00%> (ø)` | |
   | [pkg/apisix/route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9yb3V0ZS5nbw==) | `37.76% <0.00%> (+2.09%)` | :arrow_up: |
   | ... and [1 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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/601?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 [7291212...e35a871](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 edited a comment on pull request #601: feat: implement schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c5d4425) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.40%`.
   > The diff coverage is `44.08%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   34.80%   +0.40%     
   ==========================================
     Files          55       57       +2     
     Lines        5468     5646     +178     
   ==========================================
   + Hits         1881     1965      +84     
   - Misses       3362     3436      +74     
   - Partials      225      245      +20     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/ingress/apisix\_cluster\_config.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2luZ3Jlc3MvYXBpc2l4X2NsdXN0ZXJfY29uZmlnLmdv) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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.07% <0.00%> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.20% <28.88%> (+1.87%)` | :arrow_up: |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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% <50.00%> (ø)` | |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `80.00% <80.00%> (ø)` | |
   | ... and [1 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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/601?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 [7291212...c5d4425](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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] gxthrj commented on a change in pull request #601: feat: implement plugin schema API

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



##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       If you changed the types.go, Please use the `make codegen` to genrate code.
   `

##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I am not sure if this url is right. Because I can not see the prefix contains `/schema/plugins/xxx`.
   For example, if we want to get the schema of plugin `kafka-logger`. We can use this `http://127.0.0.1:9080/apisix/admin/schema/plugins/kafka-logger`.




-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cache/cache.go
##########
@@ -35,6 +35,8 @@ type Cache interface {
 	InsertGlobalRule(*v1.GlobalRule) error
 	// InsertConsumer adds or updates consumer to cache.
 	InsertConsumer(*v1.Consumer) error
+	// InsertSchema adds or updates schema to cache.
+	InsertSchema(*v1.Schema) error

Review comment:
       Better to use `InsertPluginSchema`.

##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       We may use the unified term, This so-called `Plugin` client actually only returns its schema. We may just use the term `PluginSchema`.




-- 
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 #601: feat: implement schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9cbad13) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/5635652865ef965db58794b08e2fe37ddc9c08e3?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5635652) will **increase** coverage by `0.40%`.
   > The diff coverage is `44.38%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.05%   34.46%   +0.40%     
   ==========================================
     Files          55       57       +2     
     Lines        5544     5722     +178     
   ==========================================
   + Hits         1888     1972      +84     
   - Misses       3430     3504      +74     
   - Partials      226      246      +20     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/ingress/apisix\_cluster\_config.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2luZ3Jlc3MvYXBpc2l4X2NsdXN0ZXJfY29uZmlnLmdv) | `0.00% <0.00%> (ø)` | |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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.07% <0.00%> (ø)` | |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.20% <31.00%> (+1.87%)` | :arrow_up: |
   | [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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% <50.00%> (ø)` | |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `80.00% <80.00%> (ø)` | |
   | ... and [1 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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/601?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 [5635652...9cbad13](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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] fgksgf commented on a change in pull request #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I found `/apisix/admin/schema/plugins/<plugin_name>` and `/apisix/admin/plugins/<plugin_name>` return the same result.

##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       I did it but nothing updates.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -301,6 +314,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(ctx context.Context, interval time.Duration) {
+	ticker := time.NewTicker(interval)
+	defer ticker.Stop()
+
+	for {
+		if err := c.syncSchemaOnce(); err != nil {
+			log.Warnf("failed to sync schema: %s", err)
+		}
+
+		select {
+		case <-ticker.C:
+			continue
+		case <-ctx.Done():
+			break
+		}
+	}
+}
+
+// syncSchemaOnce syncs schema from APISIX once.
+// It firstly deletes all the schema in the cache,
+// then queries and inserts to the cache.
+func (c *cluster) syncSchemaOnce() error {

Review comment:
       `context.TODO()` are used in some places, you can replace them with the passed-in context.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       updated




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -136,6 +138,9 @@ func newCluster(o *ClusterOptions) (Cluster, error) {
 
 	go c.syncCache()
 
+	ticker := time.NewTicker(o.SyncInterval)

Review comment:
       Since this ticker is used by `syncSchema`, just created it inside it.

##########
File path: pkg/apisix/cluster_test.go
##########
@@ -20,6 +20,7 @@ import (
 	"testing"
 
 	v1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+

Review comment:
       Ditto.

##########
File path: pkg/apisix/plugin.go
##########
@@ -17,7 +17,9 @@ package apisix
 
 import (
 	"context"
+
 	"github.com/apache/apisix-ingress-controller/pkg/log"

Review comment:
       Put local packages at the bottom of the import block.

##########
File path: pkg/apisix/cluster.go
##########
@@ -136,6 +138,9 @@ func newCluster(o *ClusterOptions) (Cluster, error) {
 
 	go c.syncCache()
 
+	ticker := time.NewTicker(o.SyncInterval)

Review comment:
       Also, ticker should be closed explicitly.




-- 
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 #601: feat: implement schema API

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


   It's weird, all unit tests passed on my PC but failed in CI.


-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cache/cache.go
##########
@@ -35,6 +35,8 @@ type Cache interface {
 	InsertGlobalRule(*v1.GlobalRule) error
 	// InsertConsumer adds or updates consumer to cache.
 	InsertConsumer(*v1.Consumer) error
+	// InsertSchema adds or updates schema to cache.
+	InsertSchema(*v1.Schema) error

Review comment:
       Better to use `InsertPluginSchema`.

##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       We may use the unified term, This so-called `Plugin` client actually only returns its schema. We may just use the term `PluginSchema`.




-- 
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 #601: feat: implement schema API

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


   > It's weird, all unit tests passed on my PC but failed in CI.
   
   UT passed.


-- 
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 #601: feat: implement plugin schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9e502a8) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.48%`.
   > The diff coverage is `51.53%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   34.88%   +0.48%     
   ==========================================
     Files          55       57       +2     
     Lines        5468     5598     +130     
   ==========================================
   + Hits         1881     1953      +72     
   - Misses       3362     3404      +42     
   - Partials      225      241      +16     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601/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==) | `44.44% <28.57%> (-1.99%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.71% <33.33%> (+2.38%)` | :arrow_up: |
   | [pkg/apisix/schema.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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=) | `58.13% <58.13%> (ø)` | |
   | [pkg/apisix/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `75.00% <76.47%> (+0.15%)` | :arrow_up: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `78.57% <78.57%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/601?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 [7291212...9e502a8](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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] fgksgf commented on a change in pull request #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I found `/apisix/admin/schema/plugins/<plugin_name>` and `/apisix/admin/plugins/<plugin_name>` return the same result.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/plugin.go
##########
@@ -17,7 +17,9 @@ package apisix
 
 import (
 	"context"
+
 	"github.com/apache/apisix-ingress-controller/pkg/log"

Review comment:
       @fgksgf  If use goland, you can integrate `goimports-reviser`. It works well for me.




-- 
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 #601: feat: implement plugin schema API

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


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 [#601](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (93fe625) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/7291212964a7f3505fb1bb624fb79df0c9eb0678?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7291212) will **increase** coverage by `0.18%`.
   > The diff coverage is `41.55%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/601?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     #601      +/-   ##
   ==========================================
   + Coverage   34.40%   34.58%   +0.18%     
   ==========================================
     Files          55       56       +1     
     Lines        5468     5545      +77     
   ==========================================
   + Hits         1881     1918      +37     
   - Misses       3362     3393      +31     
   - Partials      225      234       +9     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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/cache/memdb.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jYWNoZS9tZW1kYi5nbw==) | `70.93% <0.00%> (-3.92%)` | :arrow_down: |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `27.21% <31.57%> (+1.89%)` | :arrow_up: |
   | [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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==) | `45.83% <37.50%> (-0.60%)` | :arrow_down: |
   | [pkg/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601/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-cGtnL2FwaXNpeC9wbHVnaW4uZ28=) | `56.09% <56.09%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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/601?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 [7291212...93fe625](https://codecov.io/gh/apache/apisix-ingress-controller/pull/601?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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cache/cache.go
##########
@@ -35,6 +35,8 @@ type Cache interface {
 	InsertGlobalRule(*v1.GlobalRule) error
 	// InsertConsumer adds or updates consumer to cache.
 	InsertConsumer(*v1.Consumer) error
+	// InsertSchema adds or updates schema to cache.
+	InsertSchema(*v1.Schema) error

Review comment:
       Better to use `InsertPluginSchema`.

##########
File path: pkg/apisix/apisix.go
##########
@@ -54,6 +54,8 @@ type Cluster interface {
 	Consumer() Consumer
 	// HealthCheck checks apisix cluster health in realtime.
 	HealthCheck(context.Context) error
+	// Plugin returns a Plugin interface that can operate Plugin resources.
+	Plugin() Plugin

Review comment:
       We may use the unified term, This so-called `Plugin` client actually only returns its schema. We may just use the term `PluginSchema`.




-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I found `/apisix/admin/schema/plugins/<plugin_name>` and `/apisix/admin/plugins/<plugin_name>` return the same result.

##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       I did it but nothing updates.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       Just do it like `syncCache`.
   
   PS: I know the design of `newCluster` is not so elegant, we may add a context for it, but I'd like to optimize this in another PR in the future.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -301,6 +314,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(ctx context.Context, interval time.Duration) {
+	ticker := time.NewTicker(interval)
+	defer ticker.Stop()
+
+	for {
+		if err := c.syncSchemaOnce(); err != nil {
+			log.Warnf("failed to sync schema: %s", err)
+		}
+
+		select {
+		case <-ticker.C:
+			continue
+		case <-ctx.Done():
+			break
+		}
+	}
+}
+
+// syncSchemaOnce syncs schema from APISIX once.
+// It firstly deletes all the schema in the cache,
+// then queries and inserts to the cache.
+func (c *cluster) syncSchemaOnce() error {

Review comment:
       context should be propagated here.




-- 
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 #601: feat: implement plugin schema API

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



##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -463,3 +463,23 @@ func ComposeConsumerName(namespace, name string) string {
 
 	return buf.String()
 }
+
+// Schema represents the schema of APISIX objects.
+type Schema struct {

Review comment:
       If you changed the types.go, Please use the `make codegen` to genrate code.
   `

##########
File path: pkg/apisix/cluster.go
##########
@@ -550,3 +557,27 @@ func readBody(r io.ReadCloser, url string) string {
 	}
 	return string(data)
 }
+
+// getSchema returns the schema of APISIX object.
+func (c *cluster) getSchema(ctx context.Context, url string) (string, error) {
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Review comment:
       I am not sure if this url is right. Because I can not see the prefix contains `/schema/plugins/xxx`.
   For example, if we want to get the schema of plugin `kafka-logger`. We can use this `http://127.0.0.1:9080/apisix/admin/schema/plugins/kafka-logger`.




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/cluster.go
##########
@@ -315,52 +317,74 @@ func (c *cluster) HasSynced(ctx context.Context) error {
 	}
 }
 
-// syncSchema syncs schema from APISIX.
+// syncSchema syncs schema from APISIX regularly according to the interval.
+func (c *cluster) syncSchema(interval time.Duration) {
+	sigCh := make(chan os.Signal, 1)
+	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

Review comment:
       cc @tokers
   I think syncing the schema is a normal task to prevent the schema from changing after the APISIX upgrade, which requires a regular task to run in the background all the time. So this is not the same as `syncCache`.
   
   Do you have any better way to update the schema, if APISIX DP upgrade?




-- 
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 #601: feat: implement schema API

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



##########
File path: pkg/apisix/schema.go
##########
@@ -0,0 +1,91 @@
+// 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 apisix
+
+import (
+	"context"
+
+	"github.com/apache/apisix-ingress-controller/pkg/apisix/cache"

Review comment:
       ok, this should be checked in `make lint`, I will update the config of golangci




-- 
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