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

[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #666: Add the apisix-ingress-controller plugin for kubernetes.

tokers commented on a change in pull request #666:
URL: https://github.com/apache/apisix-ingress-controller/pull/666#discussion_r703127659



##########
File path: cmd/plugin/README.md
##########
@@ -0,0 +1,23 @@
+# apisix-ingress-controller plugin
+
+The apisix-ingress-controoler plugin can quikly show the apisix routes and upstreams in kubernetes cluster.
+
+# Quikly start 
+
+```shell
+git clone http://github.com/apache/apisix-ingress-controller 
+cd cmd/plugin
+sh install-plugin.sh
+```
+
+```shell 
+# Show your routes in kubernetes.
+kubectl apisix-ingress-controller routes -n <APISIX_INGRESS_NS>

Review comment:
       IMHO `apisix-ingress-controller` is too long, maybe `ingress-apisix` is more concise.

##########
File path: cmd/plugin/commands/routes/routes.go
##########
@@ -0,0 +1,129 @@
+// 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 routes
+
+import (
+	"strings"
+
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/common"
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/kubectl"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	jsoniter "github.com/json-iterator/go"
+	"github.com/spf13/cobra"
+	"k8s.io/cli-runtime/pkg/genericclioptions"
+)
+

Review comment:
       Add some comments for exportable functions.

##########
File path: cmd/plugin/README.md
##########
@@ -0,0 +1,23 @@
+# apisix-ingress-controller plugin
+
+The apisix-ingress-controoler plugin can quikly show the apisix routes and upstreams in kubernetes cluster.
+
+# Quikly start 
+
+```shell
+git clone http://github.com/apache/apisix-ingress-controller 
+cd cmd/plugin
+sh install-plugin.sh

Review comment:
       Why not assign the executable permission?

##########
File path: cmd/plugin/commands/routes/routes.go
##########
@@ -0,0 +1,129 @@
+// 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 routes
+
+import (
+	"strings"
+
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/common"
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/kubectl"
+	"github.com/apache/apisix-ingress-controller/pkg/log"

Review comment:
       Please sort the imports, we should put the 3rd parties in the middle, and put our own packages at the bottom.

##########
File path: cmd/plugin/commands/routes/routes.go
##########
@@ -0,0 +1,129 @@
+// 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 routes
+
+import (
+	"strings"
+
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/common"
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/kubectl"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	jsoniter "github.com/json-iterator/go"
+	"github.com/spf13/cobra"
+	"k8s.io/cli-runtime/pkg/genericclioptions"
+)
+
+func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
+	var routeId string
+	cmd := &cobra.Command{
+		Use:   "routes",
+		Short: "Show the apisix routes",
+		Run: func(cmd *cobra.Command, args []string) {
+			getRoutes(flags, routeId)
+			return
+		},
+	}
+	cmd.Flags().StringVar(&routeId, "route-id", "", "apisix route id")
+	return cmd
+}
+
+// getRoutes get apisix route informations.
+func getRoutes(flags *genericclioptions.ConfigFlags, routeId string) {
+	pconf := common.NewPluginConfig(flags)
+	log.Infof("namespaces: %v \n", pconf.NameSpace)
+	pconf.GetConfigMapsData()
+
+	svcName, _ := pconf.GetApisixSvcName()
+	pid := kubectl.OpenPortForward(pconf.Ctx, pconf.NameSpace, svcName)
+	header := []string{
+		"ID",
+		"Name",
+		"Host",
+		"URI",
+		"Status",
+		"UpstreamId",
+		"CreateTime",
+		"UpdateTime",
+	}
+
+	for {
+		if common.CheckPort() {
+			log.Info("the k8s port-forward is ready")
+			break
+		}
+		log.Error("the k8s port-forward is not ready")
+	}
+	var reqApisix common.RequestConf
+	reqApisix.AdminKey = pconf.Cfg.APISIX.AdminKey
+	reqApisix.URL = "http://127.0.0.1:9180/apisix/admin"

Review comment:
       Cannot assume the APISIX address is just `127.0.0.1:9180`.

##########
File path: cmd/plugin/commands/routes/routes.go
##########
@@ -0,0 +1,129 @@
+// 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 routes
+
+import (
+	"strings"
+
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/common"
+	"github.com/apache/apisix-ingress-controller/cmd/plugin/kubectl"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	jsoniter "github.com/json-iterator/go"
+	"github.com/spf13/cobra"
+	"k8s.io/cli-runtime/pkg/genericclioptions"
+)
+
+func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
+	var routeId string
+	cmd := &cobra.Command{
+		Use:   "routes",
+		Short: "Show the apisix routes",
+		Run: func(cmd *cobra.Command, args []string) {
+			getRoutes(flags, routeId)
+			return
+		},
+	}
+	cmd.Flags().StringVar(&routeId, "route-id", "", "apisix route id")
+	return cmd
+}
+
+// getRoutes get apisix route informations.
+func getRoutes(flags *genericclioptions.ConfigFlags, routeId string) {
+	pconf := common.NewPluginConfig(flags)
+	log.Infof("namespaces: %v \n", pconf.NameSpace)
+	pconf.GetConfigMapsData()
+
+	svcName, _ := pconf.GetApisixSvcName()
+	pid := kubectl.OpenPortForward(pconf.Ctx, pconf.NameSpace, svcName)
+	header := []string{
+		"ID",
+		"Name",
+		"Host",
+		"URI",
+		"Status",
+		"UpstreamId",
+		"CreateTime",
+		"UpdateTime",
+	}
+
+	for {
+		if common.CheckPort() {
+			log.Info("the k8s port-forward is ready")
+			break
+		}
+		log.Error("the k8s port-forward is not ready")
+	}
+	var reqApisix common.RequestConf
+	reqApisix.AdminKey = pconf.Cfg.APISIX.AdminKey
+	reqApisix.URL = "http://127.0.0.1:9180/apisix/admin"

Review comment:
       Also, we have a full-featured APISIX Go SDK, we don't have to create another one here. See `pkg/apisix` for more details.




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