diff --git a/docs/contributing/sources-and-providers.md b/docs/contributing/sources-and-providers.md index 3d51b3598..37c9e1163 100644 --- a/docs/contributing/sources-and-providers.md +++ b/docs/contributing/sources-and-providers.md @@ -25,6 +25,7 @@ All sources live in package `source`. * `FakeSource`: returns a random list of Endpoints for the purpose of testing providers without having access to a Kubernetes cluster. * `ConnectorSource`: returns a list of Endpoint objects which are served by a tcp server configured through `connector-source-server` flag. * `CRDSource`: returns a list of Endpoint objects sourced from the spec of CRD objects. For more details refer to [CRD source](../crd-source.md) documentation. +* `EmptySource`: returns an empty list of Endpoint objects for the purpose of testing and cleaning out entries. ### Providers diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index 0b3c4dde5..142c0ce37 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -257,7 +257,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 processing sources - app.Flag("source", "The resource types that are queried for endpoints; specify multiple times for multiple sources (required, options: service, ingress, fake, connector, istio-gateway, cloudfoundry, crd").Required().PlaceHolder("source").EnumsVar(&cfg.Sources, "service", "ingress", "istio-gateway", "cloudfoundry", "fake", "connector", "crd") + app.Flag("source", "The resource types that are queried for endpoints; specify multiple times for multiple sources (required, options: service, ingress, fake, connector, istio-gateway, cloudfoundry, crd, empty").Required().PlaceHolder("source").EnumsVar(&cfg.Sources, "service", "ingress", "istio-gateway", "cloudfoundry", "fake", "connector", "crd", "empty") app.Flag("namespace", "Limit sources of endpoints to a specific namespace (default: all namespaces)").Default(defaultConfig.Namespace).StringVar(&cfg.Namespace) app.Flag("annotation-filter", "Filter sources managed by external-dns via annotation using label selector semantics (default: all sources)").Default(defaultConfig.AnnotationFilter).StringVar(&cfg.AnnotationFilter) app.Flag("fqdn-template", "A templated string that's used to generate DNS names from sources that don't define a hostname themselves, or to add a hostname suffix when paired with the fake source (optional). Accepts comma separated list for multiple global FQDN.").Default(defaultConfig.FQDNTemplate).StringVar(&cfg.FQDNTemplate) diff --git a/source/empty.go b/source/empty.go new file mode 100644 index 000000000..c219581d3 --- /dev/null +++ b/source/empty.go @@ -0,0 +1,32 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package source + +import "github.com/kubernetes-incubator/external-dns/endpoint" + +// emptySource is a Source that returns no endpoints. +type emptySource struct{} + +// Endpoints collects endpoints of all nested Sources and returns them in a single slice. +func (e *emptySource) Endpoints() ([]*endpoint.Endpoint, error) { + return []*endpoint.Endpoint{}, nil +} + +// NewEmptySource creates a new emptySource. +func NewEmptySource() Source { + return &emptySource{} +} diff --git a/source/empty_test.go b/source/empty_test.go new file mode 100644 index 000000000..f82f1a39d --- /dev/null +++ b/source/empty_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package source + +import ( + "testing" +) + +func TestEmptySourceReturnsEmpty(t *testing.T) { + e := NewEmptySource() + + endpoints, err := e.Endpoints() + if err != nil { + t.Errorf("Expected no error but got %s", err.Error()) + } + + count := len(endpoints) + if count != 0 { + t.Errorf("Expected 0 endpoints but got %d", count) + } +}