-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returns true if an existing record can knowingly be updated to a desired state based on the differences of the specs. Current known reasons for not being able to update are: * RootHost updates * Endpoint record type changes (A -> CNAME etc..) In both these cases, and any others that may be added to `canUpdateDNSRecord` the current record should be deleted before doing a create of the desired record. Signed-off-by: Michael Nairn <mnairn@redhat.com>
- Loading branch information
Showing
2 changed files
with
165 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
externaldns "sigs.k8s.io/external-dns/endpoint" | ||
|
||
kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1" | ||
) | ||
|
||
func Test_canUpdateDNSRecord(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
current *kuadrantdnsv1alpha1.DNSRecord | ||
desired *kuadrantdnsv1alpha1.DNSRecord | ||
want bool | ||
}{ | ||
{ | ||
name: "different root hosts", | ||
current: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
RootHost: "foo.example.com", | ||
}, | ||
}, | ||
desired: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
RootHost: "bar.example.com", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "same root hosts", | ||
current: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
RootHost: "foo.example.com", | ||
}, | ||
}, | ||
desired: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
RootHost: "foo.example.com", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "different record type same dnsnames", | ||
current: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "A", | ||
}, | ||
}, | ||
}, | ||
}, | ||
desired: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "CNAME", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "same record type same dnsnames", | ||
current: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "A", | ||
}, | ||
}, | ||
}, | ||
}, | ||
desired: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "A", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "multiple endpoints", | ||
current: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "A", | ||
}, | ||
{ | ||
DNSName: "baz.example.com", | ||
RecordType: "CNAME", | ||
}, | ||
}, | ||
}, | ||
}, | ||
desired: &kuadrantdnsv1alpha1.DNSRecord{ | ||
Spec: kuadrantdnsv1alpha1.DNSRecordSpec{ | ||
Endpoints: []*externaldns.Endpoint{ | ||
{ | ||
DNSName: "foo.example.com", | ||
RecordType: "A", | ||
}, | ||
{ | ||
DNSName: "bar.example.com", | ||
RecordType: "CNAME", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := canUpdateDNSRecord(context.Background(), tt.current, tt.desired); got != tt.want { | ||
t.Errorf("canUpdateDNSRecord() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |