Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e42f5af

Browse files
committed
Merge pull request #16219 from thockin/resolvconf-filter
Add a cloud-provider hook to scrub DNS for pods
2 parents a094a6e + 42c7fec commit e42f5af

File tree

12 files changed

+139
-4
lines changed

12 files changed

+139
-4
lines changed

pkg/cloudprovider/cloud.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type Interface interface {
3939
Routes() (Routes, bool)
4040
// ProviderName returns the cloud provider ID.
4141
ProviderName() string
42+
// ScrubDNS provides an opportunity for cloud-provider-specific code to process DNS settings for pods.
43+
ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string)
4244
}
4345

4446
// Clusters is an abstract, pluggable interface for clusters of containers.

pkg/cloudprovider/providers/aws/aws.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ func (aws *AWSCloud) ProviderName() string {
597597
return ProviderName
598598
}
599599

600+
// ScrubDNS filters DNS settings for pods.
601+
func (aws *AWSCloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
602+
return nameservers, searches
603+
}
604+
600605
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Amazon Web Services.
601606
func (s *AWSCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
602607
return s, true

pkg/cloudprovider/providers/fake/fake.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func (f *FakeCloud) ProviderName() string {
9494
return ProviderName
9595
}
9696

97+
// ScrubDNS filters DNS settings for pods.
98+
func (f *FakeCloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
99+
return nameservers, searches
100+
}
101+
97102
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
98103
// Actually it just returns f itself.
99104
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {

pkg/cloudprovider/providers/gce/gce.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net"
2323
"net/http"
2424
"path"
25+
"regexp"
2526
"sort"
2627
"strconv"
2728
"strings"
@@ -201,6 +202,20 @@ func (gce *GCECloud) ProviderName() string {
201202
return ProviderName
202203
}
203204

205+
// Known-useless DNS search path.
206+
var uselessDNSSearchRE = regexp.MustCompile(`^[0-9]+.google.internal.$`)
207+
208+
// ScrubDNS filters DNS settings for pods.
209+
func (gce *GCECloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
210+
// GCE has too many search paths by default. Filter the ones we know are useless.
211+
for _, s := range searches {
212+
if !uselessDNSSearchRE.MatchString(s) {
213+
srchOut = append(srchOut, s)
214+
}
215+
}
216+
return nameservers, srchOut
217+
}
218+
204219
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
205220
func (gce *GCECloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
206221
return gce, true

pkg/cloudprovider/providers/gce/gce_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ limitations under the License.
1616

1717
package gce
1818

19-
import "testing"
19+
import (
20+
"reflect"
21+
"testing"
22+
)
2023

2124
func TestGetRegion(t *testing.T) {
2225
gce := &GCECloud{
@@ -96,3 +99,39 @@ func TestComparingHostURLs(t *testing.T) {
9699
}
97100
}
98101
}
102+
103+
func TestScrubDNS(t *testing.T) {
104+
tcs := []struct {
105+
nameserversIn []string
106+
searchesIn []string
107+
nameserversOut []string
108+
searchesOut []string
109+
}{
110+
{
111+
nameserversIn: []string{"1.2.3.4", "5.6.7.8"},
112+
nameserversOut: []string{"1.2.3.4", "5.6.7.8"},
113+
},
114+
{
115+
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "google.internal."},
116+
searchesOut: []string{"c.prj.internal.", "google.internal."},
117+
},
118+
{
119+
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "zone.c.prj.internal.", "google.internal."},
120+
searchesOut: []string{"c.prj.internal.", "zone.c.prj.internal.", "google.internal."},
121+
},
122+
{
123+
searchesIn: []string{"c.prj.internal.", "12345678910.google.internal.", "zone.c.prj.internal.", "google.internal.", "unexpected"},
124+
searchesOut: []string{"c.prj.internal.", "zone.c.prj.internal.", "google.internal.", "unexpected"},
125+
},
126+
}
127+
gce := &GCECloud{}
128+
for i := range tcs {
129+
n, s := gce.ScrubDNS(tcs[i].nameserversIn, tcs[i].searchesIn)
130+
if !reflect.DeepEqual(n, tcs[i].nameserversOut) {
131+
t.Errorf("Expected %v, got %v", tcs[i].nameserversOut, n)
132+
}
133+
if !reflect.DeepEqual(s, tcs[i].searchesOut) {
134+
t.Errorf("Expected %v, got %v", tcs[i].searchesOut, s)
135+
}
136+
}
137+
}

pkg/cloudprovider/providers/mesos/mesos.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func (c *MesosCloud) ProviderName() string {
124124
return ProviderName
125125
}
126126

127+
// ScrubDNS filters DNS settings for pods.
128+
func (c *MesosCloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
129+
return nameservers, searches
130+
}
131+
127132
// ListClusters lists the names of the available Mesos clusters.
128133
func (c *MesosCloud) ListClusters() ([]string, error) {
129134
// Always returns a single cluster (this one!)

pkg/cloudprovider/providers/openstack/openstack.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ func (os *OpenStack) ProviderName() string {
399399
return ProviderName
400400
}
401401

402+
// ScrubDNS filters DNS settings for pods.
403+
func (os *OpenStack) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
404+
return nameservers, searches
405+
}
406+
402407
type LoadBalancer struct {
403408
network *gophercloud.ServiceClient
404409
compute *gophercloud.ServiceClient

pkg/cloudprovider/providers/ovirt/ovirt.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func (v *OVirtCloud) ProviderName() string {
123123
return ProviderName
124124
}
125125

126+
// ScrubDNS filters DNS settings for pods.
127+
func (v *OVirtCloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
128+
return nameservers, searches
129+
}
130+
126131
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for oVirt cloud
127132
func (v *OVirtCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
128133
return nil, false

pkg/cloudprovider/providers/rackspace/rackspace.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ func (os *Rackspace) ProviderName() string {
362362
return ProviderName
363363
}
364364

365+
// ScrubDNS filters DNS settings for pods.
366+
func (os *Rackspace) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
367+
return nameservers, searches
368+
}
369+
365370
func (os *Rackspace) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
366371
return nil, false
367372
}

pkg/cloudprovider/providers/vagrant/vagrant.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func (v *VagrantCloud) ProviderName() string {
9191
return ProviderName
9292
}
9393

94+
// ScrubDNS filters DNS settings for pods.
95+
func (v *VagrantCloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string) {
96+
return nameservers, searches
97+
}
98+
9499
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Vagrant cloud.
95100
func (v *VagrantCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
96101
return nil, false

0 commit comments

Comments
 (0)