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/26 07:45:48 UTC

[GitHub] [apisix-ingress-controller] fhuzero commented on a change in pull request #606: feat: add support for Knative

fhuzero commented on a change in pull request #606:
URL: https://github.com/apache/apisix-ingress-controller/pull/606#discussion_r676368239



##########
File path: pkg/ingress/knative_ingress.go
##########
@@ -0,0 +1,299 @@
+// 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"
+	"fmt"
+	"time"
+
+	"go.uber.org/zap"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/client-go/tools/cache"
+	"k8s.io/client-go/util/workqueue"
+
+	"github.com/apache/apisix-ingress-controller/pkg/kube"
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	"github.com/apache/apisix-ingress-controller/pkg/types"
+)
+
+//const knativeIngressClassKey = "networking.knative.dev/ingress.class"
+
+type knativeIngressController struct {
+	controller *Controller
+	workqueue  workqueue.RateLimitingInterface
+	workers    int
+}
+
+func (c *Controller) newKnativeIngressController() *knativeIngressController {
+	ctl := &knativeIngressController{
+		controller: c,
+		workqueue:  workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "KnativeIngress"),
+		workers:    1,
+	}
+
+	c.knativeIngressInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
+		AddFunc:    ctl.onAdd,
+		UpdateFunc: ctl.onUpdate,
+		DeleteFunc: ctl.OnDelete,
+	})
+	return ctl
+}
+
+func (c *knativeIngressController) run(ctx context.Context) {
+	log.Info("knative ingress controller started")
+	defer log.Infof("knative ingress controller exited")
+	defer c.workqueue.ShutDown()
+
+	if !cache.WaitForCacheSync(ctx.Done(), c.controller.knativeIngressInformer.HasSynced) {
+		log.Errorf("cache sync failed")
+		return
+	}
+	for i := 0; i < c.workers; i++ {
+		go c.runWorker(ctx)
+	}
+	<-ctx.Done()
+}
+
+func (c *knativeIngressController) runWorker(ctx context.Context) {
+	for {
+		obj, quit := c.workqueue.Get()
+		if quit {
+			return
+		}
+		err := c.sync(ctx, obj.(*types.Event))
+		c.workqueue.Done(obj)
+		c.handleSyncErr(obj, err)
+	}
+}
+
+func (c *knativeIngressController) sync(ctx context.Context, ev *types.Event) error {
+	ingEv := ev.Object.(kube.KnativeIngressEvent)
+	namespace, name, err := cache.SplitMetaNamespaceKey(ingEv.Key)
+	if err != nil {
+		log.Errorf("found knative ingress resource with invalid meta namespace key %s: %s", ingEv.Key, err)
+		return err
+	}
+
+	var ing kube.KnativeIngress
+	switch ingEv.GroupVersion {

Review comment:
       I followed version judgement in pkg/ingress/ingress.go [here](https://github.com/apache/apisix-ingress-controller/blob/master/pkg/ingress/ingress.go#L93), which judges ingress version in `sync`, instead of `onAdd`, `onUpdate`, and `onDelete`. Could you please tell me differences between them?




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