feat(source/fake): extend fake source to emit all supported record types#6308
feat(source/fake): extend fake source to emit all supported record types#6308ivankatliarchuk wants to merge 9 commits intokubernetes-sigs:masterfrom
Conversation
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Pull Request Test Coverage Report for Build 23734458438Details
💛 - Coveralls |
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
|
Hi @frittentheke . Have a look, I'm not sure where all records supported, but yeah, make sense to use fake source as some sort of contract/issue tracker. |
Awesome thank you @ivankatliarchuk . I'll push my code as draft later for you to take ans maybe make use of .... Edit: I see you already have lots of code including the use of managed-record-types which I added as well. Cool 😎 |
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
|
Lgtm is enough. We could incorporate other code changes in follow up PRs ;-) |
There was a problem hiding this comment.
LGTM @ivankatliarchuk
... just dropped a few thoughts on making the test-data even more "valuable" or "challenging" for the consumer.
| case endpoint.RecordTypePTR: | ||
| name := generateDNSName(4, sc.dnsName) | ||
| var err error | ||
| ep, err = endpoint.NewPTREndpoint(generateIPv4Address(), endpoint.TTL(0), name) |
There was a problem hiding this comment.
Maybe randomly generate IPv6 PTR records (ip6.arpa) as well?
There was a problem hiding this comment.
I'm not sure. We going to have a flag for that #6232. But in reality it should be done with DNSEndpoint
| case endpoint.RecordTypeSRV: | ||
| // SRV target format: "priority weight port target." (target must end with a dot per RFC 2782) | ||
| name := generateDNSName(4, sc.dnsName) | ||
| ep = endpoint.NewEndpoint(fmt.Sprintf("_sip._udp.%s", sc.dnsName), endpoint.RecordTypeSRV, fmt.Sprintf("10 20 5060 %s.", name)) |
There was a problem hiding this comment.
Since SRV records are quite complex, maybe a bit more variety makes sense?
Just to ensure that
I have something like
case endpoint.RecordTypeSRV:
// SRV syntax:
// SPEC: _service._proto.name. ttl IN SRV priority weight port target.
// EXAMPLE: _sip._tcp.example.com. 86400 IN SRV 0 5 5060 sipserver.example.com.
var priority int = rand.Intn(100) + 1
var weight int = rand.Intn(100) + 1
var target string = generateDNSName(6, sc.dnsName) + "."
var service string = "_" + generateDNSName(5, "")
var protocol []string = []string{"_tcp", "_udp"}
serviceName = fmt.Sprintf("%s%s ", service, protocol[rand.Intn(2)])
address = fmt.Sprintf("%d %d %s", priority, weight, target)
in mind.
There was a problem hiding this comment.
Not sure. Better to use DNSEndpoint, fake source is to verity handling of these types.
| } | ||
|
|
||
| // Endpoints returns endpoint objects. | ||
| // Endpoints returns one endpoint per supported DNS record type. |
There was a problem hiding this comment.
Maybe sticking with creating 10 each makes sense?
Since Fake is used for testing webhooks or other integrations have a "bigger" set might be helpful to cover more ground?
There was a problem hiding this comment.
I've change it sligthtly. Updated docs, high level - user could have FQDN template to increase number of endpoints
| ep.WithLabel(endpoint.ResourceLabelKey, fmt.Sprintf("%s/%s/%s", types.Fake, pod.Namespace, ep.DNSName)) | ||
| ep.WithRefObject(events.NewObjectReference(&pod, types.Fake)) | ||
| } | ||
| return ep, nil |
There was a problem hiding this comment.
Maybe add some (debug) logging the Record generated?
| var ep *endpoint.Endpoint | ||
|
|
||
| switch recordType { | ||
| case endpoint.RecordTypeA: |
There was a problem hiding this comment.
Maybe adding a record containing more than one IP address makes sense?
| switch recordType { | ||
| case endpoint.RecordTypeA: | ||
| ep = endpoint.NewEndpoint(generateDNSName(4, sc.dnsName), endpoint.RecordTypeA, generateIPv4Address()) | ||
| case endpoint.RecordTypeAAAA: |
There was a problem hiding this comment.
Same as with IPv4 having a record contain more than one address might make for sensible test data?
I'm a bit on the edge to overload Fake source. Updated docs to better frame the fake source's scope. The fake source is a smoke-test tool - it answers "does the provider connect and accept records?" without needing a cluster. It is not a substitute for a contract test. For predictable, stable integration test fixtures (specific record types, exact counts, known values), the right approach is DNSEndpoint resources with --source=crd, where the user has full control. A few things worth noting:
Documentation updated accordingly. |
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
|
Thanks @ivankatliarchuk ! You are right, this PR is big enough, but it's also more than a leap forward. In the end it's not about creating and maintaining all possible values for all sorts of records and to validate a consumer does accept them. But I thank you again for picking up on the idea of providing just "a little" more test data for webhook authors to ensure their part works and to allow for some lightweight CI testing. |
|
We don't hold any sessions where we discuss things ;-). I've added a doc, to clarify them |
What does it do ?
Motivation
Fixes #6042
Webhook providers (3rd-party DNS backends) had no way to test all supported record types without a live Kubernetes cluster. The fake source only emitted A records, making it impossible to verify AAAA, SRV, MX, NAPTR, etc. handling. Additionally, Kubernetes events were silently skipped for fake endpoints because Regarding was never populated (UID gated), and the domain was hardcoded to example.com.
More