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 2020/12/17 01:10:28 UTC

[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #95: feat: support TLS

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



##########
File path: cmd/ingress/ingress.go
##########
@@ -102,6 +102,8 @@ func NewIngressCommand() *cobra.Command {
 			c.ApisixUpstream()
 			// ApisixService
 			c.ApisixService()
+			// ApisixTls
+			c.ApisixTls()

Review comment:
       What about `c.ApisixTLS`

##########
File path: pkg/ingress/apisix/tls.go
##########
@@ -0,0 +1,68 @@
+// 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 (
+	ingressConf "github.com/api7/ingress-controller/pkg/kube"
+	ingress "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
+	apisix "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
+	"k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+const (
+	ApisixTls = "ApisixTls"
+)
+
+type ApisixTlsCRD ingress.ApisixTls
+
+// Convert convert to  apisix.Service from ingress.ApisixService CRD

Review comment:
       The comment is not right.
   
   Should be:
   
   ```
   // Convert convert to  apisix.Ssl from ingress.ApisixTls CRD
   ```

##########
File path: samples/deploy/crd/v1beta1/ApisixTls.yaml
##########
@@ -0,0 +1,34 @@
+#

Review comment:
       Have you tried to install this by kustomize?

##########
File path: samples/deploy/rbac/apisix_view_clusterrole.yaml
##########
@@ -137,6 +137,7 @@ rules:
   - apisixroutes
   - apisixupstreams
   - apisixservices
+  - apisixtlses

Review comment:
       ditto.

##########
File path: pkg/ingress/apisix/tls.go
##########
@@ -0,0 +1,68 @@
+// 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 (
+	ingressConf "github.com/api7/ingress-controller/pkg/kube"

Review comment:
       packages in self module should be put at the end of import block.

##########
File path: pkg/ingress/controller/apisix_tls.go
##########
@@ -0,0 +1,186 @@
+// 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 controller
+
+import (
+	"fmt"
+	"github.com/api7/ingress-controller/pkg/ingress/apisix"
+	"github.com/api7/ingress-controller/pkg/log"
+	"github.com/golang/glog"
+	apisixV1 "github.com/gxthrj/apisix-ingress-types/pkg/apis/config/v1"
+	clientSet "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
+	apisixScheme "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned/scheme"
+	informers "github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions/config/v1"
+	"github.com/gxthrj/apisix-ingress-types/pkg/client/listers/config/v1"
+	"github.com/gxthrj/seven/state"
+	"k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/util/runtime"
+	"k8s.io/apimachinery/pkg/util/wait"
+	"k8s.io/client-go/kubernetes"
+	"k8s.io/client-go/kubernetes/scheme"
+	"k8s.io/client-go/tools/cache"
+	"k8s.io/client-go/util/workqueue"
+	"time"
+)
+
+type ApisixTlsController struct {
+	kubeclientset   kubernetes.Interface
+	apisixClientset clientSet.Interface
+	apisixTlsList   v1.ApisixTlsLister
+	apisixTlsSynced cache.InformerSynced
+	workqueue       workqueue.RateLimitingInterface
+}
+
+type TlsQueueObj struct {
+	Key    string              `json:"key"`
+	OldObj *apisixV1.ApisixTls `json:"old_obj"`
+	Ope    string              `json:"ope"` // add / update / delete
+}
+
+func BuildApisixTlsController(
+	kubeclientset kubernetes.Interface,
+	apisixTlsClientset clientSet.Interface,
+	apisixTlsInformer informers.ApisixTlsInformer) *ApisixTlsController {
+
+	runtime.Must(apisixScheme.AddToScheme(scheme.Scheme))
+	controller := &ApisixTlsController{
+		kubeclientset:   kubeclientset,
+		apisixClientset: apisixTlsClientset,
+		apisixTlsList:   apisixTlsInformer.Lister(),
+		apisixTlsSynced: apisixTlsInformer.Informer().HasSynced,
+		workqueue:       workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ApisixTlses"),
+	}
+	apisixTlsInformer.Informer().AddEventHandler(
+		cache.ResourceEventHandlerFuncs{
+			AddFunc:    controller.addFunc,
+			UpdateFunc: controller.updateFunc,
+			DeleteFunc: controller.deleteFunc,
+		})
+	return controller
+}
+
+func (c *ApisixTlsController) Run(stop <-chan struct{}) error {
+	if ok := cache.WaitForCacheSync(stop); !ok {
+		glog.Errorf("sync ApisixService cache failed")

Review comment:
       Since we have the `pkg/log`, we should no longer use glog.

##########
File path: pkg/ingress/apisix/tls_test.go
##########
@@ -0,0 +1,114 @@
+// 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 (
+	"encoding/json"
+	"fmt"
+	a6Type "github.com/gxthrj/apisix-types/pkg/apis/apisix/v1"
+	"github.com/stretchr/testify/assert"
+	"gopkg.in/yaml.v2"
+	"k8s.io/api/core/v1"
+	"testing"

Review comment:
       Standard packages should be put at the beginning of import block.

##########
File path: samples/deploy/crd/v1beta1/ApisixTls.yaml
##########
@@ -0,0 +1,34 @@
+#
+# 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.
+#
+
+apiVersion: apiextensions.k8s.io/v1beta1
+kind: CustomResourceDefinition
+metadata:
+  name: apisixtlses.apisix.apache.org

Review comment:
       I am not sure whether the `es` suffix is right. If singular and plural homographs, use `apisixtls.apisix.apache.org`.




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

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