From 91a7aa455b9e3527d6361ed2dbbf730d6289db3e Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Thu, 2 May 2024 14:47:02 +0200 Subject: [PATCH] Rework DNSEndpoint observation for Kubernetes change (#26) 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 --- src/sources/crd.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/sources/crd.ts b/src/sources/crd.ts index 489f8ca..bc5acbf 100644 --- a/src/sources/crd.ts +++ b/src/sources/crd.ts @@ -29,14 +29,14 @@ export class CrdSource implements DnsSource { async ListRecords() { const endpoints = new Array(); - 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 }; @@ -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}`))); }