Skip to content

Commit

Permalink
Rework DNSEndpoint observation for Kubernetes change (#26)
Browse files Browse the repository at this point in the history
Started getting this error at some point:

  WARNING Failed to observe DNSEndpoint CRD: Kubernetes returned HTTP 400 BadRequest: the name of the object (my-dns-endpoints based on URL) was undeterminable: name must be provided
  • Loading branch information
danopia authored May 2, 2024
1 parent 1e6fb04 commit 91a7aa4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/sources/crd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export class CrdSource implements DnsSource {
async ListRecords() {
const endpoints = new Array<SourceRecord>();

for await (const node of this.lister.getFreshList()) {
const {name, namespace, generation} = node.metadata ?? {};
if (!name || !namespace || !node.spec?.endpoints) continue;
for await (const resource of this.lister.getFreshList()) {
const {name, namespace, generation} = resource.metadata ?? {};
if (!name || !namespace || !resource.spec?.endpoints) continue;

const annotations = node.metadata?.annotations ?? {};
const annotations = resource.metadata?.annotations ?? {};
const resourceKey = `crd/${namespace}/${name}`;

for (const endp of node.spec.endpoints) {
for (const endp of resource.spec.endpoints) {
if (!endp.dnsName || !endp.recordType || !endp.targets?.length) continue;

const endpointAnnotations = { ...annotations };
Expand Down Expand Up @@ -77,13 +77,12 @@ export class CrdSource implements DnsSource {
}

// Hook a finalizer to mark in the status subresource that we saw the resource
if (generation && node.status?.observedGeneration !== generation) {
if (generation && resource.status?.observedGeneration !== generation) {
resource.status ??= {};
resource.status.observedGeneration = generation;
this.#finalizers.set(resourceKey, () => this.crdApi
.namespace(namespace)
.replaceDNSEndpointStatus(name, {
status: {
observedGeneration: generation,
}})
.replaceDNSEndpointStatus(name, resource)
.catch(err => log.warning(`Failed to observe DNSEndpoint CRD: ${err.message}`)));
}

Expand Down

0 comments on commit 91a7aa4

Please sign in to comment.