aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/controller_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-10-09 21:56:09 +0100
committerGravatar GitHub <noreply@github.com> 2018-10-09 21:56:09 +0100
commit830e97f8008ed83abb6b293a12a87f3fce34e423 (patch)
treed1a020aa3e7b232a52018479ab7972d350bd74e7 /plugin/kubernetes/controller_test.go
parent298b860a97481630ec65698ab0465675bf58b43a (diff)
downloadcoredns-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/controller_test.go')
-rw-r--r--plugin/kubernetes/controller_test.go46
1 files changed, 1 insertions, 45 deletions
diff --git a/plugin/kubernetes/controller_test.go b/plugin/kubernetes/controller_test.go
index 1663e4c6a..99d7e92f7 100644
--- a/plugin/kubernetes/controller_test.go
+++ b/plugin/kubernetes/controller_test.go
@@ -4,10 +4,10 @@ import (
"context"
"net"
"strconv"
- "strings"
"testing"
"github.com/coredns/coredns/plugin/test"
+
"github.com/miekg/dns"
api "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -15,50 +15,6 @@ import (
"k8s.io/client-go/kubernetes/fake"
)
-func endpointSubsets(addrs ...string) (eps []api.EndpointSubset) {
- for _, ap := range addrs {
- apa := strings.Split(ap, ":")
- address := apa[0]
- port, _ := strconv.Atoi(apa[1])
- eps = append(eps, api.EndpointSubset{Addresses: []api.EndpointAddress{{IP: address}}, Ports: []api.EndpointPort{{Port: int32(port)}}})
- }
- return eps
-}
-
-func TestEndpointsSubsetDiffs(t *testing.T) {
- var tests = []struct {
- a, b, expected api.Endpoints
- }{
- { // From a->b: Nothing changes
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- api.Endpoints{},
- },
- { // From a->b: Everything goes away
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- api.Endpoints{},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- },
- { // From a->b: Everything is new
- api.Endpoints{},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80", "10.0.0.2:8080")},
- },
- { // From a->b: One goes away, one is new
- api.Endpoints{Subsets: endpointSubsets("10.0.0.2:8080")},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.1:80")},
- api.Endpoints{Subsets: endpointSubsets("10.0.0.2:8080", "10.0.0.1:80")},
- },
- }
-
- for i, te := range tests {
- got := endpointsSubsetDiffs(&te.a, &te.b)
- if !endpointsEquivalent(got, &te.expected) {
- t.Errorf("Expected '%v' for test %v, got '%v'.", te.expected, i, got)
- }
- }
-}
-
func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++