diff --git a/docs/tutorials/gloo-proxy.md b/docs/tutorials/gloo-proxy.md index 7a9994eca6..52b1f830c0 100644 --- a/docs/tutorials/gloo-proxy.md +++ b/docs/tutorials/gloo-proxy.md @@ -25,7 +25,7 @@ spec: image: registry.k8s.io/external-dns/external-dns:v0.13.5 args: - --source=gloo-proxy - - --gloo-namespace=custom-gloo-system # gloo system namespace. Omit to use the default (gloo-system) + - --gloo-namespace=custom-gloo-system # gloo system namespace. Specify multiple times for multiple namespaces. Omit to use the default (gloo-system) - --provider=aws - --registry=txt - --txt-owner-id=my-identifier @@ -93,7 +93,7 @@ spec: image: registry.k8s.io/external-dns/external-dns:v0.13.5 args: - --source=gloo-proxy - - --gloo-namespace=custom-gloo-system # gloo system namespace. Omit to use the default (gloo-system) + - --gloo-namespace=custom-gloo-system # gloo system namespace. Specify multiple times for multiple namespaces. Omit to use the default (gloo-system) - --provider=aws - --registry=txt - --txt-owner-id=my-identifier diff --git a/main.go b/main.go index 63e065bad0..07a4986dfd 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { CFAPIEndpoint: cfg.CFAPIEndpoint, CFUsername: cfg.CFUsername, CFPassword: cfg.CFPassword, - GlooNamespace: cfg.GlooNamespace, + GlooNamespaces: cfg.GlooNamespaces, SkipperRouteGroupVersion: cfg.SkipperRouteGroupVersion, RequestTimeout: cfg.RequestTimeout, DefaultTargets: cfg.DefaultTargets, diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index e8ff366363..ad0c0fa9c8 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -47,7 +47,7 @@ type Config struct { KubeConfig string RequestTimeout time.Duration DefaultTargets []string - GlooNamespace string + GlooNamespaces []string SkipperRouteGroupVersion string Sources []string Namespace string @@ -213,7 +213,7 @@ var defaultConfig = &Config{ KubeConfig: "", RequestTimeout: time.Second * 30, DefaultTargets: []string{}, - GlooNamespace: "gloo-system", + GlooNamespaces: []string{"gloo-system"}, SkipperRouteGroupVersion: "zalando.org/v1", Sources: nil, Namespace: "", @@ -407,7 +407,7 @@ func (cfg *Config) ParseFlags(args []string) error { app.Flag("cf-password", "The password to log into the cloud foundry API").Default(defaultConfig.CFPassword).StringVar(&cfg.CFPassword) // Flags related to Gloo - app.Flag("gloo-namespace", "Gloo namespace. (default: gloo-system)").Default("gloo-system").StringVar(&cfg.GlooNamespace) + app.Flag("gloo-namespace", "The Gloo Proxy namespace; specify multiple times for multiple namespaces. (default: gloo-system)").Default("gloo-system").StringsVar(&cfg.GlooNamespaces) // Flags related to Skipper RouteGroup app.Flag("skipper-routegroup-groupversion", "The resource version for skipper routegroup").Default(source.DefaultRoutegroupVersion).StringVar(&cfg.SkipperRouteGroupVersion) diff --git a/pkg/apis/externaldns/types_test.go b/pkg/apis/externaldns/types_test.go index 12dc621306..277779d9b2 100644 --- a/pkg/apis/externaldns/types_test.go +++ b/pkg/apis/externaldns/types_test.go @@ -35,7 +35,7 @@ var ( APIServerURL: "", KubeConfig: "", RequestTimeout: time.Second * 30, - GlooNamespace: "gloo-system", + GlooNamespaces: []string{"gloo-system"}, SkipperRouteGroupVersion: "zalando.org/v1", Sources: []string{"service"}, Namespace: "", @@ -135,7 +135,7 @@ var ( APIServerURL: "http://127.0.0.1:8080", KubeConfig: "/some/path", RequestTimeout: time.Second * 77, - GlooNamespace: "gloo-not-system", + GlooNamespaces: []string{"gloo-not-system", "gloo-second-system"}, SkipperRouteGroupVersion: "zalando.org/v2", Sources: []string{"service", "ingress", "connector"}, Namespace: "namespace", @@ -266,6 +266,7 @@ func TestParseFlags(t *testing.T) { "--kubeconfig=/some/path", "--request-timeout=77s", "--gloo-namespace=gloo-not-system", + "--gloo-namespace=gloo-second-system", "--skipper-routegroup-groupversion=zalando.org/v2", "--source=service", "--source=ingress", @@ -392,7 +393,7 @@ func TestParseFlags(t *testing.T) { "EXTERNAL_DNS_KUBECONFIG": "/some/path", "EXTERNAL_DNS_REQUEST_TIMEOUT": "77s", "EXTERNAL_DNS_CONTOUR_LOAD_BALANCER": "heptio-contour-other/contour-other", - "EXTERNAL_DNS_GLOO_NAMESPACE": "gloo-not-system", + "EXTERNAL_DNS_GLOO_NAMESPACE": "gloo-not-system\ngloo-second-system", "EXTERNAL_DNS_SKIPPER_ROUTEGROUP_GROUPVERSION": "zalando.org/v2", "EXTERNAL_DNS_SOURCE": "service\ningress\nconnector", "EXTERNAL_DNS_NAMESPACE": "namespace", diff --git a/source/gloo_proxy.go b/source/gloo_proxy.go index 09e96ead05..cdc7d210ce 100644 --- a/source/gloo_proxy.go +++ b/source/gloo_proxy.go @@ -96,15 +96,16 @@ type proxyVirtualHostMetadataSourceResourceRef struct { type glooSource struct { dynamicKubeClient dynamic.Interface kubeClient kubernetes.Interface - glooNamespace string + glooNamespaces []string } // NewGlooSource creates a new glooSource with the given config -func NewGlooSource(dynamicKubeClient dynamic.Interface, kubeClient kubernetes.Interface, glooNamespace string) (Source, error) { +func NewGlooSource(dynamicKubeClient dynamic.Interface, kubeClient kubernetes.Interface, + glooNamespaces []string) (Source, error) { return &glooSource{ dynamicKubeClient, kubeClient, - glooNamespace, + glooNamespaces, }, nil } @@ -115,32 +116,34 @@ func (gs *glooSource) AddEventHandler(ctx context.Context, handler func()) { func (gs *glooSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) { endpoints := []*endpoint.Endpoint{} - proxies, err := gs.dynamicKubeClient.Resource(proxyGVR).Namespace(gs.glooNamespace).List(ctx, metav1.ListOptions{}) - if err != nil { - return nil, err - } - for _, obj := range proxies.Items { - proxy := proxy{} - jsonString, err := obj.MarshalJSON() - if err != nil { - return nil, err - } - err = json.Unmarshal(jsonString, &proxy) + for _, ns := range gs.glooNamespaces { + proxies, err := gs.dynamicKubeClient.Resource(proxyGVR).Namespace(ns).List(ctx, metav1.ListOptions{}) if err != nil { return nil, err } - log.Debugf("Gloo: Find %s proxy", proxy.Metadata.Name) - proxyTargets, err := gs.proxyTargets(ctx, proxy.Metadata.Name) - if err != nil { - return nil, err - } - log.Debugf("Gloo[%s]: Find %d target(s) (%+v)", proxy.Metadata.Name, len(proxyTargets), proxyTargets) - proxyEndpoints, err := gs.generateEndpointsFromProxy(ctx, &proxy, proxyTargets) - if err != nil { - return nil, err + for _, obj := range proxies.Items { + proxy := proxy{} + jsonString, err := obj.MarshalJSON() + if err != nil { + return nil, err + } + err = json.Unmarshal(jsonString, &proxy) + if err != nil { + return nil, err + } + log.Debugf("Gloo: Find %s proxy", proxy.Metadata.Name) + proxyTargets, err := gs.proxyTargets(ctx, proxy.Metadata.Name, ns) + if err != nil { + return nil, err + } + log.Debugf("Gloo[%s]: Find %d target(s) (%+v)", proxy.Metadata.Name, len(proxyTargets), proxyTargets) + proxyEndpoints, err := gs.generateEndpointsFromProxy(ctx, &proxy, proxyTargets) + if err != nil { + return nil, err + } + log.Debugf("Gloo[%s]: Generate %d endpoint(s)", proxy.Metadata.Name, len(proxyEndpoints)) + endpoints = append(endpoints, proxyEndpoints...) } - log.Debugf("Gloo[%s]: Generate %d endpoint(s)", proxy.Metadata.Name, len(proxyEndpoints)) - endpoints = append(endpoints, proxyEndpoints...) } return endpoints, nil } @@ -195,8 +198,8 @@ func (gs *glooSource) annotationsFromProxySource(ctx context.Context, virtualHos return annotations, nil } -func (gs *glooSource) proxyTargets(ctx context.Context, name string) (endpoint.Targets, error) { - svc, err := gs.kubeClient.CoreV1().Services(gs.glooNamespace).Get(ctx, name, metav1.GetOptions{}) +func (gs *glooSource) proxyTargets(ctx context.Context, name string, namespace string) (endpoint.Targets, error) { + svc, err := gs.kubeClient.CoreV1().Services(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/source/gloo_proxy_test.go b/source/gloo_proxy_test.go index 385d1a9692..1b72861cc7 100644 --- a/source/gloo_proxy_test.go +++ b/source/gloo_proxy_test.go @@ -311,7 +311,7 @@ func TestGlooSource(t *testing.T) { proxyGVR: "ProxyList", }) - source, err := NewGlooSource(fakeDynamicClient, fakeKubernetesClient, defaultGlooNamespace) + source, err := NewGlooSource(fakeDynamicClient, fakeKubernetesClient, []string{defaultGlooNamespace}) assert.NoError(t, err) assert.NotNil(t, source) diff --git a/source/store.go b/source/store.go index 1f2d1fbb0e..fab0371f6d 100644 --- a/source/store.go +++ b/source/store.go @@ -67,7 +67,7 @@ type Config struct { CFAPIEndpoint string CFUsername string CFPassword string - GlooNamespace string + GlooNamespaces []string SkipperRouteGroupVersion string RequestTimeout time.Duration DefaultTargets []string @@ -290,7 +290,7 @@ func BuildWithConfig(ctx context.Context, source string, p ClientGenerator, cfg if err != nil { return nil, err } - return NewGlooSource(dynamicClient, kubernetesClient, cfg.GlooNamespace) + return NewGlooSource(dynamicClient, kubernetesClient, cfg.GlooNamespaces) case "traefik-proxy": kubernetesClient, err := p.KubeClient() if err != nil {