diff --git a/bundle/manifests/kuadrant.io_managedzones.yaml b/bundle/manifests/kuadrant.io_managedzones.yaml index d14c1925..74e102b9 100644 --- a/bundle/manifests/kuadrant.io_managedzones.yaml +++ b/bundle/manifests/kuadrant.io_managedzones.yaml @@ -90,7 +90,6 @@ spec: - name type: object required: - - description - domainName - providerRef type: object diff --git a/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml b/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml index fbd8e8a4..081e160c 100644 --- a/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml +++ b/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml @@ -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 diff --git a/config/policy-controller/crd/bases/kuadrant.io_managedzones.yaml b/config/policy-controller/crd/bases/kuadrant.io_managedzones.yaml index 3001af1d..e69a3717 100644 --- a/config/policy-controller/crd/bases/kuadrant.io_managedzones.yaml +++ b/config/policy-controller/crd/bases/kuadrant.io_managedzones.yaml @@ -91,7 +91,6 @@ spec: - name type: object required: - - description - domainName - providerRef type: object diff --git a/pkg/apis/v1alpha2/managedzone_types.go b/pkg/apis/v1alpha2/managedzone_types.go index 0b693190..ffcafde8 100644 --- a/pkg/apis/v1alpha2/managedzone_types.go +++ b/pkg/apis/v1alpha2/managedzone_types.go @@ -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"` @@ -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{}) } diff --git a/pkg/apis/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/v1alpha2/zz_generated.deepcopy.go index ef97cfba..a76f880c 100644 --- a/pkg/apis/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha2/zz_generated.deepcopy.go @@ -486,31 +486,6 @@ func (in *LoadBalancingWeighted) DeepCopy() *LoadBalancingWeighted { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ManagedHost) DeepCopyInto(out *ManagedHost) { - *out = *in - if in.ManagedZone != nil { - in, out := &in.ManagedZone, &out.ManagedZone - *out = new(ManagedZone) - (*in).DeepCopyInto(*out) - } - if in.DnsRecord != nil { - in, out := &in.DnsRecord, &out.DnsRecord - *out = new(DNSRecord) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedHost. -func (in *ManagedHost) DeepCopy() *ManagedHost { - if in == nil { - return nil - } - out := new(ManagedHost) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ManagedZone) DeepCopyInto(out *ManagedZone) { *out = *in @@ -588,6 +563,16 @@ func (in *ManagedZoneReference) DeepCopy() *ManagedZoneReference { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ManagedZoneSpec) DeepCopyInto(out *ManagedZoneSpec) { *out = *in + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } if in.ParentManagedZone != nil { in, out := &in.ParentManagedZone, &out.ParentManagedZone *out = new(ManagedZoneReference) diff --git a/pkg/controllers/managedzone/managedzone_controller.go b/pkg/controllers/managedzone/managedzone_controller.go index 198fd722..b7093f78 100644 --- a/pkg/controllers/managedzone/managedzone_controller.go +++ b/pkg/controllers/managedzone/managedzone_controller.go @@ -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 } diff --git a/pkg/dns/aws/dns.go b/pkg/dns/aws/dns.go index 53155792..1b410447 100644 --- a/pkg/dns/aws/dns.go +++ b/pkg/dns/aws/dns.go @@ -124,7 +124,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, @@ -135,8 +135,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 } @@ -152,15 +152,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 @@ -176,7 +179,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), }, }) @@ -407,3 +410,7 @@ func removeTrailingDot(hostname string) string { return strings.TrimSuffix(hostname, ".") } + +func removeHostedZoneIDPrefix(id string) string { + return strings.TrimPrefix(id, "/hostedzone/") +} diff --git a/pkg/dns/dns.go b/pkg/dns/dns.go index bcc54173..f5b94ed6 100644 --- a/pkg/dns/dns.go +++ b/pkg/dns/dns.go @@ -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 } diff --git a/pkg/dns/google/google.go b/pkg/dns/google/google.go index c23c9e52..6c423dc9 100644 --- a/pkg/dns/google/google.go +++ b/pkg/dns/google/google.go @@ -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 } @@ -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 { diff --git a/test/policy_integration/dnspolicy_controller_health_checks_test.go b/test/policy_integration/dnspolicy_controller_health_checks_test.go index 06f3dc2e..8de010a4 100644 --- a/test/policy_integration/dnspolicy_controller_health_checks_test.go +++ b/test/policy_integration/dnspolicy_controller_health_checks_test.go @@ -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). @@ -166,7 +172,7 @@ 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), }), @@ -174,7 +180,7 @@ var _ = Describe("DNSPolicy Health Checks", 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": HaveLen(6), }), diff --git a/test/policy_integration/dnspolicy_controller_multi_cluster_test.go b/test/policy_integration/dnspolicy_controller_multi_cluster_test.go index d0282468..731511f3 100644 --- a/test/policy_integration/dnspolicy_controller_multi_cluster_test.go +++ b/test/policy_integration/dnspolicy_controller_multi_cluster_test.go @@ -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). @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/test/policy_integration/dnspolicy_controller_single_cluster_test.go b/test/policy_integration/dnspolicy_controller_single_cluster_test.go index 7ecbae37..c137269d 100644 --- a/test/policy_integration/dnspolicy_controller_single_cluster_test.go +++ b/test/policy_integration/dnspolicy_controller_single_cluster_test.go @@ -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). @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/test/policy_integration/dnspolicy_controller_test.go b/test/policy_integration/dnspolicy_controller_test.go index 9adb9783..f5c31d6a 100644 --- a/test/policy_integration/dnspolicy_controller_test.go +++ b/test/policy_integration/dnspolicy_controller_test.go @@ -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). diff --git a/test/policy_integration/managedzone_controller_test.go b/test/policy_integration/managedzone_controller_test.go index ee7ce4b1..343a3651 100644 --- a/test/policy_integration/managedzone_controller_test.go +++ b/test/policy_integration/managedzone_controller_test.go @@ -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, @@ -87,7 +87,7 @@ var _ = Describe("ManagedZoneReconciler", func() { Namespace: defaultNS, }, Spec: v1alpha2.ManagedZoneSpec{ - ID: "invalid_domain", + ID: testutil.Pointer("invalid_domain"), DomainName: "invalid_domain", }, } diff --git a/test/util/test_dnspolicy_types.go b/test/util/test_dnspolicy_types.go index 4d80b35f..03da37ec 100644 --- a/test/util/test_dnspolicy_types.go +++ b/test/util/test_dnspolicy_types.go @@ -139,28 +139,20 @@ type ManagedZoneBuilder struct { *v1alpha2.ManagedZone } -func NewManagedZoneBuilder(name, ns, domainName string) *ManagedZoneBuilder { +func NewManagedZoneBuilder(name, ns string) *ManagedZoneBuilder { return &ManagedZoneBuilder{ &v1alpha2.ManagedZone{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: ns, }, - Spec: v1alpha2.ManagedZoneSpec{ - ID: "1234", - DomainName: domainName, - Description: domainName, - ProviderRef: v1alpha2.ProviderRef{ - Name: "secretname", - Kind: "Secret", - }, - }, + Spec: v1alpha2.ManagedZoneSpec{}, }, } } func (t *ManagedZoneBuilder) WithID(id string) *ManagedZoneBuilder { - t.Spec.ID = id + t.Spec.ID = &id return t } @@ -170,7 +162,7 @@ func (t *ManagedZoneBuilder) WithDomainName(domainName string) *ManagedZoneBuild } func (t *ManagedZoneBuilder) WithDescription(description string) *ManagedZoneBuilder { - t.Spec.Description = description + t.Spec.Description = &description return t }