ISSUE-2911 (#2923)

- Remove resyncperiod from Kubernetes plugin
This commit is contained in:
Anshul Sharma 2019-07-04 01:09:12 +05:30 committed by Miek Gieben
parent 2bd77d0823
commit f9fb9db171
6 changed files with 17 additions and 139 deletions

View file

@ -47,7 +47,6 @@ all the zones the plugin should be authoritative for.
.nf .nf
kubernetes [ZONES...] { kubernetes [ZONES...] {
resyncperiod DURATION
endpoint URL endpoint URL
tls CERT KEY CACERT tls CERT KEY CACERT
kubeconfig KUBECONFIG CONTEXT kubeconfig KUBECONFIG CONTEXT
@ -65,9 +64,7 @@ kubernetes [ZONES...] {
.fi .fi
.RE .RE
.IP \(bu 4
\fB\fCresyncperiod\fR specifies the Kubernetes data API \fBDURATION\fP period. By
default resync is disabled (DURATION is zero).
.IP \(bu 4 .IP \(bu 4
\fB\fCendpoint\fR specifies the \fBURL\fP for a remote k8s API endpoint. \fB\fCendpoint\fR specifies the \fBURL\fP for a remote k8s API endpoint.
If omitted, it will connect to k8s in-cluster using the cluster service account. If omitted, it will connect to k8s in-cluster using the cluster service account.

View file

@ -31,7 +31,6 @@ all the zones the plugin should be authoritative for.
``` ```
kubernetes [ZONES...] { kubernetes [ZONES...] {
resyncperiod DURATION
endpoint URL endpoint URL
tls CERT KEY CACERT tls CERT KEY CACERT
kubeconfig KUBECONFIG CONTEXT kubeconfig KUBECONFIG CONTEXT
@ -47,8 +46,7 @@ kubernetes [ZONES...] {
} }
``` ```
* `resyncperiod` specifies the Kubernetes data API **DURATION** period. By
default resync is disabled (DURATION is zero).
* `endpoint` specifies the **URL** for a remote k8s API endpoint. * `endpoint` specifies the **URL** for a remote k8s API endpoint.
If omitted, it will connect to k8s in-cluster using the cluster service account. If omitted, it will connect to k8s in-cluster using the cluster service account.
* `tls` **CERT** **KEY** **CACERT** are the TLS cert, key and the CA cert file names for remote k8s connection. * `tls` **CERT** **KEY** **CACERT** are the TLS cert, key and the CA cert file names for remote k8s connection.

View file

@ -80,7 +80,6 @@ type dnsControl struct {
type dnsControlOpts struct { type dnsControlOpts struct {
initPodCache bool initPodCache bool
initEndpointsCache bool initEndpointsCache bool
resyncPeriod time.Duration
ignoreEmptyService bool ignoreEmptyService bool
// Label handling. // Label handling.
@ -110,7 +109,6 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns
WatchFunc: serviceWatchFunc(dns.client, api.NamespaceAll, dns.selector), WatchFunc: serviceWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
&api.Service{}, &api.Service{},
opts.resyncPeriod,
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{svcNameNamespaceIndex: svcNameNamespaceIndexFunc, svcIPIndex: svcIPIndexFunc}, cache.Indexers{svcNameNamespaceIndex: svcNameNamespaceIndexFunc, svcIPIndex: svcIPIndexFunc},
object.ToService, object.ToService,
@ -123,7 +121,6 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns
WatchFunc: podWatchFunc(dns.client, api.NamespaceAll, dns.selector), WatchFunc: podWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
&api.Pod{}, &api.Pod{},
opts.resyncPeriod,
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{podIPIndex: podIPIndexFunc}, cache.Indexers{podIPIndex: podIPIndexFunc},
object.ToPod, object.ToPod,
@ -137,7 +134,6 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns
WatchFunc: endpointsWatchFunc(dns.client, api.NamespaceAll, dns.selector), WatchFunc: endpointsWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
&api.Endpoints{}, &api.Endpoints{},
opts.resyncPeriod,
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc}, cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc},
object.ToEndpoints) object.ToEndpoints)
@ -149,7 +145,7 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns
WatchFunc: namespaceWatchFunc(dns.client, dns.namespaceSelector), WatchFunc: namespaceWatchFunc(dns.client, dns.namespaceSelector),
}, },
&api.Namespace{}, &api.Namespace{},
opts.resyncPeriod, defaultResyncPeriod,
cache.ResourceEventHandlerFuncs{}) cache.ResourceEventHandlerFuncs{})
return &dns return &dns
@ -516,3 +512,5 @@ func (dns *dnsControl) updateModifed() {
} }
var errObj = errors.New("obj was not of the correct type") var errObj = errors.New("obj was not of the correct type")
const defaultResyncPeriod = 0

View file

@ -1,14 +1,12 @@
package object package object
import ( import (
"time"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
) )
// NewIndexerInformer is a copy of the cache.NewIndexInformer function, but allows Process to have a conversion function (ToFunc). // NewIndexerInformer is a copy of the cache.NewIndexInformer function, but allows Process to have a conversion function (ToFunc).
func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPeriod time.Duration, h cache.ResourceEventHandler, indexers cache.Indexers, convert ToFunc) (cache.Indexer, cache.Controller) { func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, h cache.ResourceEventHandler, indexers cache.Indexers, convert ToFunc) (cache.Indexer, cache.Controller) {
clientState := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, indexers) clientState := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, indexers)
fifo := cache.NewDeltaFIFO(cache.MetaNamespaceKeyFunc, clientState) fifo := cache.NewDeltaFIFO(cache.MetaNamespaceKeyFunc, clientState)
@ -17,7 +15,7 @@ func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPe
Queue: fifo, Queue: fifo,
ListerWatcher: lw, ListerWatcher: lw,
ObjectType: objType, ObjectType: objType,
FullResyncPeriod: resyncPeriod, FullResyncPeriod: defaultResyncPeriod,
RetryOnError: false, RetryOnError: false,
Process: func(obj interface{}) error { Process: func(obj interface{}) error {
for _, d := range obj.(cache.Deltas) { for _, d := range obj.(cache.Deltas) {
@ -49,3 +47,5 @@ func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPe
} }
return clientState, cache.New(cfg) return clientState, cache.New(cfg)
} }
const defaultResyncPeriod = 0

