From 59bffafb2d254fbbe8da7d13e095e79cf71a9cc3 Mon Sep 17 00:00:00 2001 From: kaezon Date: Tue, 11 Jan 2022 19:03:06 +0000 Subject: [PATCH] typo --- kubernetes.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/kubernetes.go b/kubernetes.go index 26ab403..5d01b26 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -19,11 +19,11 @@ import ( ) const ( - defaultResyncPeriod = 0 - ingressHostnameIndex = "ingressHostname" - serviceHostnameIndex = "serviceHostname" - virtualServiceHostnameIndex = "virtualServiceHostname" - hostnameAnnotationKey = "coredns.io/hostname" + defaultResyncPeriod = 0 + ingressHostnameIndex = "ingressHostname" + serviceHostnameIndex = "serviceHostname" + virtualServerHostnameIndex = "virtualServerHostname" + hostnameAnnotationKey = "coredns.io/hostname" ) // KubeController stores the current runtime configuration and cache @@ -71,18 +71,18 @@ func newKubeController(ctx context.Context, c *kubernetes.Clientset) *KubeContro ctrl.controllers = append(ctrl.controllers, serviceController) } - if resource := lookupResource("VirtualService"); resource != nil { - virtualServiceController := cache.NewSharedIndexInformer( + if resource := lookupResource("VirtualServer"); resource != nil { + virtualServerController := cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: virtualServiceLister(ctx, nginxV1Client, core.NamespaceAll), - WatchFunc: virtualServiceWatcher(ctx, nginxV1Client, core.NamespaceAll), + ListFunc: virtualServerLister(ctx, nginxV1Client, core.NamespaceAll), + WatchFunc: virtualServerWatcher(ctx, nginxV1Client, core.NamespaceAll), }, &nginx_v1.VirtualServer{}, defaultResyncPeriod, - cache.Indexers{virtualServiceHostnameIndex: virtualServiceHostnameIndexFunc}, + cache.Indexers{virtualServerHostnameIndex: virtualServerHostnameIndexFunc}, ) - resource.lookup = lookupVirtualServiceIndex(virtualServiceController) - ctrl.controllers = append(ctrl.controllers, virtualServiceController) + resource.lookup = lookupVirtualServerIndex(virtualServerController) + ctrl.controllers = append(ctrl.controllers, virtualServerController) } return ctrl @@ -160,7 +160,7 @@ func serviceLister(ctx context.Context, c kubernetes.Interface, ns string) func( } } -func virtualServiceLister(ctx context.Context, c k8s_nginx.Interface, ns string) func(meta.ListOptions) (runtime.Object, error) { +func virtualServerLister(ctx context.Context, c k8s_nginx.Interface, ns string) func(meta.ListOptions) (runtime.Object, error) { return func(opts meta.ListOptions) (runtime.Object, error) { return c.K8sV1().VirtualServers(ns).List(ctx, opts) } @@ -178,7 +178,7 @@ func serviceWatcher(ctx context.Context, c kubernetes.Interface, ns string) func } } -func virtualServiceWatcher(ctx context.Context, c k8s_nginx.Interface, ns string) func(meta.ListOptions) (watch.Interface, error) { +func virtualServerWatcher(ctx context.Context, c k8s_nginx.Interface, ns string) func(meta.ListOptions) (watch.Interface, error) { return func(opts meta.ListOptions) (watch.Interface, error) { return c.K8sV1().VirtualServers(ns).Watch(ctx, opts) } @@ -218,12 +218,14 @@ func serviceHostnameIndexFunc(obj interface{}) ([]string, error) { return []string{hostname}, nil } -func virtualServiceHostnameIndexFunc(obj interface{}) ([]string, error) { +func virtualServerHostnameIndexFunc(obj interface{}) ([]string, error) { virtualServer, ok := obj.(*nginx_v1.VirtualServer) if !ok { return []string{}, nil } + log.Debugf("Adding index %s for VirtualServer %s", virtualServer.Spec.Host, virtualServer.Name) + return []string{virtualServer.Spec.Host}, nil } @@ -244,14 +246,14 @@ func lookupServiceIndex(ctrl cache.SharedIndexInformer) func([]string) []net.IP } } -func lookupVirtualServiceIndex(ctrl cache.SharedIndexInformer) func([]string) []net.IP { +func lookupVirtualServerIndex(ctrl cache.SharedIndexInformer) func([]string) []net.IP { return func(indexKeys []string) (result []net.IP) { var objs []interface{} for _, key := range indexKeys { - obj, _ := ctrl.GetIndexer().ByIndex(virtualServiceHostnameIndex, strings.ToLower(key)) + obj, _ := ctrl.GetIndexer().ByIndex(virtualServerHostnameIndex, strings.ToLower(key)) objs = append(objs, obj...) } - log.Debugf("Found %d matching VirtualService objects", len(objs)) + log.Debugf("Found %d matching VirtualServer objects", len(objs)) for _, obj := range objs { virtualServer, _ := obj.(*nginx_v1.VirtualServer)