Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
ManagedZone updates
Browse files Browse the repository at this point in the history
* Make description optional
* fix managedZoneListToZoneList - use range index
* Make ID and description pointers
* Remove hostedzone prefix from AWS hosted zones
* Use status id in managedZoneListToZoneList
  • Loading branch information
mikenairn committed Dec 6, 2023
1 parent e14dbfb commit 2b20c79
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 84 deletions.
1 change: 0 additions & 1 deletion bundle/manifests/kuadrant.io_managedzones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ spec:
- name
type: object
required:
- description
- domainName
- providerRef
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
alm-examples: '[]'
capabilities: Basic Install
createdAt: "2023-11-29T09:52:49Z"
createdAt: "2023-12-04T11:02:57Z"
operators.operatorframework.io/builder: operator-sdk-v1.28.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: multicluster-gateway-controller.v0.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ spec:
- name
type: object
required:
- description
- domainName
- providerRef
type: object
Expand Down
13 changes: 4 additions & 9 deletions pkg/apis/v1alpha2/managedzone_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ type ManagedZoneReference struct {
type ManagedZoneSpec struct {
// ID is the provider assigned id of this zone (i.e. route53.HostedZone.ID).
// +optional
ID string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
//Domain name of this ManagedZone
// +required
// +kubebuilder:validation:Pattern=`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`
DomainName string `json:"domainName"`
//Description for this ManagedZone
Description string `json:"description"`
// +optional
Description *string `json:"description"`
// Reference to another managed zone that this managed zone belongs to.
// +optional
ParentManagedZone *ManagedZoneReference `json:"parentManagedZone,omitempty"`
Expand Down Expand Up @@ -97,13 +99,6 @@ type ManagedZoneList struct {
Items []ManagedZone `json:"items"`
}

type ManagedHost struct {
Subdomain string
Host string
ManagedZone *ManagedZone
DnsRecord *DNSRecord
}

func init() {
SchemeBuilder.Register(&ManagedZone{}, &ManagedZoneList{})
}
35 changes: 10 additions & 25 deletions pkg/apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controllers/managedzone/managedzone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *ManagedZoneReconciler) publishManagedZone(ctx context.Context, managedZ
}

func (r *ManagedZoneReconciler) deleteManagedZone(ctx context.Context, managedZone *v1alpha2.ManagedZone) error {
if managedZone.Spec.ID != "" {
if managedZone.Spec.ID != nil {
log.Log.Info("Skipping deletion of managed zone with provider ID specified in spec", "managedZone", managedZone.Name)
return nil
}
Expand Down
29 changes: 18 additions & 11 deletions pkg/dns/aws/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *Route53DNSProvider) ListZones() (dns.ZoneList, error) {
}
for _, zone := range zones {
dnsName := removeTrailingDot(*zone.Name)
zoneID := strings.TrimPrefix(*zone.Id, "/hostedzone/")
zoneID := removeHostedZoneIDPrefix(*zone.Id)
zoneList.Items = append(zoneList.Items, &dns.Zone{
ID: &zoneID,
DNSName: &dnsName,
Expand All @@ -134,8 +134,8 @@ func (p *Route53DNSProvider) ListZones() (dns.ZoneList, error) {

func (p *Route53DNSProvider) EnsureManagedZone(zone *v1alpha2.ManagedZone) (dns.ManagedZoneOutput, error) {
var zoneID string
if zone.Spec.ID != "" {
zoneID = zone.Spec.ID
if zone.Spec.ID != nil {
zoneID = *zone.Spec.ID
} else {
zoneID = zone.Status.ID
}
Expand All @@ -151,15 +151,18 @@ func (p *Route53DNSProvider) EnsureManagedZone(zone *v1alpha2.ManagedZone) (dns.
return managedZoneOutput, err
}

_, err = p.client.UpdateHostedZoneComment(&route53.UpdateHostedZoneCommentInput{
Comment: &zone.Spec.Description,
Id: &zoneID,
})
if err != nil {
log.Log.Error(err, "failed to update hosted zone comment")
//Only update if we created the managed zone and description is set
if zone.Spec.ID != nil && zone.Spec.Description != nil {
_, err = p.client.UpdateHostedZoneComment(&route53.UpdateHostedZoneCommentInput{
Comment: zone.Spec.Description,
Id: &zoneID,
})
if err != nil {
log.Log.Error(err, "failed to update hosted zone comment")
}
}

managedZoneOutput.ID = *getResp.HostedZone.Id
managedZoneOutput.ID = removeHostedZoneIDPrefix(*getResp.HostedZone.Id)
managedZoneOutput.RecordCount = *getResp.HostedZone.ResourceRecordSetCount
managedZoneOutput.NameServers = getResp.DelegationSet.NameServers

Expand All @@ -175,7 +178,7 @@ func (p *Route53DNSProvider) EnsureManagedZone(zone *v1alpha2.ManagedZone) (dns.
CallerReference: &callerRef,
Name: &zone.Spec.DomainName,
HostedZoneConfig: &route53.HostedZoneConfig{
Comment: &zone.Spec.Description,
Comment: zone.Spec.Description,
PrivateZone: aws.Bool(false),
},
})
Expand Down Expand Up @@ -406,3 +409,7 @@ func removeTrailingDot(hostname string) string {

return strings.TrimSuffix(hostname, ".")
}

func removeHostedZoneIDPrefix(id string) string {
return strings.TrimPrefix(id, "/hostedzone/")
}
8 changes: 6 additions & 2 deletions pkg/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ func (*FakeProvider) Delete(_ *v1alpha2.DNSRecord) error {
func (*FakeProvider) ListZones() (ZoneList, error) {
return ZoneList{}, nil
}
func (*FakeProvider) EnsureManagedZone(_ *v1alpha2.ManagedZone) (ManagedZoneOutput, error) {
return ManagedZoneOutput{}, nil
func (*FakeProvider) EnsureManagedZone(mz *v1alpha2.ManagedZone) (ManagedZoneOutput, error) {
return ManagedZoneOutput{
ID: *mz.Spec.ID,
NameServers: nil,
RecordCount: 0,
}, nil
}
func (*FakeProvider) DeleteManagedZone(_ *v1alpha2.ManagedZone) error { return nil }

Expand Down
6 changes: 3 additions & 3 deletions pkg/dns/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func (g *GoogleDNSProvider) DeleteManagedZone(managedZone *v1alpha2.ManagedZone)
func (g *GoogleDNSProvider) EnsureManagedZone(managedZone *v1alpha2.ManagedZone) (dns.ManagedZoneOutput, error) {
var zoneID string

if managedZone.Spec.ID != "" {
zoneID = managedZone.Spec.ID
if managedZone.Spec.ID != nil {
zoneID = *managedZone.Spec.ID
} else {
zoneID = managedZone.Status.ID
}
Expand All @@ -259,7 +259,7 @@ func (g *GoogleDNSProvider) createManagedZone(managedZone *v1alpha2.ManagedZone)
zone := dnsv1.ManagedZone{
Name: zoneID,
DnsName: ensureTrailingDot(managedZone.Spec.DomainName),
Description: managedZone.Spec.Description,
Description: *managedZone.Spec.Description,
}
mz, err := g.managedZonesClient.Create(g.project, &zone).Do()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ var _ = Describe("DNSPolicy Health Checks", func() {
gatewayClass = testutil.NewTestGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace, "example.com").ManagedZone
managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace).
WithID("1234").
WithDomainName("example.com").
WithDescription("example.com").
WithProviderSecret("secretname").
ManagedZone

Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())

gateway = testutil.NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace).
Expand Down Expand Up @@ -166,15 +172,15 @@ var _ = Describe("DNSPolicy Health Checks", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": HaveLen(6),
}),
}),
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": HaveLen(6),
}),
Expand Down
19 changes: 12 additions & 7 deletions test/policy_integration/dnspolicy_controller_multi_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
gatewayClass = testutil.NewTestGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace, "example.com").ManagedZone
managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace).
WithID("1234").
WithDomainName("example.com").
WithDescription("example.com").
WithProviderSecret("secretname").
ManagedZone
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())

gateway = testutil.NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace).
Expand Down Expand Up @@ -150,7 +155,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand All @@ -166,7 +171,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -210,7 +215,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -264,7 +269,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -342,7 +347,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -404,7 +409,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
gatewayClass = testutil.NewTestGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace, "example.com").ManagedZone
managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace).
WithID("1234").
WithDomainName("example.com").
WithDescription("example.com").
WithProviderSecret("secretname").
ManagedZone
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())

