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/05/27 13:10:14 UTC

[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #497: feat: subset translation

gxthrj commented on a change in pull request #497:
URL: https://github.com/apache/apisix-ingress-controller/pull/497#discussion_r640606110



##########
File path: pkg/ingress/pod.go
##########
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package ingress
+
+import (
+	"context"
+
+	"go.uber.org/zap"
+	corev1 "k8s.io/api/core/v1"
+	"k8s.io/client-go/tools/cache"
+
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+type podController struct {
+	controller *Controller
+}
+
+func (c *Controller) newPodController() *podController {
+	ctl := &podController{
+		controller: c,
+	}
+	ctl.controller.podInformer.AddEventHandler(
+		cache.ResourceEventHandlerFuncs{
+			AddFunc:    ctl.onAdd,
+			DeleteFunc: ctl.onDelete,

Review comment:
       There is  no updateFunc?

##########
File path: pkg/ingress/pod.go
##########
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package ingress
+
+import (
+	"context"
+
+	"go.uber.org/zap"
+	corev1 "k8s.io/api/core/v1"
+	"k8s.io/client-go/tools/cache"
+
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+)
+
+type podController struct {
+	controller *Controller
+}
+
+func (c *Controller) newPodController() *podController {
+	ctl := &podController{
+		controller: c,
+	}
+	ctl.controller.podInformer.AddEventHandler(
+		cache.ResourceEventHandlerFuncs{
+			AddFunc:    ctl.onAdd,
+			DeleteFunc: ctl.onDelete,
+		},
+	)
+	return ctl
+}
+
+func (c *podController) run(ctx context.Context) {
+	log.Info("pod controller started")
+	defer log.Info("pod controller exited")
+
+	if ok := cache.WaitForCacheSync(ctx.Done(), c.controller.podInformer.HasSynced); !ok {
+		log.Error("informers sync failed")
+		return
+	}
+
+	<-ctx.Done()
+}
+
+func (c *podController) onAdd(obj interface{}) {
+	key, err := cache.MetaNamespaceKeyFunc(obj)
+	if err != nil {
+		log.Errorf("found pod with bad namespace/name: %s, ignore it", err)
+		return
+	}
+	if !c.controller.namespaceWatching(key) {
+		return
+	}
+	log.Debugw("pod add event arrived",
+		zap.Any("object", obj),
+	)
+	pod := obj.(*corev1.Pod)
+	if err := c.controller.podCache.Add(pod); err != nil {

Review comment:
       Need to check the status of pod, on some status like pending, the pod IP is not exist.




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