Skip to content

Commit

Permalink
CoreDNS/SkyDNS provider
Browse files Browse the repository at this point in the history
This commit adds support for CoreDNS through its etcd middleware.
Because the middleware is backward compatible with SkyDNS this
commit adds support for SkyDNS as well. In fact, new provider
is available under two names in CLI (coredns and skydns).

All interactions with middleware happen through etcd cluster,
whose location (URIs) is specified via --etcd CLI parameter
by default http://localhost:2379).

The provider translates CoreDNS/DkyDNS SRV records to
A/CNAME + optional TXT endpoints, when reading from etcd and
combines A/CNAME with TXT endpoints back into single SRV record
when writing it back.

Also:
* adds github.com/coreos/etcd package to glide.yaml and vendor folder
  because it is used by the provider
* adds "interfaces" packages and moves Registry and Provider interfaces
  declaration there. This is required in order to use registry in
  provider unit tests. Otherwise there going to be circular imports
  because provider UTests would import registry which imports providers
  back.
  • Loading branch information
Stan Lagun committed Jun 26, 2017
1 parent 1592ef0 commit 2a103b4
Show file tree
Hide file tree
Showing 1,693 changed files with 487,116 additions and 30 deletions.
4 changes: 2 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

log "github.com/Sirupsen/logrus"

"github.com/kubernetes-incubator/external-dns/interfaces"
"github.com/kubernetes-incubator/external-dns/plan"
"github.com/kubernetes-incubator/external-dns/registry"
"github.com/kubernetes-incubator/external-dns/source"
)