gateway = testutil.NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace).
Expand Down Expand Up @@ -121,7 +126,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand All @@ -137,7 +142,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -175,7 +180,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", recordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -214,7 +219,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
MatchFields(IgnoreExtras, Fields{
"ObjectMeta": HaveField("Name", wildcardRecordName),
"Spec": MatchFields(IgnoreExtras, Fields{
"ZoneID": PointTo(Equal(managedZone.Spec.ID)),
"ZoneID": Equal(managedZone.Spec.ID),
"ProviderRef": Equal(dnsPolicy.Spec.ProviderRef),
"Endpoints": ContainElements(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down
7 changes: 6 additions & 1 deletion test/policy_integration/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ var _ = Describe("DNSPolicy", func() {
gatewayClass = testutil.NewTestGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace, "example.com").ManagedZone
managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace).
WithID("1234").
WithDomainName("example.com").
WithDescription("example.com").
WithProviderSecret("secretname").
ManagedZone
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())

dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace).
Expand Down
4 changes: 2 additions & 2 deletions test/policy_integration/managedzone_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var _ = Describe("ManagedZoneReconciler", func() {
Namespace: defaultNS,
},
Spec: v1alpha2.ManagedZoneSpec{
ID: testutil.Domain,
ID: testutil.Pointer(testutil.Domain),
DomainName: testutil.Domain,
ProviderRef: v1alpha2.ProviderRef{
Name: providerCredential,
Expand Down Expand Up @@ -87,7 +87,7 @@ var _ = Describe("ManagedZoneReconciler", func() {
Namespace: defaultNS,
},
Spec: v1alpha2.ManagedZoneSpec{
ID: "invalid_domain",
ID: testutil.Pointer("invalid_domain"),
DomainName: "invalid_domain",
},
}
Expand Down
Loading

0 comments on commit 2b20c79

Please sign in to comment.