-
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.
dnspolicy section name support (#961)
dnspolicy section name support * fix dsnpolicy: Don't change owner ref on update DNSRecords are currently owned by the DNSPolicy that created them. We can't just update the ownership on policy change since the new policy may not be compatible with the current DNSRecord, instead we must re-create the DNSRecord resource. This is not ideal, issue to look into changing this Kuadrant/dns-operator#287 * Add canUpdateDNSRecord function 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 <[email protected]>
- Loading branch information
Showing
11 changed files
with
388 additions
and
22 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.