Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #971 from gcs278/release-4.12-shared-vpc
[release-4.12] NE-1372: Add support for AWS shared VPC in another account #966
- Loading branch information
Showing
83 changed files
with
12,671 additions
and
18,768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package split | ||
|
||
import ( | ||
"reflect" | ||
|
||
iov1 "github.com/openshift/api/operatoringress/v1" | ||
"github.com/openshift/cluster-ingress-operator/pkg/dns" | ||
logf "github.com/openshift/cluster-ingress-operator/pkg/log" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
) | ||
|
||
var ( | ||
_ dns.Provider = &Provider{} | ||
log = logf.Logger.WithName("dns") | ||
) | ||
|
||
// Provider is a dns.Provider that wraps two other providers. The first | ||
// provider is used for public hosted zones, and the second provider is used for | ||
// private hosted zones. | ||
type Provider struct { | ||
private, public dns.Provider | ||
privateZone *configv1.DNSZone | ||
} | ||
|
||
// NewProvider returns a new Provider that wraps the provided wrappers, using | ||
// the first for the public zone and the second for the private zone. | ||
func NewProvider(public, private dns.Provider, privateZone *configv1.DNSZone) *Provider { | ||
return &Provider{ | ||
public: public, | ||
private: private, | ||
privateZone: privateZone, | ||
} | ||
} | ||
|
||
// Ensure calls the Ensure method of one of the wrapped DNS providers. | ||
func (p *Provider) Ensure(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
if reflect.DeepEqual(zone, *p.privateZone) { | ||
return p.private.Ensure(record, zone) | ||
} | ||
return p.public.Ensure(record, zone) | ||
} | ||
|
||
// Delete calls the Delete method of one of the wrapped DNS providers. | ||
func (p *Provider) Delete(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
if reflect.DeepEqual(zone, *p.privateZone) { | ||
return p.private.Delete(record, zone) | ||
} | ||
return p.public.Delete(record, zone) | ||
} | ||
|
||
// Replace calls the Replace method of one of the wrapped DNS providers. | ||
func (p *Provider) Replace(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
if reflect.DeepEqual(zone, *p.privateZone) { | ||
return p.private.Replace(record, zone) | ||
} | ||
return p.public.Replace(record, zone) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package split_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
iov1 "github.com/openshift/api/operatoringress/v1" | ||
|
||
"github.com/openshift/cluster-ingress-operator/pkg/dns" | ||
splitdns "github.com/openshift/cluster-ingress-operator/pkg/dns/split" | ||
) | ||
|
||
// TestSplitDNSProvider verifies that the split DNS provider dispatches to the | ||
// public or private provider as appropriate for the DNS zone. | ||
func TestSplitDNSProvider(t *testing.T) { | ||
var ( | ||
// ch is a channel that is used in the fake public and private | ||
// providers to record which one is called. | ||
ch = make(chan string, 6) | ||
// getResult reads and returns one item from ch, or returns the | ||
// empty string if ch is empty. | ||
getResult = func() string { | ||
var result string | ||
select { | ||
case result = <-ch: | ||
default: | ||
} | ||
return result | ||
} | ||
// publicProvider is a fake dns.Provider for the public zone. | ||
publicProvider = newFakeProvider("public", ch) | ||
// privateProvider is a fake dns.Provider for the private zone. | ||
privateProvider = newFakeProvider("private", ch) | ||
// publicZoneWithID is a public zone that is defined by ID. | ||
publicZoneWithID = configv1.DNSZone{ID: "public_zone"} | ||
// privateZoneWithID is a private zone that is defined by ID. | ||
privateZoneWithID = configv1.DNSZone{ID: "private_zone"} | ||
// publicZoneWithTags is a public zone that is defined by tags. | ||
publicZoneWithTags = configv1.DNSZone{Tags: map[string]string{"zone": "public"}} | ||
// privateZoneWithID is a private zone that is defined by tags. | ||
privateZoneWithTags = configv1.DNSZone{Tags: map[string]string{"zone": "private"}} | ||
) | ||
testCases := []struct { | ||
name string | ||
publicZone configv1.DNSZone | ||
privateZone configv1.DNSZone | ||
publishToZone configv1.DNSZone | ||
expect string | ||
}{ | ||
{ | ||
name: "publish to public zone specified by id", | ||
publicZone: publicZoneWithID, | ||
privateZone: privateZoneWithID, | ||
publishToZone: publicZoneWithID, | ||
expect: "public", | ||
}, | ||
{ | ||
name: "publish to private zone specified by id", | ||
publicZone: publicZoneWithID, | ||
privateZone: privateZoneWithID, | ||
publishToZone: privateZoneWithID, | ||
expect: "private", | ||
}, | ||
{ | ||
name: "publish to public zone specified by tags", | ||
publicZone: publicZoneWithTags, | ||
privateZone: privateZoneWithID, | ||
publishToZone: publicZoneWithTags, | ||
expect: "public", | ||
}, | ||
{ | ||
name: "publish to private zone specified by tags", | ||
publicZone: publicZoneWithTags, | ||
privateZone: privateZoneWithTags, | ||
publishToZone: privateZoneWithTags, | ||
expect: "private", | ||
}, | ||
{ | ||
name: "publish to other zone should fall back to the public zone", | ||
publicZone: publicZoneWithID, | ||
privateZone: privateZoneWithID, | ||
publishToZone: configv1.DNSZone{ID: "other_zone"}, | ||
expect: "public", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
provider := splitdns.NewProvider(publicProvider, privateProvider, &tc.privateZone) | ||
assert.NoError(t, provider.Ensure(&iov1.DNSRecord{}, tc.publishToZone)) | ||
assert.Equal(t, tc.expect, getResult()) | ||
assert.NoError(t, provider.Replace(&iov1.DNSRecord{}, tc.publishToZone)) | ||
assert.Equal(t, tc.expect, getResult()) | ||
assert.NoError(t, provider.Delete(&iov1.DNSRecord{}, tc.publishToZone)) | ||
assert.Equal(t, tc.expect, getResult()) | ||
assert.Empty(t, ch) | ||
}) | ||
} | ||
|
||
} | ||
|
||
var _ dns.Provider = &fakeProvider{} | ||
|
||
type fakeProvider struct { | ||
name string | ||
recorder chan string | ||
} | ||
|
||
func (p *fakeProvider) Ensure(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
p.recorder <- p.name | ||
return nil | ||
} | ||
func (p *fakeProvider) Delete(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
p.recorder <- p.name | ||
return nil | ||
} | ||
func (p *fakeProvider) Replace(record *iov1.DNSRecord, zone configv1.DNSZone) error { | ||
p.recorder <- p.name | ||
return nil | ||
} | ||
|
||
// newFakeProvider returns a new dns.Provider that records invocations. | ||
func newFakeProvider(name string, ch chan string) dns.Provider { | ||
return &fakeProvider{name, ch} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.