Skip to content

Commit

Permalink
fix removal of domain when no dns entrypoint have been created
Browse files Browse the repository at this point in the history
  • Loading branch information
simonoff committed Sep 12, 2024
1 parent 2c1ec97 commit 52a92af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions internal/controller/domain/domain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ref "k8s.io/client-go/tools/reference"
Expand Down Expand Up @@ -211,15 +210,14 @@ func (r *DomainReconciler) createExternalDNSEntity(ctx context.Context, mailgunD
Endpoints: []*endpoint.Endpoint{},
},
}
dnsEntrypoint.SetGroupVersionKind(schema.GroupVersionKind{
Group: "externaldns.k8s.io",
Version: "v1alpha1",
Kind: "DNSEndpoint",
})

records := slices.Concat(mailgunDomain.Status.ReceivingDnsRecords, mailgunDomain.Status.SendingDnsRecords)

for _, record := range records {
// skip the already valid records. Looks like they already have been created on DNS so no need to create again
if record.Valid == "valid" {
continue
}
dnsName := record.Name
target := record.Value
// sending record
Expand Down Expand Up @@ -282,7 +280,8 @@ func (r *DomainReconciler) deleteDomain(ctx context.Context, domain *domainv1.Do
"Deleting domain %s from mailgun", domainName,
)

if domain.Spec.ExternalDNS != nil && *domain.Spec.ExternalDNS {
// if we have a linked dns entrypoint then we should to delete it.
if len(domain.Status.DnsEntrypoint.Name) > 0 {
// lets get the dns enpoint
dnsEndpoint := &endpoint.DNSEndpoint{}
dnsEndpointLookup := types.NamespacedName{
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/mailgun_mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (m *MailgunMockServer) newMGDnsRecordsFor(domainName string, sendingRecords
},
{
RecordType: "CNAME",
Valid: "valid",
Valid: dnsValid,
Name: "email." + domainName,
Value: "mailgun.org",
},
Expand Down

0 comments on commit 52a92af

Please sign in to comment.