Expand All @@ -34,7 +34,7 @@ import (
// * Tell the DNS provider to apply the changes calucated by the Plan.
type Controller struct {
Source source.Source
Registry registry.Registry
Registry interfaces.Registry
// The policy that defines which changes to DNS records are allowed
Policy plan.Policy
// The interval between individual synchronizations
Expand Down
1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ import:
- package: github.com/digitalocean/godo
version: ~1.1.0
- package: github.com/coreos/go-oidc
- package: github.com/coreos/etcd
28 changes: 28 additions & 0 deletions interfaces/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2017 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 interfaces

import (
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/plan"
)

// Provider defines the interface DNS providers should implement.
type Provider interface {
Records() ([]*endpoint.Endpoint, error)
ApplyChanges(changes *plan.Changes) error
}
31 changes: 31 additions & 0 deletions interfaces/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2017 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 interfaces

import (
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/plan"
)

// Registry is an interface which should enables ownership concept in external-dns
// Records() returns ALL records registered with DNS provider (TODO: for multi-zone support return all records)
// each entry includes owner information
// ApplyChanges(changes *plan.Changes) propagates the changes to the DNS Provider API and correspondingly updates ownership depending on type of registry being used
type Registry interface {
Records() ([]*endpoint.Endpoint, error)
ApplyChanges(changes *plan.Changes) error
}
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/kubernetes-incubator/external-dns/controller"
"github.com/kubernetes-incubator/external-dns/interfaces"
"github.com/kubernetes-incubator/external-dns/pkg/apis/externaldns"
"github.com/kubernetes-incubator/external-dns/pkg/apis/externaldns/validation"
"github.com/kubernetes-incubator/external-dns/plan"
Expand Down Expand Up @@ -108,7 +109,7 @@ func main() {

endpointsSource := source.NewDedupSource(source.NewMultiSource(sources))

var p provider.Provider
var p interfaces.Provider
switch cfg.Provider {
case "aws":
p, err = provider.NewAWSProvider(cfg.DomainFilter, cfg.DryRun)
Expand All @@ -122,14 +123,16 @@ func main() {
p, err = provider.NewDigitalOceanProvider(cfg.DomainFilter, cfg.DryRun)
case "inmemory":
p, err = provider.NewInMemoryProvider(provider.InMemoryWithDomain(cfg.DomainFilter), provider.InMemoryWithLogging()), nil
case "coredns", "skydns":
p, err = provider.NewCoreDNSProvider(cfg.ETCD, cfg.DryRun)
default:
log.Fatalf("unknown dns provider: %s", cfg.Provider)
}
if err != nil {
log.Fatal(err)
}

var r registry.Registry
var r interfaces.Registry
switch cfg.Registry {
case "noop":
r, err = registry.NewNoopRegistry(p)
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Config struct {
LogFormat string
MetricsAddress string
Debug bool
ETCD string
}

var defaultConfig = &Config{
Expand All @@ -73,6 +74,7 @@ var defaultConfig = &Config{
LogFormat: "text",
MetricsAddress: ":7979",
Debug: false,
ETCD: "http://localhost:2379",
}

// NewConfig returns new Config object
Expand All @@ -97,11 +99,12 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("compatibility", "Process annotation semantics from legacy implementations (optional, options: mate, molecule)").Default(defaultConfig.Compatibility).EnumVar(&cfg.Compatibility, "", "mate", "molecule")

// Flags related to providers
app.Flag("provider", "The DNS provider where the DNS records will be created (required, options: aws, google, azure, cloudflare, digitalocean, inmemory)").Required().PlaceHolder("provider").EnumVar(&cfg.Provider, "aws", "google", "azure", "cloudflare", "digitalocean", "inmemory")
app.Flag("provider", "The DNS provider where the DNS records will be created (required, options: aws, google, azure, cloudflare, digitalocean, inmemory, coredns, skydns)").Required().PlaceHolder("provider").EnumVar(&cfg.Provider, "aws", "google", "azure", "cloudflare", "digitalocean", "inmemory", "coredns", "skydns")
app.Flag("google-project", "When using the Google provider, specify the Google project (required when --provider=google)").Default(defaultConfig.GoogleProject).StringVar(&cfg.GoogleProject)
app.Flag("domain-filter", "Limit possible target zones by a domain suffix (optional)").Default(defaultConfig.DomainFilter).StringVar(&cfg.DomainFilter)
app.Flag("azure-config-file", "When using the Azure provider, specify the Azure configuration file (required when --provider=azure").Default(defaultConfig.AzureConfigFile).StringVar(&cfg.AzureConfigFile)
app.Flag("azure-resource-group", "When using the Azure provider, override the Azure resource group to use (optional)").Default(defaultConfig.AzureResourceGroup).StringVar(&cfg.AzureResourceGroup)
app.Flag("etcd", "ETCD cluster URI(s) for coredns/skydns provider").Default(defaultConfig.ETCD).StringVar(&cfg.ETCD)

// Flags related to policies
app.Flag("policy", "Modify how DNS records are sychronized between sources and providers (default: sync, options: sync, upsert-only)").Default(defaultConfig.Policy).EnumVar(&cfg.Policy, "sync", "upsert-only")
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/externaldns/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
LogFormat: "text",
MetricsAddress: ":7979",
Debug: false,
ETCD: "http://localhost:2379",
}

overriddenConfig = &Config{
Expand All @@ -72,6 +73,7 @@ var (
LogFormat: "json",
MetricsAddress: "127.0.0.1:9099",
Debug: true,
ETCD: "http://host:3378,http://host:3379",
}
)

Expand Down Expand Up @@ -116,6 +118,7 @@ func TestParseFlags(t *testing.T) {
"--log-format=json",
"--metrics-address=127.0.0.1:9099",
"--debug",
"--etcd=http://host:3378,http://host:3379",
},
envVars: map[string]string{},
expected: overriddenConfig,
Expand Down Expand Up @@ -145,6 +148,7 @@ func TestParseFlags(t *testing.T) {
"EXTERNAL_DNS_LOG_FORMAT": "json",
"EXTERNAL_DNS_METRICS_ADDRESS": "127.0.0.1:9099",
"EXTERNAL_DNS_DEBUG": "1",
"EXTERNAL_DNS_ETCD": "http://host:3378,http://host:3379",
},
expected: overriddenConfig,
},
Expand Down
Loading

0 comments on commit 2a103b4

Please sign in to comment.