diff options
author | 2018-10-09 21:56:09 +0100 | |
---|---|---|
committer | 2018-10-09 21:56:09 +0100 | |
commit | 830e97f8008ed83abb6b293a12a87f3fce34e423 (patch) | |
tree | d1a020aa3e7b232a52018479ab7972d350bd74e7 /plugin/kubernetes/xfr_test.go | |
parent | 298b860a97481630ec65698ab0465675bf58b43a (diff) | |
download | coredns-830e97f8008ed83abb6b293a12a87f3fce34e423.tar.gz coredns-830e97f8008ed83abb6b293a12a87f3fce34e423.tar.zst coredns-830e97f8008ed83abb6b293a12a87f3fce34e423.zip |
plugin/kubernetes: allow trimming down of cached items. (#2128)
* Convert to runtime.Object to smaller structs
This adds conversion for all the objects we want to keep in the cache.
It keeps the minimum for CoreDNS to function and throws away the rest.
The conversion:
api.Endpoints -> object.Endpoints
api.Pod -> object.Pod
api.Serivce -> object.Service
We needed to copy some client-go stuff to insert a conversion function
into NewIndexInformers.
Some unrelated cleanups in the watch functionality as that needed to be
touched because of the above translation of objects.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Reduce test line-count
Signed-off-by: Miek Gieben <miek@miek.nl>
* ....and fix test
Signed-off-by: Miek Gieben <miek@miek.nl>
* Drop use of append
Signed-off-by: Miek Gieben <miek@miek.nl>
* cosmetic changes
Signed-off-by: Miek Gieben <miek@miek.nl>
* that was a typo
Signed-off-by: Miek Gieben <miek@miek.nl>
* re-introduce append here
We can't really use len() here because we don't know the number before
hand.
Signed-off-by: Miek Gieben <miek@miek.nl>
* comment in better place
Signed-off-by: Miek Gieben <miek@miek.nl>
* Make the timestamp a bool; thats where it is used for
Signed-off-by: Miek Gieben <miek@miek.nl>
* Set incoming object to nil
Explicataliy discard the converted object; we did a deep copy it's
not needed anymore.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Per Chris's comment
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/kubernetes/xfr_test.go')
-rw-r--r-- | plugin/kubernetes/xfr_test.go | 84 |
1 files changed, 39 insertions, 45 deletions
diff --git a/plugin/kubernetes/xfr_test.go b/plugin/kubernetes/xfr_test.go index 61bacf66e..0117ebf06 100644 --- a/plugin/kubernetes/xfr_test.go +++ b/plugin/kubernetes/xfr_test.go @@ -5,10 +5,9 @@ import ( "strings" "testing" + "github.com/coredns/coredns/plugin/kubernetes/object" "github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/test" - api "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/miekg/dns" ) @@ -89,12 +88,11 @@ func TestKubernetesXFR(t *testing.T) { diff = difference(gotRRs, testRRs) if len(diff) != 0 { - t.Errorf("Found %d records we're missing tham test cases, should be 0:", len(diff)) + t.Errorf("Found %d records we're missing, should be 0:", len(diff)) for _, rec := range diff { t.Errorf("%+v", rec) } } - } // difference shows what we're missing when comparing two RR slices @@ -114,72 +112,68 @@ func difference(testRRs []dns.RR, gotRRs []dns.RR) []dns.RR { } func TestEndpointsEquivalent(t *testing.T) { - epA := api.Endpoints{ - ObjectMeta: meta.ObjectMeta{ResourceVersion: "1230"}, - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - NotReadyAddresses: []api.EndpointAddress{{IP: "1.2.3.5", Hostname: "foobar"}}, + epA := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, }}, } - epB := api.Endpoints{ - ObjectMeta: meta.ObjectMeta{ResourceVersion: "1234"}, - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - NotReadyAddresses: []api.EndpointAddress{{IP: "1.1.1.1", Hostname: "foobar"}}, + epB := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, }}, } - epC := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, + epC := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, }}, } - epD := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, + epD := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, }, { - Addresses: []api.EndpointAddress{{IP: "1.2.2.2", Hostname: "foofoo"}}, + Addresses: []object.EndpointAddress{{IP: "1.2.2.2", Hostname: "foofoo"}}, }}, } - epE := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}, {IP: "1.1.1.1"}}, + epE := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}, {IP: "1.1.1.1"}}, }}, } - epF := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foofoo"}}, + epF := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foofoo"}}, }}, } - epG := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []api.EndpointPort{{Name: "http", Port: 80, Protocol: "TCP"}}, + epG := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, + Ports: []object.EndpointPort{{Name: "http", Port: 80, Protocol: "TCP"}}, }}, } - epH := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []api.EndpointPort{{Name: "newportname", Port: 80, Protocol: "TCP"}}, + epH := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, + Ports: []object.EndpointPort{{Name: "newportname", Port: 80, Protocol: "TCP"}}, }}, } - epI := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []api.EndpointPort{{Name: "http", Port: 8080, Protocol: "TCP"}}, + epI := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, + Ports: []object.EndpointPort{{Name: "http", Port: 8080, Protocol: "TCP"}}, }}, } - epJ := api.Endpoints{ - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []api.EndpointPort{{Name: "http", Port: 80, Protocol: "UDP"}}, + epJ := object.Endpoints{ + Subsets: []object.EndpointSubset{{ + Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, + Ports: []object.EndpointPort{{Name: "http", Port: 80, Protocol: "UDP"}}, }}, } tests := []struct { equiv bool - a *api.Endpoints - b *api.Endpoints + a *object.Endpoints + b *object.Endpoints }{ {true, &epA, &epB}, {false, &epA, &epC}, |