From 27f0cfa8879712070736a91b4b67c1ea0cdd4835 Mon Sep 17 00:00:00 2001 From: cmssczy Date: Wed, 23 Feb 2022 08:44:42 -0500 Subject: [PATCH 1/2] update the-hard-way.md (#875) --- docs/en/latest/practices/the-hard-way.md | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/en/latest/practices/the-hard-way.md b/docs/en/latest/practices/the-hard-way.md index cb007fffc8..ddb538e5b3 100644 --- a/docs/en/latest/practices/the-hard-way.md +++ b/docs/en/latest/practices/the-hard-way.md @@ -127,6 +127,10 @@ spec: volumeMounts: - name: data mountPath: /etcd + # If you don't have a storage provisioner or don't want to use persistence volume, you could use an `emptyDir` as follow. + # volumes: + # - name: data + # emptyDir: {} volumeClaimTemplates: - metadata: name: data @@ -443,11 +447,13 @@ apiVersion: v1 kind: ServiceAccount metadata: name: apisix-ingress-controller + namespace: apisix --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: apisix-clusterrole + namespace: apisix rules: - apiGroups: - "" @@ -589,6 +595,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: apisix-clusterrolebinding + namespace: apisix roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -694,7 +701,7 @@ spec: initContainers: - name: wait-apisix-admin image: busybox:1.28 - command: ['sh', '-c', "until nc -z apisix-service.apisix.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"] + command: ['sh', '-c', "until nc -z apisix-admin.apisix.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"] containers: - name: ingress-controller command: @@ -730,20 +737,21 @@ After the ingress controller status is converted to `Running`, we could create a Here is an example ApisixRoute: ```yaml -apiVersion: apisix.apache.org/v2beta1 +apiVersion: apisix.apache.org/v2beta3 kind: ApisixRoute metadata: name: httpserver-route + namespace: demo spec: http: - - name: httpbin - match: - hosts: - - local.httpbin.org - paths: - - "/*" - backend: - serviceName: httpbin + - name: httpbin + match: + hosts: + - local.httpbin.org + paths: + - /* + backends: + - serviceName: httpbin servicePort: 80 ``` From d30bef56d5502724901c7eae42b319ad1b92c76c Mon Sep 17 00:00:00 2001 From: Sarasa Kisaragi Date: Wed, 23 Feb 2022 22:35:58 +0800 Subject: [PATCH 2/2] fix: endless retry if namespace doesn't exist (#882) --- pkg/ingress/apisix_consumer.go | 6 ++-- pkg/ingress/apisix_pluginconfig.go | 6 ++-- pkg/ingress/apisix_route.go | 6 ++-- pkg/ingress/apisix_tls.go | 6 ++-- pkg/ingress/apisix_upstream.go | 6 ++-- pkg/ingress/compare.go | 8 ++--- pkg/ingress/controller.go | 58 +++++++++++++++--------------- pkg/ingress/endpoint.go | 8 ++--- pkg/ingress/endpointslice.go | 6 ++-- pkg/ingress/gateway.go | 2 +- pkg/ingress/ingress.go | 4 +-- pkg/ingress/namespace.go | 40 +++++++++++++-------- pkg/ingress/pod.go | 6 ++-- pkg/ingress/pod_test.go | 18 +++++----- pkg/ingress/secret.go | 8 ++--- 15 files changed, 100 insertions(+), 88 deletions(-) diff --git a/pkg/ingress/apisix_consumer.go b/pkg/ingress/apisix_consumer.go index ce65cca3e7..e007c3e89e 100644 --- a/pkg/ingress/apisix_consumer.go +++ b/pkg/ingress/apisix_consumer.go @@ -158,7 +158,7 @@ func (c *apisixConsumerController) onAdd(obj interface{}) { log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixConsumer add event arrived", @@ -184,7 +184,7 @@ func (c *apisixConsumerController) onUpdate(oldObj, newObj interface{}) { log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixConsumer update event arrived", @@ -215,7 +215,7 @@ func (c *apisixConsumerController) onDelete(obj interface{}) { log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixConsumer delete event arrived", diff --git a/pkg/ingress/apisix_pluginconfig.go b/pkg/ingress/apisix_pluginconfig.go index 6b79299327..be90735ce4 100644 --- a/pkg/ingress/apisix_pluginconfig.go +++ b/pkg/ingress/apisix_pluginconfig.go @@ -248,7 +248,7 @@ func (c *apisixPluginConfigController) onAdd(obj interface{}) { log.Errorf("found ApisixPluginConfig resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixPluginConfig add event arrived", @@ -277,7 +277,7 @@ func (c *apisixPluginConfigController) onUpdate(oldObj, newObj interface{}) { log.Errorf("found ApisixPluginConfig resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixPluginConfig update event arrived", @@ -310,7 +310,7 @@ func (c *apisixPluginConfigController) onDelete(obj interface{}) { log.Errorf("found ApisixPluginConfig resource with bad meta namesapce key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixPluginConfig delete event arrived", diff --git a/pkg/ingress/apisix_route.go b/pkg/ingress/apisix_route.go index 8d601a4efd..7b6ed53ac5 100644 --- a/pkg/ingress/apisix_route.go +++ b/pkg/ingress/apisix_route.go @@ -337,7 +337,7 @@ func (c *apisixRouteController) onAdd(obj interface{}) { log.Errorf("found ApisixRoute resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixRoute add event arrived", @@ -366,7 +366,7 @@ func (c *apisixRouteController) onUpdate(oldObj, newObj interface{}) { log.Errorf("found ApisixRoute resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixRoute update event arrived", @@ -399,7 +399,7 @@ func (c *apisixRouteController) onDelete(obj interface{}) { log.Errorf("found ApisixRoute resource with bad meta namesapce key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixRoute delete event arrived", diff --git a/pkg/ingress/apisix_tls.go b/pkg/ingress/apisix_tls.go index dfad187367..c2865f8b79 100644 --- a/pkg/ingress/apisix_tls.go +++ b/pkg/ingress/apisix_tls.go @@ -189,7 +189,7 @@ func (c *apisixTlsController) onAdd(obj interface{}) { log.Errorf("found ApisixTls object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixTls add event arrived", @@ -214,7 +214,7 @@ func (c *apisixTlsController) onUpdate(prev, curr interface{}) { log.Errorf("found ApisixTls object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixTls update event arrived", @@ -246,7 +246,7 @@ func (c *apisixTlsController) onDelete(obj interface{}) { log.Errorf("found ApisixTls resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixTls delete event arrived", diff --git a/pkg/ingress/apisix_upstream.go b/pkg/ingress/apisix_upstream.go index 3a1aab2711..835ec648e9 100644 --- a/pkg/ingress/apisix_upstream.go +++ b/pkg/ingress/apisix_upstream.go @@ -221,7 +221,7 @@ func (c *apisixUpstreamController) onAdd(obj interface{}) { log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixUpstream add event arrived", @@ -246,7 +246,7 @@ func (c *apisixUpstreamController) onUpdate(oldObj, newObj interface{}) { log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixUpstream update event arrived", @@ -277,7 +277,7 @@ func (c *apisixUpstreamController) onDelete(obj interface{}) { log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("ApisixUpstream delete event arrived", diff --git a/pkg/ingress/compare.go b/pkg/ingress/compare.go index 9acd7dd05d..05c7521074 100644 --- a/pkg/ingress/compare.go +++ b/pkg/ingress/compare.go @@ -46,8 +46,8 @@ func (c *Controller) CompareResources(ctx context.Context) error { consumerMapA6 = make(map[string]string) pluginConfigMapA6 = make(map[string]string) ) - // watchingNamespace == nil means to monitor all namespaces - if !validation.HasValueInSyncMap(c.watchingNamespace) { + // watchingNamespaces == nil means to monitor all namespaces + if !validation.HasValueInSyncMap(c.watchingNamespaces) { opts := v1.ListOptions{} // list all namespaces nsList, err := c.kubeClient.Client.CoreV1().Namespaces().List(ctx, opts) @@ -59,11 +59,11 @@ func (c *Controller) CompareResources(ctx context.Context) error { for _, v := range nsList.Items { wns.Store(v.Name, struct{}{}) } - c.watchingNamespace = wns + c.watchingNamespaces = wns } } - c.watchingNamespace.Range(func(key, value interface{}) bool { + c.watchingNamespaces.Range(func(key, value interface{}) bool { wg.Add(1) go func(ns string) { defer wg.Done() diff --git a/pkg/ingress/controller.go b/pkg/ingress/controller.go index 0496a78f67..ecb8c007c4 100644 --- a/pkg/ingress/controller.go +++ b/pkg/ingress/controller.go @@ -68,18 +68,18 @@ const ( // Controller is the ingress apisix controller object. type Controller struct { - name string - namespace string - cfg *config.Config - wg sync.WaitGroup - watchingNamespace *sync.Map - watchingLabels types.Labels - apisix apisix.APISIX - podCache types.PodCache - translator translation.Translator - apiServer *api.Server - MetricsCollector metrics.Collector - kubeClient *kube.KubeClient + name string + namespace string + cfg *config.Config + wg sync.WaitGroup + watchingNamespaces *sync.Map + watchingLabels types.Labels + apisix apisix.APISIX + podCache types.PodCache + translator translation.Translator + apiServer *api.Server + MetricsCollector metrics.Collector + kubeClient *kube.KubeClient // recorder event recorder record.EventRecorder // this map enrolls which ApisixTls objects refer to a Kubernetes @@ -181,17 +181,17 @@ func NewController(cfg *config.Config) (*Controller, error) { eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeClient.Client.CoreV1().Events("")}) c := &Controller{ - name: podName, - namespace: podNamespace, - cfg: cfg, - apiServer: apiSrv, - apisix: client, - MetricsCollector: metrics.NewPrometheusCollector(), - kubeClient: kubeClient, - watchingNamespace: watchingNamespace, - watchingLabels: watchingLabels, - secretSSLMap: new(sync.Map), - recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: _component}), + name: podName, + namespace: podNamespace, + cfg: cfg, + apiServer: apiSrv, + apisix: client, + MetricsCollector: metrics.NewPrometheusCollector(), + kubeClient: kubeClient, + watchingNamespaces: watchingNamespace, + watchingLabels: watchingLabels, + secretSSLMap: new(sync.Map), + recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: _component}), podCache: types.NewPodCache(), } @@ -442,8 +442,8 @@ func (c *Controller) run(ctx context.Context) { c.initWhenStartLeading() - // list namesapce and init watchingNamespace - if err := c.initWatchingNamespaceByLabels(ctx); err != nil { + // list namespaces and init watchingNamespaces + if err := c.initWatchingNamespacesByLabels(ctx); err != nil { ctx.Done() return } @@ -552,10 +552,10 @@ func (c *Controller) run(ctx context.Context) { c.wg.Wait() } -// namespaceWatching accepts a resource key, getting the namespace part +// isWatchingNamespace accepts a resource key, getting the namespace part // and checking whether the namespace is being watched. -func (c *Controller) namespaceWatching(key string) (ok bool) { - if !validation.HasValueInSyncMap(c.watchingNamespace) { +func (c *Controller) isWatchingNamespace(key string) (ok bool) { + if !validation.HasValueInSyncMap(c.watchingNamespaces) { ok = true return } @@ -566,7 +566,7 @@ func (c *Controller) namespaceWatching(key string) (ok bool) { log.Warnf("resource %s was ignored since: %s", key, err) return } - _, ok = c.watchingNamespace.Load(ns) + _, ok = c.watchingNamespaces.Load(ns) return } diff --git a/pkg/ingress/endpoint.go b/pkg/ingress/endpoint.go index a85d588bfd..9464d59164 100644 --- a/pkg/ingress/endpoint.go +++ b/pkg/ingress/endpoint.go @@ -106,7 +106,7 @@ func (c *endpointsController) onAdd(obj interface{}) { log.Errorf("found endpoints object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("endpoints add event arrived", @@ -133,7 +133,7 @@ func (c *endpointsController) onUpdate(prev, curr interface{}) { log.Errorf("found endpoints object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("endpoints update event arrived", @@ -160,10 +160,10 @@ func (c *endpointsController) onDelete(obj interface{}) { ep = tombstone.Obj.(*corev1.Endpoints) } - // FIXME Refactor Controller.namespaceWatching to just use + // FIXME Refactor Controller.isWatchingNamespace to just use // namespace after all controllers use the same way to fetch // the object. - if !c.controller.namespaceWatching(ep.Namespace + "/" + ep.Name) { + if !c.controller.isWatchingNamespace(ep.Namespace + "/" + ep.Name) { return } log.Debugw("endpoints delete event arrived", diff --git a/pkg/ingress/endpointslice.go b/pkg/ingress/endpointslice.go index aece7ced0c..5c09998249 100644 --- a/pkg/ingress/endpointslice.go +++ b/pkg/ingress/endpointslice.go @@ -124,7 +124,7 @@ func (c *endpointSliceController) onAdd(obj interface{}) { if err != nil { log.Errorf("found endpointSlice object with bad namespace") } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } ep := obj.(*discoveryv1.EndpointSlice) @@ -165,7 +165,7 @@ func (c *endpointSliceController) onUpdate(prev, curr interface{}) { log.Errorf("found endpointSlice object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } if currEp.Labels[discoveryv1.LabelManagedBy] != _endpointSlicesManagedBy { @@ -209,7 +209,7 @@ func (c *endpointSliceController) onDelete(obj interface{}) { log.Errorf("found endpointSlice object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } if ep.Labels[discoveryv1.LabelManagedBy] != _endpointSlicesManagedBy { diff --git a/pkg/ingress/gateway.go b/pkg/ingress/gateway.go index af92eb4ffa..6f3eefa1c8 100644 --- a/pkg/ingress/gateway.go +++ b/pkg/ingress/gateway.go @@ -139,7 +139,7 @@ func (c *gatewayController) onAdd(obj interface{}) { log.Errorf("found gateway resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("gateway add event arrived", diff --git a/pkg/ingress/ingress.go b/pkg/ingress/ingress.go index c97dc8334b..f3d650fa75 100644 --- a/pkg/ingress/ingress.go +++ b/pkg/ingress/ingress.go @@ -259,7 +259,7 @@ func (c *ingressController) onAdd(obj interface{}) { log.Errorf("found ingress resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } @@ -340,7 +340,7 @@ func (c *ingressController) OnDelete(obj interface{}) { log.Errorf("found ingress resource with bad meta namespace key: %s", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } valid := c.isIngressEffective(ing) diff --git a/pkg/ingress/namespace.go b/pkg/ingress/namespace.go index 31da666054..0307151431 100644 --- a/pkg/ingress/namespace.go +++ b/pkg/ingress/namespace.go @@ -20,6 +20,7 @@ import ( "go.uber.org/zap" corev1 "k8s.io/api/core/v1" + k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" @@ -51,7 +52,7 @@ func (c *Controller) newNamespaceController() *namespaceController { return ctl } -func (c *Controller) initWatchingNamespaceByLabels(ctx context.Context) error { +func (c *Controller) initWatchingNamespacesByLabels(ctx context.Context) error { labelSelector := metav1.LabelSelector{MatchLabels: c.watchingLabels} opts := metav1.ListOptions{ LabelSelector: labels.Set(labelSelector.MatchLabels).String(), @@ -59,22 +60,25 @@ func (c *Controller) initWatchingNamespaceByLabels(ctx context.Context) error { namespaces, err := c.kubeClient.Client.CoreV1().Namespaces().List(ctx, opts) if err != nil { return err - } else { - for _, ns := range namespaces.Items { - c.watchingNamespace.Store(ns.Name, struct{}{}) - } } + var nss []string + + for _, ns := range namespaces.Items { + nss = append(nss, ns.Name) + c.watchingNamespaces.Store(ns.Name, struct{}{}) + } + log.Infow("label selector watching namespaces", zap.Strings("namespaces", nss)) + return nil } func (c *namespaceController) run(ctx context.Context) { - log.Info("namespace controller started") - defer log.Info("namespace controller exited") - if ok := cache.WaitForCacheSync(ctx.Done(), c.controller.namespaceInformer.HasSynced); !ok { - log.Error("informers sync failed") + log.Error("namespace informers sync failed") return } + log.Info("namespace controller started") + defer log.Info("namespace controller exited") for i := 0; i < c.workers; i++ { go c.runWorker(ctx) } @@ -100,17 +104,17 @@ func (c *namespaceController) sync(ctx context.Context, ev *types.Event) error { if err != nil { return err } else { - // if labels of namespace contains the watchingLabels, the namespace should be set to controller.watchingNamespace + // if labels of namespace contains the watchingLabels, the namespace should be set to controller.watchingNamespaces if c.controller.watchingLabels.IsSubsetOf(namespace.Labels) { - c.controller.watchingNamespace.Store(namespace.Name, struct{}{}) + c.controller.watchingNamespaces.Store(namespace.Name, struct{}{}) } } } else { // type == types.EventDelete namespace := ev.Tombstone.(*corev1.Namespace) - if _, ok := c.controller.watchingNamespace.Load(namespace.Name); ok { - c.controller.watchingNamespace.Delete(namespace.Name) + if _, ok := c.controller.watchingNamespaces.Load(namespace.Name); ok { + c.controller.watchingNamespaces.Delete(namespace.Name) } - // do nothing, if the namespace did not in controller.watchingNamespace + // do nothing, if the namespace did not in controller.watchingNamespaces } return nil } @@ -118,6 +122,14 @@ func (c *namespaceController) sync(ctx context.Context, ev *types.Event) error { func (c *namespaceController) handleSyncErr(event *types.Event, err error) { name := event.Object.(string) if err != nil { + if k8serrors.IsNotFound(err) && event.Type != types.EventDelete { + log.Infow("sync namespace but not found, ignore", + zap.String("event_type", event.Type.String()), + zap.String("namespace", event.Object.(string)), + ) + c.workqueue.Forget(event) + return + } log.Warnw("sync namespace info failed, will retry", zap.String("namespace", name), zap.Error(err), diff --git a/pkg/ingress/pod.go b/pkg/ingress/pod.go index be961a8fda..51a5cea3eb 100644 --- a/pkg/ingress/pod.go +++ b/pkg/ingress/pod.go @@ -61,7 +61,7 @@ func (c *podController) onAdd(obj interface{}) { log.Errorf("found pod with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("pod add event arrived", @@ -87,7 +87,7 @@ func (c *podController) onAdd(obj interface{}) { func (c *podController) onUpdate(_, cur interface{}) { pod := cur.(*corev1.Pod) - if !c.controller.namespaceWatching(pod.Namespace + "/" + pod.Name) { + if !c.controller.isWatchingNamespace(pod.Namespace + "/" + pod.Name) { return } log.Debugw("pod update event arrived", @@ -125,7 +125,7 @@ func (c *podController) onDelete(obj interface{}) { pod = tombstone.Obj.(*corev1.Pod) } - if !c.controller.namespaceWatching(pod.Namespace + "/" + pod.Name) { + if !c.controller.isWatchingNamespace(pod.Namespace + "/" + pod.Name) { return } log.Debugw("pod delete event arrived", diff --git a/pkg/ingress/pod_test.go b/pkg/ingress/pod_test.go index 10a2fe06ec..e12248dd82 100644 --- a/pkg/ingress/pod_test.go +++ b/pkg/ingress/pod_test.go @@ -32,9 +32,9 @@ func TestPodOnAdd(t *testing.T) { watchingNamespace.Store("default", struct{}{}) ctl := &podController{ controller: &Controller{ - watchingNamespace: watchingNamespace, - podCache: types.NewPodCache(), - MetricsCollector: metrics.NewPrometheusCollector(), + watchingNamespaces: watchingNamespace, + podCache: types.NewPodCache(), + MetricsCollector: metrics.NewPrometheusCollector(), }, } @@ -74,9 +74,9 @@ func TestPodOnDelete(t *testing.T) { watchingNamespace.Store("default", struct{}{}) ctl := &podController{ controller: &Controller{ - watchingNamespace: watchingNamespace, - podCache: types.NewPodCache(), - MetricsCollector: metrics.NewPrometheusCollector(), + watchingNamespaces: watchingNamespace, + podCache: types.NewPodCache(), + MetricsCollector: metrics.NewPrometheusCollector(), }, } @@ -119,9 +119,9 @@ func TestPodOnUpdate(t *testing.T) { watchingNamespace.Store("default", struct{}{}) ctl := &podController{ controller: &Controller{ - watchingNamespace: watchingNamespace, - podCache: types.NewPodCache(), - MetricsCollector: metrics.NewPrometheusCollector(), + watchingNamespaces: watchingNamespace, + podCache: types.NewPodCache(), + MetricsCollector: metrics.NewPrometheusCollector(), }, } diff --git a/pkg/ingress/secret.go b/pkg/ingress/secret.go index c42719a665..d8e9b23777 100644 --- a/pkg/ingress/secret.go +++ b/pkg/ingress/secret.go @@ -235,7 +235,7 @@ func (c *secretController) onAdd(obj interface{}) { log.Errorf("found secret object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } @@ -262,7 +262,7 @@ func (c *secretController) onUpdate(prev, curr interface{}) { log.Errorf("found secrets object with bad namespace/name: %s, ignore it", err) return } - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("secret update event arrived", @@ -293,10 +293,10 @@ func (c *secretController) onDelete(obj interface{}) { log.Errorf("found secret resource with bad meta namespace key: %s", err) return } - // FIXME Refactor Controller.namespaceWatching to just use + // FIXME Refactor Controller.isWatchingNamespace to just use // namespace after all controllers use the same way to fetch // the object. - if !c.controller.namespaceWatching(key) { + if !c.controller.isWatchingNamespace(key) { return } log.Debugw("secret delete event arrived",