View file

@ -131,7 +131,6 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
opts := dnsControlOpts{ opts := dnsControlOpts{
initEndpointsCache: true, initEndpointsCache: true,
ignoreEmptyService: false, ignoreEmptyService: false,
resyncPeriod: defaultResyncPeriod,
} }
k8s.opts = opts k8s.opts = opts
@ -214,16 +213,7 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
} }
return nil, c.ArgErr() return nil, c.ArgErr()
case "resyncperiod": case "resyncperiod":
args := c.RemainingArgs() continue
if len(args) > 0 {
rp, err := time.ParseDuration(args[0])
if err != nil {
return nil, fmt.Errorf("unable to parse resync duration value: '%v': %v", args[0], err)
}
k8s.opts.resyncPeriod = rp
continue
}
return nil, c.ArgErr()
case "labels": case "labels":
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) > 0 { if len(args) > 0 {
@ -322,5 +312,3 @@ func searchFromResolvConf() []string {
plugin.Zones(rc.Search).Normalize() plugin.Zones(rc.Search).Normalize()
return rc.Search return rc.Search
} }
const defaultResyncPeriod = 0

View file

@ -3,7 +3,6 @@ package kubernetes
import ( import (
"strings" "strings"
"testing" "testing"
"time"
"github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/fall"
@ -13,14 +12,13 @@ import (
func TestKubernetesParse(t *testing.T) { func TestKubernetesParse(t *testing.T) {
tests := []struct { tests := []struct {
input string // Corefile data as string input string // Corefile data as string
shouldErr bool // true if test case is expected to produce an error. shouldErr bool // true if test case is expected to produce an error.
expectedErrContent string // substring from the expected error. Empty for positive cases. expectedErrContent string // substring from the expected error. Empty for positive cases.
expectedZoneCount int // expected count of defined zones. expectedZoneCount int // expected count of defined zones.
expectedNSCount int // expected count of namespaces. expectedNSCount int // expected count of namespaces.
expectedResyncPeriod time.Duration // expected resync period value expectedLabelSelector string // expected label selector value
expectedLabelSelector string // expected label selector value expectedNamespaceLabelSelector string // expected namespace label selector value
expectedNamespaceLabelSelector string // expected namespace label selector value
expectedPodMode string expectedPodMode string
expectedFallthrough fall.F expectedFallthrough fall.F
}{ }{
@ -31,7 +29,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -43,7 +40,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
2, 2,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -56,7 +52,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -70,7 +65,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -84,7 +78,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
1, 1,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -98,35 +91,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
2, 2,
defaultResyncPeriod,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
resyncperiod 30s
}`,
false,
"",
1,
0,
30 * time.Second,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
resyncperiod 15m
}`,
false,
"",
1,
0,
15 * time.Minute,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -140,7 +104,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"environment=prod", "environment=prod",
"", "",
podModeDisabled, podModeDisabled,
@ -154,7 +117,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"application=nginx,environment in (production,qa,staging)", "application=nginx,environment in (production,qa,staging)",
"", "",
podModeDisabled, podModeDisabled,
@ -168,7 +130,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"istio-injection=enabled", "istio-injection=enabled",
podModeDisabled, podModeDisabled,
@ -183,7 +144,6 @@ func TestKubernetesParse(t *testing.T) {
"Error during parsing: namespaces and namespace_labels cannot both be set", "Error during parsing: namespaces and namespace_labels cannot both be set",
-1, -1,
0, 0,
defaultResyncPeriod,
"", "",
"istio-injection=enabled", "istio-injection=enabled",
podModeDisabled, podModeDisabled,
@ -191,7 +151,6 @@ func TestKubernetesParse(t *testing.T) {
}, },
{ {
`kubernetes coredns.local test.local { `kubernetes coredns.local test.local {
resyncperiod 15m
endpoint http://localhost:8080 endpoint http://localhost:8080
namespaces demo test namespaces demo test
labels environment in (production, staging, qa),application=nginx labels environment in (production, staging, qa),application=nginx
@ -201,7 +160,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
2, 2,
2, 2,
15 * time.Minute,
"application=nginx,environment in (production,qa,staging)", "application=nginx,environment in (production,qa,staging)",
"", "",
podModeDisabled, podModeDisabled,
@ -216,7 +174,6 @@ func TestKubernetesParse(t *testing.T) {
"rong argument count or unexpected line ending", "rong argument count or unexpected line ending",
-1, -1,
-1, -1,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -230,49 +187,6 @@ func TestKubernetesParse(t *testing.T) {
"rong argument count or unexpected line ending", "rong argument count or unexpected line ending",
-1, -1,
-1, -1,
defaultResyncPeriod,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
resyncperiod
}`,
true,
"rong argument count or unexpected line ending",
-1,
0,
0 * time.Minute,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
resyncperiod 15
}`,
true,
"unable to parse resync duration value",
-1,
0,
0 * time.Second,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
resyncperiod abc
}`,
true,
"unable to parse resync duration value",
-1,
0,
0 * time.Second,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -286,7 +200,6 @@ func TestKubernetesParse(t *testing.T) {
"rong argument count or unexpected line ending", "rong argument count or unexpected line ending",
-1, -1,
0, 0,
0 * time.Second,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -300,7 +213,6 @@ func TestKubernetesParse(t *testing.T) {
"unable to parse label selector", "unable to parse label selector",
-1, -1,
0, 0,
0 * time.Second,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -315,7 +227,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -330,7 +241,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeInsecure, podModeInsecure,
@ -345,7 +255,6 @@ func TestKubernetesParse(t *testing.T) {
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeVerified, podModeVerified,
@ -360,7 +269,6 @@ func TestKubernetesParse(t *testing.T) {
"rong value for pods", "rong value for pods",
-1, -1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeVerified, podModeVerified,
@ -375,7 +283,6 @@ func TestKubernetesParse(t *testing.T) {
"rong argument count", "rong argument count",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -389,7 +296,6 @@ kubernetes cluster.local`,
"this plugin", "this plugin",
-1, -1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -403,7 +309,6 @@ kubernetes cluster.local`,
"Wrong argument count or unexpected line ending after", "Wrong argument count or unexpected line ending after",
-1, -1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -417,7 +322,6 @@ kubernetes cluster.local`,
"Wrong argument count or unexpected line ending after", "Wrong argument count or unexpected line ending after",
-1, -1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -431,7 +335,6 @@ kubernetes cluster.local`,
"", "",
1, 1,
0, 0,
defaultResyncPeriod,
"", "",
"", "",
podModeDisabled, podModeDisabled,
@ -480,12 +383,6 @@ kubernetes cluster.local`,
t.Errorf("Test %d: Expected kubernetes controller to be initialized with %d namespaces. Instead found %d namespaces: '%v' for input '%s'", i, test.expectedNSCount, foundNSCount, k8sController.Namespaces, test.input) t.Errorf("Test %d: Expected kubernetes controller to be initialized with %d namespaces. Instead found %d namespaces: '%v' for input '%s'", i, test.expectedNSCount, foundNSCount, k8sController.Namespaces, test.input)
} }
// ResyncPeriod
foundResyncPeriod := k8sController.opts.resyncPeriod
if foundResyncPeriod != test.expectedResyncPeriod {
t.Errorf("Test %d: Expected kubernetes controller to be initialized with resync period '%s'. Instead found period '%s' for input '%s'", i, test.expectedResyncPeriod, foundResyncPeriod, test.input)
}
// Labels // Labels
if k8sController.opts.labelSelector != nil { if k8sController.opts.labelSelector != nil {
foundLabelSelectorString := meta.FormatLabelSelector(k8sController.opts.labelSelector) foundLabelSelectorString := meta.FormatLabelSelector(k8sController.opts.labelSelector)