-
Notifications
You must be signed in to change notification settings - Fork 218
OCPBUGS-31521: Don't publish duplicate DNS records #1229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,12 @@ import ( | |
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| iov1 "github.com/openshift/api/operatoringress/v1" | ||
| "github.com/openshift/cluster-ingress-operator/pkg/dns" | ||
| testutil "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/test/util" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/cache/informertest" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
|
|
@@ -117,6 +120,7 @@ func Test_publishRecordToZones(t *testing.T) { | |
| r := &reconciler{ | ||
| // TODO To write a fake provider that can return errors and add more test cases. | ||
| dnsProvider: &dns.FakeProvider{}, | ||
| cache: buildFakeCache(t), | ||
| } | ||
|
|
||
| _, actual := r.publishRecordToZones(test.zones, record) | ||
|
|
@@ -128,9 +132,9 @@ func Test_publishRecordToZones(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // TestPublishRecordToZonesMergesStatus verifies that publishRecordToZones | ||
| // Test_publishRecordToZonesMergesStatus verifies that publishRecordToZones | ||
| // correctly merges status updates. | ||
| func TestPublishRecordToZonesMergesStatus(t *testing.T) { | ||
| func Test_publishRecordToZonesMergesStatus(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably I am also missing something here, but is there a new test case that will check if the condition is set? |
||
| testCases := []struct { | ||
| description string | ||
| oldZoneStatuses []iov1.DNSZoneStatus | ||
|
|
@@ -215,7 +219,10 @@ func TestPublishRecordToZonesMergesStatus(t *testing.T) { | |
| }, | ||
| Status: iov1.DNSRecordStatus{Zones: tc.oldZoneStatuses}, | ||
| } | ||
| r := &reconciler{dnsProvider: &dns.FakeProvider{}} | ||
| r := &reconciler{ | ||
| dnsProvider: &dns.FakeProvider{}, | ||
| cache: buildFakeCache(t), | ||
| } | ||
| zone := []configv1.DNSZone{{ID: "zone2"}} | ||
| oldStatuses := record.Status.DeepCopy().Zones | ||
| _, newStatuses := r.publishRecordToZones(zone, record) | ||
|
|
@@ -840,3 +847,28 @@ func Test_customCABundle(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| // buildFakeCache returns a fake cache, with the necessary schema and index function(s) to mimic the parts of the cache | ||
| // that the dns controller interacts with. | ||
| func buildFakeCache(t *testing.T) *testutil.FakeCache { | ||
rfredette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| t.Helper() | ||
| scheme := runtime.NewScheme() | ||
| iov1.AddToScheme(scheme) | ||
| fakeClient := fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithIndex(&iov1.DNSRecord{}, dnsRecordIndexFieldName, func(o client.Object) []string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (no need to fix now!): do we care about making this indexer function some sort of utils/specific function that can be used both on the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean a util function that the controller logic and test logic would share? That does make sense, though I do caution against re-using controller logic in tests if doing so could mask a defect in the controller logic.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the idea was to make some util/shared function, but also I see your concerns here, so makes sense also to not share and in case something changes on the main reconciliation logic, the test that has a different cache logic will catch the regression.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent here is to use the same index function that was added in lines 117-122. Since the fake cache doesn't go through all the setup steps that the actual one does, it needed to be added manually. In this case, having the logic match what's used in the actual controller probably is the way to go. |
||
| dnsRecord := o.(*iov1.DNSRecord) | ||
| return []string{dnsRecord.Spec.DNSName} | ||
| }). | ||
| Build() | ||
| cl := &testutil.FakeClientRecorder{ | ||
| Client: fakeClient, | ||
| T: t, | ||
| Added: []client.Object{}, | ||
| Updated: []client.Object{}, | ||
| Deleted: []client.Object{}, | ||
| } | ||
| informer := informertest.FakeInformers{Scheme: scheme} | ||
| cache := testutil.FakeCache{Informers: &informer, Reader: cl} | ||
| return &cache | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for safety (sorry for realizing this just now): DeletionTimestamp is a nullable field / a pointer (https://github.com/kubernetes/apimachinery/blob/d74026bbe3beeff64c3dc7259a29be7708aa834f/pkg/apis/meta/v1/types.go#L209) and as so, I would recommend checking if it is null, and then checking if it is zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
IsZeromethod has an nil check on its receiver, so I think the caller can omit the nil check?cluster-ingress-operator/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/time.go
Lines 60 to 63 in 4822baa
I would be happy with a unit test case in lieu of a nil check.