mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
Add ID to Zone interface
This allows us to differentiate when we have two HostedZones with the same DNS name.
This commit is contained in:
parent
ac8aae584d
commit
816e50bd8d
@ -43,6 +43,8 @@ type Zones interface {
|
|||||||
type Zone interface {
|
type Zone interface {
|
||||||
// Name returns the name of the zone, e.g. "example.com"
|
// Name returns the name of the zone, e.g. "example.com"
|
||||||
Name() string
|
Name() string
|
||||||
|
// ID returns the unique provider identifier for the zone
|
||||||
|
ID() string
|
||||||
// ResourceRecordsets returns the provider's ResourceRecordSets interface, or false if not supported.
|
// ResourceRecordsets returns the provider's ResourceRecordSets interface, or false if not supported.
|
||||||
ResourceRecordSets() (ResourceRecordSets, bool)
|
ResourceRecordSets() (ResourceRecordSets, bool)
|
||||||
}
|
}
|
||||||
|
@ -141,11 +141,22 @@ func addRrsetOrFail(t *testing.T, rrsets dnsprovider.ResourceRecordSets, rrset d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TestResourceRecordSetsList verifies that listing of zones succeeds */
|
/* TestZonesList verifies that listing of zones succeeds */
|
||||||
func TestZonesList(t *testing.T) {
|
func TestZonesList(t *testing.T) {
|
||||||
firstZone(t)
|
firstZone(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TestZonesID verifies that the id of the zone is returned with the prefix removed */
|
||||||
|
func TestZonesID(t *testing.T) {
|
||||||
|
zone := firstZone(t)
|
||||||
|
|
||||||
|
// Check /hostedzone/ prefix is removed
|
||||||
|
zoneID := zone.ID()
|
||||||
|
if zoneID != zone.Name() {
|
||||||
|
t.Fatalf("Unexpected zone id: %q", zoneID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* TestZoneAddSuccess verifies that addition of a valid managed DNS zone succeeds */
|
/* TestZoneAddSuccess verifies that addition of a valid managed DNS zone succeeds */
|
||||||
func TestZoneAddSuccess(t *testing.T) {
|
func TestZoneAddSuccess(t *testing.T) {
|
||||||
testZoneName := "ubernetes.testing"
|
testZoneName := "ubernetes.testing"
|
||||||
|
@ -20,6 +20,7 @@ package stubs
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/route53"
|
"github.com/aws/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -108,14 +109,16 @@ func (r *Route53APIStub) ListHostedZonesPages(input *route53.ListHostedZonesInpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route53APIStub) CreateHostedZone(input *route53.CreateHostedZoneInput) (*route53.CreateHostedZoneOutput, error) {
|
func (r *Route53APIStub) CreateHostedZone(input *route53.CreateHostedZoneInput) (*route53.CreateHostedZoneOutput, error) {
|
||||||
if _, ok := r.zones[*input.Name]; ok {
|
name := aws.StringValue(input.Name)
|
||||||
return nil, fmt.Errorf("Error creating hosted DNS zone: %s already exists", *input.Name)
|
id := "/hostedzone/" + name
|
||||||
|
if _, ok := r.zones[id]; ok {
|
||||||
|
return nil, fmt.Errorf("Error creating hosted DNS zone: %s already exists", id)
|
||||||
}
|
}
|
||||||
r.zones[*input.Name] = &route53.HostedZone{
|
r.zones[id] = &route53.HostedZone{
|
||||||
Id: input.Name,
|
Id: aws.String(id),
|
||||||
Name: input.Name,
|
Name: aws.String(name),
|
||||||
}
|
}
|
||||||
return &route53.CreateHostedZoneOutput{HostedZone: r.zones[*input.Name]}, nil
|
return &route53.CreateHostedZoneOutput{HostedZone: r.zones[id]}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route53APIStub) DeleteHostedZone(input *route53.DeleteHostedZoneInput) (*route53.DeleteHostedZoneOutput, error) {
|
func (r *Route53APIStub) DeleteHostedZone(input *route53.DeleteHostedZoneInput) (*route53.DeleteHostedZoneOutput, error) {
|
||||||
|
@ -17,8 +17,10 @@ limitations under the License.
|
|||||||
package route53
|
package route53
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/route53"
|
"github.com/aws/aws-sdk-go/service/route53"
|
||||||
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Compile time check for interface adeherence
|
// Compile time check for interface adeherence
|
||||||
@ -30,7 +32,13 @@ type Zone struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (zone *Zone) Name() string {
|
func (zone *Zone) Name() string {
|
||||||
return *zone.impl.Name
|
return aws.StringValue(zone.impl.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (zone *Zone) ID() string {
|
||||||
|
id := aws.StringValue(zone.impl.Id)
|
||||||
|
id = strings.TrimPrefix(id, "/hostedzone/")
|
||||||
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zone *Zone) ResourceRecordSets() (dnsprovider.ResourceRecordSets, bool) {
|
func (zone *Zone) ResourceRecordSets() (dnsprovider.ResourceRecordSets, bool) {
|
||||||
|
@ -107,7 +107,7 @@ func NewFakeInterface() (dnsprovider.Interface, error) {
|
|||||||
interface_ := newInterfaceWithStub("", service)
|
interface_ := newInterfaceWithStub("", service)
|
||||||
zones := service.ManagedZones_
|
zones := service.ManagedZones_
|
||||||
// Add a fake zone to test against.
|
// Add a fake zone to test against.
|
||||||
zone := &stubs.ManagedZone{Service: zones, Name_: "example.com", Rrsets: []stubs.ResourceRecordSet{}}
|
zone := &stubs.ManagedZone{Service: zones, Name_: "example.com", Rrsets: []stubs.ResourceRecordSet{}, Id_: 1}
|
||||||
call := zones.Create(interface_.project(), zone)
|
call := zones.Create(interface_.project(), zone)
|
||||||
if _, err := call.Do(); err != nil {
|
if _, err := call.Do(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -118,11 +118,21 @@ func addRrsetOrFail(t *testing.T, rrsets dnsprovider.ResourceRecordSets, rrset d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TestResourceRecordSetsList verifies that listing of zones succeeds */
|
/* TestZonesList verifies that listing of zones succeeds */
|
||||||
func TestZonesList(t *testing.T) {
|
func TestZonesList(t *testing.T) {
|
||||||
firstZone(t)
|
firstZone(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TestZonesID verifies that the id of the zone is returned with the prefix removed */
|
||||||
|
func TestZonesID(t *testing.T) {
|
||||||
|
zone := firstZone(t)
|
||||||
|
|
||||||
|
zoneID := zone.ID()
|
||||||
|
if zoneID != "1" {
|
||||||
|
t.Fatalf("Unexpected zone id: %q", zoneID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* TestZoneAddSuccess verifies that addition of a valid managed DNS zone succeeds */
|
/* TestZoneAddSuccess verifies that addition of a valid managed DNS zone succeeds */
|
||||||
func TestZoneAddSuccess(t *testing.T) {
|
func TestZoneAddSuccess(t *testing.T) {
|
||||||
testZoneName := "ubernetesv2.test."
|
testZoneName := "ubernetesv2.test."
|
||||||
|
@ -83,7 +83,7 @@ type (
|
|||||||
// CreationTime() string // TODO: Add as needed
|
// CreationTime() string // TODO: Add as needed
|
||||||
// Description() string // TODO: Add as needed
|
// Description() string // TODO: Add as needed
|
||||||
DnsName() string
|
DnsName() string
|
||||||
// Id() uint64 // TODO: Add as needed
|
Id() uint64
|
||||||
// Kind() string // TODO: Add as needed
|
// Kind() string // TODO: Add as needed
|
||||||
Name() string
|
Name() string
|
||||||
// NameServerSet() string // TODO: Add as needed
|
// NameServerSet() string // TODO: Add as needed
|
||||||
|
@ -30,6 +30,10 @@ func (m ManagedZone) Name() string {
|
|||||||
return m.impl.Name
|
return m.impl.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m ManagedZone) Id() uint64 {
|
||||||
|
return m.impl.Id
|
||||||
|
}
|
||||||
|
|
||||||
func (m ManagedZone) DnsName() string {
|
func (m ManagedZone) DnsName() string {
|
||||||
return m.impl.DnsName
|
return m.impl.DnsName
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ var _ interfaces.ManagedZone = ManagedZone{}
|
|||||||
type ManagedZone struct {
|
type ManagedZone struct {
|
||||||
Service *ManagedZonesService
|
Service *ManagedZonesService
|
||||||
Name_ string
|
Name_ string
|
||||||
|
Id_ uint64
|
||||||
Rrsets []ResourceRecordSet
|
Rrsets []ResourceRecordSet
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +32,10 @@ func (m ManagedZone) Name() string {
|
|||||||
return m.Name_
|
return m.Name_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m ManagedZone) Id() uint64 {
|
||||||
|
return m.Id_
|
||||||
|
}
|
||||||
|
|
||||||
func (m ManagedZone) DnsName() string {
|
func (m ManagedZone) DnsName() string {
|
||||||
return m.Name_ // Don't bother storing a separate DNS name
|
return m.Name_ // Don't bother storing a separate DNS name
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package clouddns
|
|||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
||||||
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns/internal/interfaces"
|
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns/internal/interfaces"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Compile time check for interface adeherence
|
// Compile time check for interface adeherence
|
||||||
@ -33,6 +34,10 @@ func (zone *Zone) Name() string {
|
|||||||
return zone.impl.DnsName()
|
return zone.impl.DnsName()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (zone *Zone) ID() string {
|
||||||
|
return strconv.FormatUint(zone.impl.Id(), 10)
|
||||||
|
}
|
||||||
|
|
||||||
func (zone *Zone) ResourceRecordSets() (dnsprovider.ResourceRecordSets, bool) {
|
func (zone *Zone) ResourceRecordSets() (dnsprovider.ResourceRecordSets, bool) {
|
||||||
return &ResourceRecordSets{zone, zone.zones.interface_.service.ResourceRecordSets()}, true
|
return &ResourceRecordSets{zone, zone.zones.interface_.service.ResourceRecordSets()}, true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user