Skip to content

Commit

Permalink
Merge f7e360d into e3055f1
Browse files Browse the repository at this point in the history
  • Loading branch information
josephglanville committed Jun 24, 2020
2 parents e3055f1 + f7e360d commit 84d697c
Show file tree
Hide file tree
Showing 37 changed files with 1,664 additions and 196 deletions.
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *Controller) RunOnce(ctx context.Context) error {

ctx = context.WithValue(ctx, provider.RecordsContextKey, records)

endpoints, err := c.Source.Endpoints()
endpoints, err := c.Source.Endpoints(ctx)
if err != nil {
sourceErrorsTotal.Inc()
deprecatedSourceErrors.Inc()
Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ require (
github.com/exoscale/egoscale v0.18.1
github.com/ffledgling/pdns-go v0.0.0-20180219074714-524e7daccd99
github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/sync v0.0.0-20180314180146-1d60e4601c6f
github.com/google/go-cmp v0.4.1
github.com/gophercloud/gophercloud v0.1.0
github.com/gorilla/mux v1.7.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/infobloxopen/infoblox-go-client v0.0.0-20180606155407-61dc5f9b0a65
github.com/json-iterator/go v1.1.9 // indirect
github.com/linki/instrumented_http v0.2.0
github.com/linode/linodego v0.15.0
github.com/linode/linodego v0.19.0
github.com/maxatome/go-testdeep v1.4.0
github.com/miekg/dns v1.1.25
github.com/nesv/go-dynect v0.6.0
github.com/nic-at/rc0go v1.1.0
github.com/openshift/api v0.0.0-20200302134843-001335d6cc34
github.com/openshift/client-go v0.0.0-20200116145930-eb24d03d8420
github.com/openshift/api v0.0.0-20200605231317-fb2a6ca106ae
github.com/openshift/client-go v0.0.0-20200608144219-584632b8fc73
github.com/oracle/oci-go-sdk v1.8.0
github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014
github.com/pkg/errors v0.9.1
github.com/projectcontour/contour v1.4.0
github.com/projectcontour/contour v1.5.0
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/client_model v0.2.0 // indirect
github.com/sanyu/dynectsoap v0.0.0-20181203081243-b83de5edc4e0
github.com/satori/go.uuid v1.2.0 // indirect
github.com/sirupsen/logrus v1.4.2
Expand All @@ -59,11 +63,11 @@ require (
google.golang.org/api v0.15.0
gopkg.in/ns1/ns1-go.v2 v2.0.0-20190322154155-0dafb5275fd1
gopkg.in/yaml.v2 v2.2.8
istio.io/api v0.0.0-20200324230725-4b064f75ad8f
istio.io/client-go v0.0.0-20200324231043-96a582576da1
k8s.io/api v0.17.5
k8s.io/apimachinery v0.17.5
k8s.io/client-go v0.17.5
istio.io/api v0.0.0-20200529165953-72dad51d4ffc
istio.io/client-go v0.0.0-20200529172309-31c16ea3f751
k8s.io/api v0.18.3
k8s.io/apimachinery v0.18.3
k8s.io/client-go v0.18.3
)

replace (
Expand All @@ -72,5 +76,6 @@ replace (
github.com/Azure/go-autorest/autorest/adal => github.com/Azure/go-autorest/autorest/adal v0.6.0
github.com/Azure/go-autorest/autorest/azure/auth => github.com/Azure/go-autorest/autorest/azure/auth v0.3.0
github.com/golang/glog => github.com/kubermatic/glog-logrus v0.0.0-20180829085450-3fa5b9870d1d
google.golang.org/grpc => google.golang.org/grpc v1.26.0
k8s.io/klog => github.com/mikkeloscar/knolog v0.0.0-20190326191552-80742771eb6b
)
146 changes: 89 additions & 57 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/testutils/mock_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type MockSource struct {
}

// Endpoints returns the desired mock endpoints.
func (m *MockSource) Endpoints() ([]*endpoint.Endpoint, error) {
func (m *MockSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
args := m.Called()

endpoints := args.Get(0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("skipper-routegroup-groupversion", "The resource version for skipper routegroup").Default(source.DefaultRoutegroupVersion).StringVar(&cfg.SkipperRouteGroupVersion)

// 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, node, fake, connector, istio-gateway, cloudfoundry, contour-ingressroute, crd, empty, skipper-routegroup,openshift-route)").Required().PlaceHolder("source").EnumsVar(&cfg.Sources, "service", "ingress", "node", "istio-gateway", "cloudfoundry", "contour-ingressroute", "fake", "connector", "crd", "empty", "skipper-routegroup", "openshift-route")
app.Flag("source", "The resource types that are queried for endpoints; specify multiple times for multiple sources (required, options: service, ingress, node, fake, connector, istio-gateway, cloudfoundry, contour-ingressroute, contour-httpproxy, crd, empty, skipper-routegroup,openshift-route)").Required().PlaceHolder("source").EnumsVar(&cfg.Sources, "service", "ingress", "node", "istio-gateway", "cloudfoundry", "contour-ingressroute", "contour-httpproxy", "fake", "connector", "crd", "empty", "skipper-routegroup", "openshift-route")

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)
Expand Down
2 changes: 1 addition & 1 deletion source/cloudfoundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (rs *cloudfoundrySource) AddEventHandler(ctx context.Context, handler func(
}

// Endpoints returns endpoint objects
func (rs *cloudfoundrySource) Endpoints() ([]*endpoint.Endpoint, error) {
func (rs *cloudfoundrySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
endpoints := []*endpoint.Endpoint{}

u, err := url.Parse(rs.client.Config.ApiAddress)
Expand Down
2 changes: 1 addition & 1 deletion source/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewConnectorSource(remoteServer string) (Source, error) {
}

// Endpoints returns endpoint objects.
func (cs *connectorSource) Endpoints() ([]*endpoint.Endpoint, error) {
func (cs *connectorSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
endpoints := []*endpoint.Endpoint{}

conn, err := net.DialTimeout("tcp", cs.remoteServer, dialTimeout)
Expand Down
3 changes: 2 additions & 1 deletion source/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package source

import (
"context"
"encoding/gob"
"net"
"testing"
Expand Down Expand Up @@ -124,7 +125,7 @@ func testConnectorSourceEndpoints(t *testing.T) {
}
cs, _ := NewConnectorSource(ti.serverAddress)

endpoints, err := cs.Endpoints()
endpoints, err := cs.Endpoints(context.Background())
if ti.expectError {
assert.Error(t, err)
} else {
Expand Down
14 changes: 7 additions & 7 deletions source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (cs *crdSource) AddEventHandler(ctx context.Context, handler func()) {
}

// Endpoints returns endpoint objects.
func (cs *crdSource) Endpoints() ([]*endpoint.Endpoint, error) {
func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
endpoints := []*endpoint.Endpoint{}

result, err := cs.List(&metav1.ListOptions{})
result, err := cs.List(ctx, &metav1.ListOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func (cs *crdSource) Endpoints() ([]*endpoint.Endpoint, error) {

dnsEndpoint.Status.ObservedGeneration = dnsEndpoint.Generation
// Update the ObservedGeneration
_, err = cs.UpdateStatus(&dnsEndpoint)
_, err = cs.UpdateStatus(ctx, &dnsEndpoint)
if err != nil {
log.Warnf("Could not update ObservedGeneration of the CRD: %v", err)
}
Expand All @@ -181,26 +181,26 @@ func (cs *crdSource) setResourceLabel(crd *endpoint.DNSEndpoint, endpoints []*en
}
}

func (cs *crdSource) List(opts *metav1.ListOptions) (result *endpoint.DNSEndpointList, err error) {
func (cs *crdSource) List(ctx context.Context, opts *metav1.ListOptions) (result *endpoint.DNSEndpointList, err error) {
result = &endpoint.DNSEndpointList{}
err = cs.crdClient.Get().
Namespace(cs.namespace).
Resource(cs.crdResource).
VersionedParams(opts, cs.codec).
Do().
Do(ctx).
Into(result)
return
}

func (cs *crdSource) UpdateStatus(dnsEndpoint *endpoint.DNSEndpoint) (result *endpoint.DNSEndpoint, err error) {
func (cs *crdSource) UpdateStatus(ctx context.Context, dnsEndpoint *endpoint.DNSEndpoint) (result *endpoint.DNSEndpoint, err error) {
result = &endpoint.DNSEndpoint{}
err = cs.crdClient.Put().
Namespace(dnsEndpoint.Namespace).
Resource(cs.crdResource).
Name(dnsEndpoint.Name).
SubResource("status").
Body(dnsEndpoint).
Do().
Do(ctx).
Into(result)
return
}
Expand Down
5 changes: 3 additions & 2 deletions source/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package source

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -318,7 +319,7 @@ func testCRDSourceEndpoints(t *testing.T) {

cs, _ := NewCRDSource(restClient, ti.namespace, ti.kind, ti.annotationFilter, scheme)

receivedEndpoints, err := cs.Endpoints()
receivedEndpoints, err := cs.Endpoints(context.Background())
if ti.expectError {
require.Errorf(t, err, "Received err %v", err)
} else {
Expand All @@ -341,7 +342,7 @@ func testCRDSourceEndpoints(t *testing.T) {

func validateCRDResource(t *testing.T, src Source, expectError bool) {
cs := src.(*crdSource)
result, err := cs.List(&metav1.ListOptions{})
result, err := cs.List(context.Background(), &metav1.ListOptions{})
if expectError {
require.Errorf(t, err, "Received err %v", err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions source/dedup_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func NewDedupSource(source Source) Source {
}

// Endpoints collects endpoints from its wrapped source and returns them without duplicates.
func (ms *dedupSource) Endpoints() ([]*endpoint.Endpoint, error) {
func (ms *dedupSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
result := []*endpoint.Endpoint{}
collected := map[string]bool{}

endpoints, err := ms.source.Endpoints()
endpoints, err := ms.source.Endpoints(ctx)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion source/dedup_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package source

import (
"context"
"testing"

"sigs.k8s.io/external-dns/endpoint"
Expand Down Expand Up @@ -97,7 +98,7 @@ func testDedupEndpoints(t *testing.T) {
// Create our object under test and get the endpoints.
source := NewDedupSource(mockSource)

endpoints, err := source.Endpoints()
endpoints, err := source.Endpoints(context.Background())
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion source/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (e *emptySource) AddEventHandler(ctx context.Context, handler func()) {
}

// Endpoints collects endpoints of all nested Sources and returns them in a single slice.
func (e *emptySource) Endpoints() ([]*endpoint.Endpoint, error) {
func (e *emptySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
return []*endpoint.Endpoint{}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion source/empty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ limitations under the License.
package source

import (
"context"
"testing"
)

func TestEmptySourceReturnsEmpty(t *testing.T) {
e := NewEmptySource()

endpoints, err := e.Endpoints()
endpoints, err := e.Endpoints(context.Background())
if err != nil {
t.Errorf("Expected no error but got %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion source/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (sc *fakeSource) AddEventHandler(ctx context.Context, handler func()) {
}

// Endpoints returns endpoint objects.
func (sc *fakeSource) Endpoints() ([]*endpoint.Endpoint, error) {
func (sc *fakeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
endpoints := make([]*endpoint.Endpoint, 10)

for i := 0; i < 10; i++ {
Expand Down
3 changes: 2 additions & 1 deletion source/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package source

import (
"context"
"net"
"regexp"
"testing"
Expand All @@ -27,7 +28,7 @@ import (
func generateTestEndpoints() []*endpoint.Endpoint {
sc, _ := NewFakeSource("")

endpoints, _ := sc.Endpoints()
endpoints, _ := sc.Endpoints(context.Background())

return endpoints
}
Expand Down
4 changes: 2 additions & 2 deletions source/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func NewIstioGatewaySource(

// Endpoints returns endpoint objects for each host-target combination that should be processed.
// Retrieves all gateway resources in the source's namespace(s).
func (sc *gatewaySource) Endpoints() ([]*endpoint.Endpoint, error) {
gwList, err := sc.istioClient.NetworkingV1alpha3().Gateways(sc.namespace).List(metav1.ListOptions{})
func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
gwList, err := sc.istioClient.NetworkingV1alpha3().Gateways(sc.namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions source/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package source

import (
"context"
"testing"

"github.com/pkg/errors"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (suite *GatewaySuite) SetupTest() {
}

for _, service := range suite.lbServices {
_, err = fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(service)
_, err = fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(context.Background(), service, metav1.CreateOptions{})
suite.NoError(err, "should succeed")
}

Expand All @@ -82,7 +83,7 @@ func (suite *GatewaySuite) SetupTest() {
}

func (suite *GatewaySuite) TestResourceLabelIsSet() {
endpoints, _ := suite.source.Endpoints()
endpoints, _ := suite.source.Endpoints(context.Background())
for _, ep := range endpoints {
suite.Equal("gateway/default/foo-gateway-with-targets", ep.Labels[endpoint.ResourceLabelKey], "should set correct resource label")
}
Expand Down Expand Up @@ -1078,14 +1079,14 @@ func testGatewayEndpoints(t *testing.T) {

for _, lb := range ti.lbServices {
service := lb.Service()
_, err := fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(service)
_, err := fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(context.Background(), service, metav1.CreateOptions{})
require.NoError(t, err)
}

fakeIstioClient := NewFakeConfigStore()
for _, config := range ti.configItems {
gatewayCfg := config.Config()
_, err := fakeIstioClient.NetworkingV1alpha3().Gateways(ti.targetNamespace).Create(&gatewayCfg)
_, err := fakeIstioClient.NetworkingV1alpha3().Gateways(ti.targetNamespace).Create(context.Background(), &gatewayCfg, metav1.CreateOptions{})
require.NoError(t, err)
}

Expand All @@ -1100,7 +1101,7 @@ func testGatewayEndpoints(t *testing.T) {
)
require.NoError(t, err)

res, err := gatewaySource.Endpoints()
res, err := gatewaySource.Endpoints(context.Background())
if ti.expectError {
assert.Error(t, err)
} else {
Expand All @@ -1119,7 +1120,7 @@ func newTestGatewaySource(loadBalancerList []fakeIngressGatewayService) (*gatewa

for _, lb := range loadBalancerList {
service := lb.Service()
_, err := fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(service)
_, err := fakeKubernetesClient.CoreV1().Services(service.Namespace).Create(context.Background(), service, metav1.CreateOptions{})
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 84d697c

Please sign in to comment.