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
kubernetes [ZONES...] {
resyncperiod DURATION
endpoint URL
tls CERT KEY CACERT
kubeconfig KUBECONFIG CONTEXT
@ -65,9 +64,7 @@ kubernetes [ZONES...] {
.fi
.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
\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.

View file

@ -31,7 +31,6 @@ all the zones the plugin should be authoritative for.
```
kubernetes [ZONES...] {
resyncperiod DURATION
endpoint URL
tls CERT KEY CACERT
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.
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.

View file

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

View file

@ -1,14 +1,12 @@
package object
import (
"time"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
)
// 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)
fifo := cache.NewDeltaFIFO(cache.MetaNamespaceKeyFunc, clientState)
@ -17,7 +15,7 @@ func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPe
Queue: fifo,
ListerWatcher: lw,
ObjectType: objType,
FullResyncPeriod: resyncPeriod,
FullResyncPeriod: defaultResyncPeriod,
RetryOnError: false,
Process: func(obj interface{}) error {
for _, d := range obj.(cache.Deltas) {
@ -49,3 +47,5 @@ func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPe
}
return clientState, cache.New(cfg)
}
const defaultResyncPeriod = 0

View file

@ -131,7 +131,6 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
opts := dnsControlOpts{
initEndpointsCache: true,
ignoreEmptyService: false,
resyncPeriod: defaultResyncPeriod,
}
k8s.opts = opts
@ -214,16 +213,7 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
}
return nil, c.ArgErr()
case "resyncperiod":
args := c.RemainingArgs()
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()
continue
case "labels":
args := c.RemainingArgs()
if len(args) > 0 {
@ -322,5 +312,3 @@ func searchFromResolvConf() []string {
plugin.Zones(rc.Search).Normalize()
return rc.Search
}
const defaultResyncPeriod = 0

View file

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