Skip to content

Autodelegate - #48

Open
azgabur wants to merge 7 commits into
Kuadrant:mainfrom
azgabur:autodelegate
Open

Autodelegate#48
azgabur wants to merge 7 commits into
Kuadrant:mainfrom
azgabur:autodelegate

Conversation

@azgabur

@azgabur azgabur commented Sep 23, 2025

Copy link
Copy Markdown
Member

Closes #43

Reverts #39 due to problems described in #39 (comment)
The cloud problem needs to be solved different way #49

Changes watch namespace to empty string to not have hardcoded "kuadrant" so now coredns will watch all namespaces

Added need for secrets in tools-instances due to autodelegate script needing AWS IAM user

Added autodelegation script which will add .Values.tools.coredns.zones to AWS

coredns-config secret is created in tools namespace which contains deployed zone, useful for testsuite loading

Next work before merge: Kuadrant/testsuite-pipelines#130

Summary by CodeRabbit

Release Notes

  • New Features

    • CoreDNS is now a top-level, first-class component with dedicated configuration options.
    • Added automatic DNS zone delegation support with scheduled post-install and pre-delete operations.
    • Consolidated TCP and UDP DNS services into a single unified service endpoint.
    • Added dynamic zone configuration for more flexible DNS management.
  • Refactor

    • CoreDNS deployment changed from DaemonSet to single-replica Deployment for consistent behaviour across clusters.

Comment thread charts/tools-instances/templates/coredns/autodelegate/00-rbac.yaml Outdated
Comment thread charts/tools-instances/templates/coredns/autodelegate/01-configMap-script.yaml Outdated
Comment thread charts/tools-instances/templates/coredns/autodelegate/01-configMap-script.yaml Outdated
@azgabur
azgabur force-pushed the autodelegate branch 2 times, most recently from 3e1bf44 to 0bc8aff Compare October 3, 2025 10:25
@azgabur

azgabur commented Dec 8, 2025

Copy link
Copy Markdown
Member Author

Instead of using aws cli with a horrible way to append records to record sets, rather use https://github.com/barnybug/cli53
(still need to check if it works)

This reverts commit b579375.

Signed-off-by: Alex Zgabur <azgabur@redhat.com>
Signed-off-by: Alex Zgabur <azgabur@redhat.com>
@azgabur

azgabur commented Feb 9, 2026

Copy link
Copy Markdown
Member Author

Instead of using aws cli with a horrible way to append records to record sets, rather use https://github.com/barnybug/cli53 (still need to check if it works)

The tool was not that intuitive as I first anticipated, it was done via aws-cli (thanks claude)

@azgabur
azgabur requested review from averevki and trepel and removed request for trepel February 9, 2026 21:14

@averevki averevki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! I would wait this chart integration into the pipelines to try it out myself. Or I can try it out now, if you can show me how it would work locally if I want to autodelegate 2 primary clusters. Would it be enough to just set correct values for coredns tools chart for each cluster, and just run it on both primaries?

Comment thread charts/tools-instances/templates/coredns/autodelegate/02-create-job.yaml Outdated
Comment on lines +4 to +5
name: coredns-config
namespace: {{ .Values.tools.namespace }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this secret created in the tools namespace, would it require a copy between the namespaces from the testsuite?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tools charts I do not have access to value of "kuadrant" namespace. I could hardcode it, but this secret is just for reference which zones were deployed. The same information could be found in Corefile.

I imagine testsuite reading this secret and creating appropriate dns provider secret in "kuadrant" namespace at runtime

Do you think having a task in deploy pipeline which will create default dns provider secret for coredns is wanted?

@azgabur

azgabur commented Feb 10, 2026

Copy link
Copy Markdown
Member Author

Looks very good! I would wait this chart integration into the pipelines to try it out myself. Or I can try it out now, if you can show me how it would work locally if I want to autodelegate 2 primary clusters. Would it be enough to just set correct values for coredns tools chart for each cluster, and just run it on both primaries?

Yes exactly, in tools-values.yaml you choose zones you wish to deploy and autodelegate and it will handle multiple clusters having the same zone, even when deleting so you can re-create one cluster and the other cluster should not be affected.

Addition to pipelines is coming 👍

Signed-off-by: Alex Zgabur <azgabur@redhat.com>
averevki
averevki previously approved these changes Feb 16, 2026
azgabur added 4 commits April 21, 2026 12:19
Signed-off-by: Alex Zgabur <azgabur@redhat.com>
Signed-off-by: Alex Zgabur <azgabur@redhat.com>
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request refactors CoreDNS configuration from a nested tools.coredns structure to a top-level coredns component with enhanced capabilities. It introduces autodelegation automation via Kubernetes Jobs that publish DNS NS and A records to AWS Route53, transitions CoreDNS from DaemonSet to single-replica Deployment, consolidates TCP/UDP Services into one, and supports dynamic zone management.

Changes

Cohort / File(s) Summary
Documentation & Configuration
README.md, values-tools.yaml
Added CoreDNS to tools list; removed nested tools.coredns configuration block.
Values & Manifests
values.yaml, example-additionalManifests.yaml
Introduced top-level coredns configuration with enable/namespace/metrics/zones/autoDelegate/image settings; added example AWS credentials secret for autodelegation.
Core Templates
charts/kuadrant-instances/templates/coredns/00-namespace.yaml, 00-rbac.yaml, 01-deployment.yaml
Added namespace template; updated RBAC and deployment to reference .Values.coredns.* instead of .Values.tools.coredns.*; changed workload from DaemonSet to single-replica Deployment, removed master-node tolerations.
Service & Monitoring
charts/kuadrant-instances/templates/coredns/03-service.yaml, 04-corefile.yaml, 05-serviceMonitor.yaml, 06-remoteServiceAccount.yaml
Consolidated separate TCP/UDP services into unified coredns LoadBalancer Service; removed NLB annotation; updated ConfigMap to support dynamic zone configuration via .Values.coredns.zones; updated all conditionals and namespaces to use new values paths.
Autodelegation RBAC
charts/kuadrant-instances/templates/coredns/autodelegate/00-rbac.yaml
New RBAC template (ServiceAccount, Role, RoleBinding) for post-install autodelegation tasks with permissions to read/list services and manage secrets.
Autodelegation Scripts & Jobs
charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml, 02-create-job.yaml, 04-delete-job.yaml
New ConfigMap with bash scripts for Route53 NS/A record management; post-install Job waits for CoreDNS LoadBalancer IP and publishes NS records; pre-delete Job cleans up delegated records.
Autodelegation Configuration
charts/kuadrant-instances/templates/coredns/autodelegate/05-coredns-config-secret.yaml
New Secret template provisioning ZONES annotation and stringData for autodelegation scripts.
Installation Scripts
install.sh, tools-install.sh
Updated to pass --values additionalManifests.yaml to Helm install commands for tools operators/instances.

Sequence Diagram(s)

sequenceDiagram
    actor Admin
    participant K8s as Kubernetes Cluster
    participant DNS as CoreDNS Service
    participant AWS as AWS Route53
    participant Job as Post-Install Job

    Admin->>K8s: Deploy Helm chart with autoDelegate=true
    K8s->>K8s: Create ConfigMap (create.sh, delete.sh)
    K8s->>K8s: Create ServiceAccount & RBAC
    K8s->>K8s: Create CoreDNS Deployment
    K8s->>Job: Trigger post-install Job
    
    Job->>DNS: Poll: GET coredns LoadBalancer IP/hostname
    loop Until LB Ready
        DNS-->>Job: Pending (no IP)
        Job->>Job: Wait
    end
    DNS-->>Job: IP/hostname available
    
    loop For each zone in config
        Job->>AWS: GET current NS records for zone
        AWS-->>Job: Existing NS record set
        Job->>Job: Merge/create new NS entry
        Job->>AWS: UPSERT NS record batch
        AWS-->>Job: Change ID
        Job->>Job: Wait for propagation
        Job->>AWS: Create A record (nameserver.zone → IP)
        AWS-->>Job: Success
    end
    
    Job->>K8s: Complete
    Note over DNS,AWS: CoreDNS now accessible via delegated domain
Loading
sequenceDiagram
    actor Admin
    participant K8s as Kubernetes Cluster
    participant Job as Pre-Delete Job
    participant AWS as AWS Route53

    Admin->>K8s: Delete Helm release
    K8s->>Job: Trigger pre-delete Job

    loop For each zone in config
        Job->>AWS: GET current NS records for zone
        AWS-->>Job: Existing NS record set
        Job->>Job: Filter out delegated nameserver
        
        alt Remaining NS records exist
            Job->>AWS: UPSERT (remaining NS values)
            AWS-->>Job: Success
        else No NS records remain
            Job->>AWS: DELETE NS record
            AWS-->>Job: Success
        end
        
        Job->>AWS: DELETE A record (nameserver.zone)
        AWS-->>Job: Success
    end
    
    Job->>K8s: Complete
    K8s->>K8s: Proceed with release deletion
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Poem

🐰 Hoppy whiskers twitch with glee,
CoreDNS hops from tools to free,
Zones now dance in dynamic rows,
AWS routes where delegation flows!
From DaemonSet to Deployment neat,
Autodelegation makes it complete! 🌐✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive All changes are scoped to CoreDNS configuration refactoring and autodelegate implementation. However, the restructuring of CoreDNS from tools.coredns to standalone coredns configuration extends beyond issue #43's narrowly-defined job requirement. Clarify whether the architectural shift of CoreDNS from tools.coredns to top-level coredns values was explicitly planned or a supporting change; document the rationale in the commit message or PR description.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Autodelegate' directly describes the main feature being introduced: automated delegation of DNS records, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #43: creates a Job that publishes NS and A records from a secret, waits for CoreDNS service readiness, and handles multiple zones with proper deletion/recreation support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
charts/kuadrant-instances/templates/coredns/03-service.yaml (1)

12-21: ⚠️ Potential issue | 🟠 Major

Mixed TCP/UDP on a single LoadBalancer Service requires cloud-provider support.

Consolidating UDP/53 and TCP/53 into one LoadBalancer Service depends on the underlying cloud LB implementation:

  • AWS in-tree CLB (the default without any service.beta.kubernetes.io/aws-load-balancer-* annotation) does not support mixed protocols. The Kubernetes AWS cloud-controller explicitly validates and rejects mixed-protocol Services. To use mixed protocols on EKS, you must switch to AWS Load Balancer Controller (which provisions NLBs with mixed-protocol support) via configuration.
  • GCP LoadBalancer does not support mixed protocols natively. Whilst the MixedProtocolLBService feature gate reached GA in Kubernetes 1.26, the GCP cloud-provider does not provision mixed-protocol support. Full support requires GKE 1.34.1-gke.2190000 or later with the specific loadBalancerClass: networking.gke.io/l4-regional-external. Earlier GKE versions may silently fail or provide unreliable provisioning.

Document the minimum Kubernetes/managed-service versions required for mixed-protocol LoadBalancer Services in the chart README, and consider adding an optional .Values.coredns.service.annotations so users can configure cloud-provider-specific settings (e.g., AWS NLB) without forking the chart.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kuadrant-instances/templates/coredns/03-service.yaml` around lines 12
- 21, The Service currently exposes both UDP and TCP on port 53 under a single
Service (ports: "udp-53" and "tcp-53" with type: LoadBalancer), which requires
cloud-provider support; update the chart by (1) documenting required
Kubernetes/managed-cluster versions and provider-specific notes in the chart
README (explain AWS in-tree vs ALB/NLB, GKE version/loadBalancerClass
requirements and any feature gates), and (2) add an optional
.Values.coredns.service.annotations map and merge it into the Service
metadata.annotations in the coredns template so users can set provider-specific
annotations (e.g., AWS NLB annotations or GKE loadBalancerClass) or choose to
split protocols via separate Services if their provider does not support
mixed-protocol LBs.
🧹 Nitpick comments (3)
charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml (1)

17-17: Avoid the :latest image tag for hook Jobs.

Using quay.io/kuadrant/testsuite-pipelines-tools:latest makes the pre-delete cleanup non-reproducible and risks sudden breakage if the upstream image changes incompatibly. Consider pinning to a digest or explicit tag, ideally exposed through a value (e.g. .Values.coredns.autoDelegate.image) so it can be overridden. Same concern applies to 02-create-job.yaml line 17.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml`
at line 17, Replace the hardcoded
quay.io/kuadrant/testsuite-pipelines-tools:latest image in the auto-delegate
hook Jobs with a configurable, pinned image reference: add a new chart value
(e.g. .Values.coredns.autoDelegate.image) and use that value in both templates
(04-delete-job.yaml and 02-create-job.yaml) so callers can specify a tagged or
digest-pinned image (sha256) instead of :latest; update the templates to use the
value and consider adding a corresponding
.Values.coredns.autoDelegate.imagePullPolicy to keep behavior explicit.
example-additionalManifests.yaml (1)

132-142: Example uses stringData while the other example secrets use data.

Minor consistency nit: every other secret in this example file uses data: with placeholder values, whereas this new coredns-autodelegate secret uses stringData:. Both are valid, but mixing styles in the same example can confuse users copying the template. Consider aligning with the rest of the file (or converting the others if stringData is the preferred style going forward).

Also worth noting for users: the secret only contains AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/ZONE_ID — no AWS_REGION. That is correct for Route53 (a global service), but a short comment here would spare users from wondering whether region needs to be added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@example-additionalManifests.yaml` around lines 132 - 142, The
coredns-autodelegate Secret in toolsManifests uses stringData while other
example Secrets use data; change the coredns-autodelegate entry to use data with
base64-placeholder values (or convert the other Secrets to stringData if you
prefer that style) so examples are consistent, and add a short inline comment
near the coredns-autodelegate Secret noting that AWS_REGION is intentionally
omitted for Route53 (region not required). Reference: toolsManifests ->
coredns-autodelegate, fields stringData/data, and keys AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY, ZONE_ID.
charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml (1)

13-18: Shell hardening suggestions.

A few small robustness tweaks that would benefit both scripts:

  • set -xe echoes every command, including the aws invocations — fine for debugging but any secret substitution into args (not the case today, but easy to introduce) would end up in Job logs. Consider set -eo pipefail and leaving -x off by default (toggle via an env var).
  • set -e will abort on the first failing zone in the range, leaving subsequent zones unprocessed. For the delete path in particular, you may want to continue-on-error per zone and exit non-zero at the end, so one broken zone doesn't block cleanup of the rest.
  • The kubectl wait ... || exit 1 on line 16 is redundant under set -e.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml`
around lines 13 - 18, Switch strictness: replace unsafe "set -xe" with "set -eo
pipefail" and add an env-var toggle (e.g., DEBUG or VERBOSE) to enable "-x" only
when debugging; in the script areas referencing NS_NAME, TTL, COREDNS_IP and
COREDNS_HOSTNAME keep the quieter default. Change per-zone error handling in the
deletion range loop so failures for one zone do not abort the whole loop:
capture per-zone exit status, continue processing remaining zones, and after the
loop exit with non-zero if any zone failed. Remove the redundant "|| exit 1" on
the "kubectl wait ... service coredns" invocation (since set -e will handle
failures) and ensure kubectl waits still respect the configured timeout.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@charts/kuadrant-instances/templates/coredns/01-deployment.yaml`:
- Around line 10-14: The RollingUpdate settings allow the single CoreDNS pod to
be taken down (replicas: 1 with rollingUpdate.maxUnavailable: 1); update the
Deployment spec so rollingUpdate.maxUnavailable is 0 and add
rollingUpdate.maxSurge: 1 to maintain availability during updates (or make
replicas configurable for HA), changing the fields under strategy ->
rollingUpdate (maxUnavailable and add maxSurge) and ensure replicas is
documented/configurable rather than fixed at 1.

In `@charts/kuadrant-instances/templates/coredns/06-remoteServiceAccount.yaml`:
- Line 1: The templates are evaluating .Values.tools.enabled as a string,
causing truthy behavior; update either values.yaml to set tools.enabled: false
(boolean, no quotes) or change each template conditional (e.g., the coredns
template's condition using the symbol '{{ if and .Values.coredns.enable
.Values.tools.enabled }}') to an explicit comparison like '{{ if and
.Values.coredns.enable (eq .Values.tools.enabled "true") }}'; apply the chosen
fix consistently across all seven affected templates that reference
.Values.tools.enabled.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/00-rbac.yaml`:
- Around line 22-28: Remove the unused RBAC permission for Kubernetes secrets by
deleting the resources: - secrets block (and its verbs: - get / - create) from
the Role/ClusterRole in the coredns autodelegate RBAC manifest; specifically
remove the rule that lists apiGroups: [""] with resources: ["secrets"] and verbs
including "get" and "create" so the Role/ClusterRole only grants the remaining
necessary permissions (e.g., service-related verbs), preserving YAML structure
and indentation for the surrounding rules.

In
`@charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml`:
- Around line 71-93: The script silently skips cleanup when both COREDNS_IP and
COREDNS_HOSTNAME are empty; update the pre-delete logic in delete.sh (the block
that sets COREDNS_IP/COREDNS_HOSTNAME and computes EXCLUDE_VALUE) to first wait
for the Service LB ingress (e.g., run a kubectl wait for
.status.loadBalancer.ingress with a short timeout against the service in {{
.Values.coredns.namespace }}) and then re-evaluate COREDNS_IP/COREDNS_HOSTNAME;
if after waiting both are still empty, fail fast (exit 1) with a clear error so
deletion does not silently skip cleanup. Ensure references to COREDNS_IP,
COREDNS_HOSTNAME, EXCLUDE_VALUE, NS_NAME and ZONE_ID remain unchanged so the
later A/NS deletion logic can proceed.
- Around line 82-90: The DELETE change-batch currently uses the live Service IP
($COREDNS_IP) which can differ from the value stored in the zone; modify the
block that builds CHANGE_BATCH (where CURRENT_A, TTL, CHANGE_BATCH and the aws
route53 change-resource-record-sets call are used) to extract the actual record
value from CURRENT_A (e.g. the ResourceRecords[0].Value) and use that extracted
IP for the --arg ip in the jq -n payload so the DELETE matches the exact
existing record.
- Around line 108-125: Add a short retry loop around the aws route53
change-resource-record-sets call to handle the TOCTOU race: on error responses
like "InvalidChangeBatch" or other stale-version failures, re-run the
list-resource-record-sets command to refresh CURRENT_RECORDS (or CURRENT_NS),
recompute REMAINING_VALUES/REMAINING_COUNT, rebuild the CHANGE_BATCH (using the
same logic that chooses DELETE vs UPSERT), and retry the aws call up to a small
max attempts with a brief sleep between tries; implement this around both
branches that construct CHANGE_BATCH and call aws route53
change-resource-record-sets so REMAINING_COUNT, CURRENT_RECORDS,
REMAINING_VALUES and CHANGE_BATCH are re-evaluated before each retry.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/02-create-job.yaml`:
- Around line 7-8: Add a Helm hook delete policy so completed post-install Jobs
are removed: update the annotations block in the post-install Job (the template
that creates the post-install-autodelegate Job) to include
"helm.sh/hook-delete-policy": "hook-succeeded" (so successful runs are deleted).
For the pre-delete/autodelegate-cleanup Job referenced in 04-delete-job.yaml,
ensure it keeps "helm.sh/hook-delete-policy": "before-hook-creation" (or omit
deletion on failure) so the Job is retained for debugging.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml`:
- Line 10: The pre-delete Job sets backoffLimit: 10 which can block helm
uninstall on persistent failures; update the Job spec (referencing backoffLimit
and restartPolicy in the pre-delete Job manifest) to reduce backoffLimit to a
lower value (e.g., 3 to match the create job) and add an activeDeadlineSeconds
(e.g., 300) to bound total runtime so uninstall fails fast and surfaces a clear
error instead of retrying for a long time.

In
`@charts/kuadrant-instances/templates/coredns/autodelegate/05-coredns-config-secret.yaml`:
- Around line 1-12: The secret template renders coredns-credentials in namespace
"kuadrant" but is incorrectly gated on .Values.tools.enabled; either remove the
tools gate so the template condition uses only .Values.coredns.enable and
.Values.coredns.autoDelegate, or keep the current condition but add the
annotation "helm.sh/resource-policy": "keep" to metadata.annotations (matching
other kuadrant secrets) so the secret is not removed on upgrades; update the
template around the if statement and metadata.annotations for the Secret named
coredns-credentials accordingly.
- Line 11: The ZONES line applies trimSuffix to the whole joined string causing
only the last zone to lose its trailing dot; update the template to trim the
trailing dot for each element of .Values.coredns.zones before joining.
Specifically, iterate over .Values.coredns.zones (or build a new $cleaned
slice), call trimSuffix "." on each zone value, then join the cleaned slice with
"," and quote the result so ZONES contains consistently trimmed entries
(reference the ZONES line, .Values.coredns.zones, trimSuffix and join).

In `@README.md`:
- Line 39: Update the product name spelling in the README by replacing the
incorrect "Coredns" instance with the canonical "CoreDNS" so all user-facing
documentation uses the standard capitalization; locate the occurrence of the
string "Coredns" in the README and change it to "CoreDNS".

In `@tools-install.sh`:
- Line 8: The script currently forces additional_flags='--values
additionalManifests.yaml' which makes tools-install.sh fail if that file is
missing and can wrongly deploy secrets; change the logic so additional_flags is
empty by default and only set to '--values additionalManifests.yaml' if the file
exists (check [-f additionalManifests.yaml]) or if an opt-in env/CLI flag is
provided, and additionally guard any deployment of toolsManifests secrets (e.g.,
coredns-autodelegate) behind the appropriate feature flag (CoreDNS autodelegate)
or config check before applying them; update all uses of additional_flags in
tools-install.sh to rely on this conditional value.

In `@values.yaml`:
- Line 99: Replace the unpinned CoreDNS image tag "latest" with a specific,
immutable version in values.yaml (update the image field/value for the CoreDNS
chart entry) so the chart uses a fixed tag (e.g., set image to
quay.io/kuadrant/coredns-kuadrant:<semver-or-digest>), and ensure
imagePullPolicy is appropriate (If using a digest or specific tag, change
imagePullPolicy from Always to IfNotPresent or document why Always is required);
also update any README or chart values comments to require updating this tag for
upgrades.

---

Outside diff comments:
In `@charts/kuadrant-instances/templates/coredns/03-service.yaml`:
- Around line 12-21: The Service currently exposes both UDP and TCP on port 53
under a single Service (ports: "udp-53" and "tcp-53" with type: LoadBalancer),
which requires cloud-provider support; update the chart by (1) documenting
required Kubernetes/managed-cluster versions and provider-specific notes in the
chart README (explain AWS in-tree vs ALB/NLB, GKE version/loadBalancerClass
requirements and any feature gates), and (2) add an optional
.Values.coredns.service.annotations map and merge it into the Service
metadata.annotations in the coredns template so users can set provider-specific
annotations (e.g., AWS NLB annotations or GKE loadBalancerClass) or choose to
split protocols via separate Services if their provider does not support
mixed-protocol LBs.

---

Nitpick comments:
In
`@charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml`:
- Around line 13-18: Switch strictness: replace unsafe "set -xe" with "set -eo
pipefail" and add an env-var toggle (e.g., DEBUG or VERBOSE) to enable "-x" only
when debugging; in the script areas referencing NS_NAME, TTL, COREDNS_IP and
COREDNS_HOSTNAME keep the quieter default. Change per-zone error handling in the
deletion range loop so failures for one zone do not abort the whole loop:
capture per-zone exit status, continue processing remaining zones, and after the
loop exit with non-zero if any zone failed. Remove the redundant "|| exit 1" on
the "kubectl wait ... service coredns" invocation (since set -e will handle
failures) and ensure kubectl waits still respect the configured timeout.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml`:
- Line 17: Replace the hardcoded
quay.io/kuadrant/testsuite-pipelines-tools:latest image in the auto-delegate
hook Jobs with a configurable, pinned image reference: add a new chart value
(e.g. .Values.coredns.autoDelegate.image) and use that value in both templates
(04-delete-job.yaml and 02-create-job.yaml) so callers can specify a tagged or
digest-pinned image (sha256) instead of :latest; update the templates to use the
value and consider adding a corresponding
.Values.coredns.autoDelegate.imagePullPolicy to keep behavior explicit.

In `@example-additionalManifests.yaml`:
- Around line 132-142: The coredns-autodelegate Secret in toolsManifests uses
stringData while other example Secrets use data; change the coredns-autodelegate
entry to use data with base64-placeholder values (or convert the other Secrets
to stringData if you prefer that style) so examples are consistent, and add a
short inline comment near the coredns-autodelegate Secret noting that AWS_REGION
is intentionally omitted for Route53 (region not required). Reference:
toolsManifests -> coredns-autodelegate, fields stringData/data, and keys
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, ZONE_ID.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 684177ca-8769-4d80-a3cf-62a8f1723356

📥 Commits

Reviewing files that changed from the base of the PR and between 76441e4 and 1b34daf.

📒 Files selected for processing (18)
  • README.md
  • charts/kuadrant-instances/templates/coredns/00-namespace.yaml
  • charts/kuadrant-instances/templates/coredns/00-rbac.yaml
  • charts/kuadrant-instances/templates/coredns/01-deployment.yaml
  • charts/kuadrant-instances/templates/coredns/03-service.yaml
  • charts/kuadrant-instances/templates/coredns/04-corefile.yaml
  • charts/kuadrant-instances/templates/coredns/05-serviceMonitor.yaml
  • charts/kuadrant-instances/templates/coredns/06-remoteServiceAccount.yaml
  • charts/kuadrant-instances/templates/coredns/autodelegate/00-rbac.yaml
  • charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml
  • charts/kuadrant-instances/templates/coredns/autodelegate/02-create-job.yaml
  • charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml
  • charts/kuadrant-instances/templates/coredns/autodelegate/05-coredns-config-secret.yaml
  • example-additionalManifests.yaml
  • install.sh
  • tools-install.sh
  • values-tools.yaml
  • values.yaml
💤 Files with no reviewable changes (1)
  • values-tools.yaml

Comment thread charts/kuadrant-instances/templates/coredns/01-deployment.yaml
Comment on lines +22 to +28
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- create

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify no kubectl secret operations in the autodelegate scripts
rg -nP --type=yaml -C2 '\bsecret(s)?\b' charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml
rg -nP -C2 'kubectl\s+(get|create|apply).*secret' charts/kuadrant-instances/templates/coredns/autodelegate/

Repository: Kuadrant/helm-charts-olm

Length of output: 1805


🏁 Script executed:

#!/bin/bash
# Attempt to locate and examine the coredns autodelegate scripts
find . -path "*/charts/kuadrant-instances/templates/coredns/autodelegate/*" -type f 2>/dev/null | head -20

Repository: Kuadrant/helm-charts-olm

Length of output: 468


🏁 Script executed:

#!/bin/bash
# Read the ConfigMap script file to see what the create.sh and delete.sh do
cat -n ./charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml

Repository: Kuadrant/helm-charts-olm

Length of output: 6796


🏁 Script executed:

#!/bin/bash
# Check the job definitions to see how they access credentials
cat -n ./charts/kuadrant-instances/templates/coredns/autodelegate/02-create-job.yaml
echo "---"
cat -n ./charts/kuadrant-instances/templates/coredns/autodelegate/04-delete-job.yaml

Repository: Kuadrant/helm-charts-olm

Length of output: 2264


🏁 Script executed:

#!/bin/bash
# Check the secret definition and full RBAC
cat -n ./charts/kuadrant-instances/templates/coredns/autodelegate/05-coredns-config-secret.yaml
echo "---"
cat -n ./charts/kuadrant-instances/templates/coredns/autodelegate/00-rbac.yaml

Repository: Kuadrant/helm-charts-olm

Length of output: 1773


🏁 Script executed:

#!/bin/bash
# Search for where coredns-autodelegate secret is created
rg -r 'coredns-autodelegate' --type=yaml ./charts/kuadrant-instances/templates/coredns/
echo "---"
# Also check if there's any kubectl secret operation in the entire autodelegate directory
rg -i 'kubectl.*secret|secret.*kubectl' --type=yaml ./charts/kuadrant-instances/templates/coredns/autodelegate/

Repository: Kuadrant/helm-charts-olm

Length of output: 71


🏁 Script executed:

#!/bin/bash
# Broader search for coredns-autodelegate in the entire repository
rg 'coredns-autodelegate' ./charts/ --type=yaml
echo "---"
# Also check if any secret creation happens in shell scripts
rg -i 'kubectl.*create.*secret|kubectl.*apply.*secret' ./charts/kuadrant-instances/templates/coredns/ --type=yaml

Repository: Kuadrant/helm-charts-olm

Length of output: 313


🏁 Script executed:

#!/bin/bash
# Check if coredns-autodelegate secret is created by any Job or external process
rg 'coredns-autodelegate' ./charts/ --type=yaml -B5 -A5
echo "---"
# Also check if there are any other references or comments about secret creation
rg -i 'secret.*create|create.*secret' ./charts/kuadrant-instances/templates/coredns/autodelegate/ --type=yaml

Repository: Kuadrant/helm-charts-olm

Length of output: 2478


Remove unused secrets: [get, create] RBAC rule.

The create.sh and delete.sh scripts perform no kubectl secret operations—they only use kubectl get and kubectl wait on services. AWS credentials are injected via envFrom referencing the coredns-autodelegate secret, which is provided externally, not created by the Job. The secrets rule therefore violates the principle of least privilege and should be removed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kuadrant-instances/templates/coredns/autodelegate/00-rbac.yaml` around
lines 22 - 28, Remove the unused RBAC permission for Kubernetes secrets by
deleting the resources: - secrets block (and its verbs: - get / - create) from
the Role/ClusterRole in the coredns autodelegate RBAC manifest; specifically
remove the rule that lists apiGroups: [""] with resources: ["secrets"] and verbs
including "get" and "create" so the Role/ClusterRole only grants the remaining
necessary permissions (e.g., service-related verbs), preserving YAML structure
and indentation for the surrounding rules.

Comment on lines +71 to +93
COREDNS_IP="$(kubectl get -n {{ .Values.coredns.namespace }} service coredns '-o=jsonpath={.status.loadBalancer.ingress[0].ip}')"
COREDNS_HOSTNAME="$(kubectl get -n {{ .Values.coredns.namespace }} service coredns '-o=jsonpath={.status.loadBalancer.ingress[0].hostname}')"

{{- range .Values.coredns.zones }}
ZONE="{{ . }}"

# Delete A record if using IP
if [ -n "$COREDNS_IP" ]; then
EXCLUDE_VALUE="${NS_NAME}.${ZONE}"
CURRENT_A=$(aws route53 list-resource-record-sets --hosted-zone-id "${ZONE_ID}" \
--query "ResourceRecordSets[?Name=='${NS_NAME}.${ZONE}' && Type=='A']" --output json)
if [ "$CURRENT_A" != "[]" ]; then
TTL=$(echo "$CURRENT_A" | jq -r '.[0].TTL')
CHANGE_BATCH=$(jq -n \
--arg name "${NS_NAME}.${ZONE}" \
--arg ip "$COREDNS_IP" \
--argjson ttl "$TTL" \
'{Changes: [{Action: "DELETE", ResourceRecordSet: {Name: $name, Type: "A", TTL: $ttl, ResourceRecords: [{Value: $ip}]}}]}')
aws route53 change-resource-record-sets --hosted-zone-id "${ZONE_ID}" --change-batch "$CHANGE_BATCH"
fi
else
EXCLUDE_VALUE="${COREDNS_HOSTNAME}."
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

delete.sh silently skips cleanup if the CoreDNS Service no longer has an LB ingress.

Both COREDNS_IP and COREDNS_HOSTNAME are best-effort kubectl get calls (no wait, no error handling). If the Service has already been deleted, is still pending, or was never ready, both variables are empty, and the else branch sets EXCLUDE_VALUE="." — which will not match any NS record value, so no NS cleanup happens and the stale delegation stays in Route53. Given this is a pre-delete hook the Service should still exist, but defensively:

  • kubectl wait for .status.loadBalancer.ingress with a short timeout, or
  • abort (exit 1) when both COREDNS_IP and COREDNS_HOSTNAME are empty so the failure is visible rather than silent.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml`
around lines 71 - 93, The script silently skips cleanup when both COREDNS_IP and
COREDNS_HOSTNAME are empty; update the pre-delete logic in delete.sh (the block
that sets COREDNS_IP/COREDNS_HOSTNAME and computes EXCLUDE_VALUE) to first wait
for the Service LB ingress (e.g., run a kubectl wait for
.status.loadBalancer.ingress with a short timeout against the service in {{
.Values.coredns.namespace }}) and then re-evaluate COREDNS_IP/COREDNS_HOSTNAME;
if after waiting both are still empty, fail fast (exit 1) with a clear error so
deletion does not silently skip cleanup. Ensure references to COREDNS_IP,
COREDNS_HOSTNAME, EXCLUDE_VALUE, NS_NAME and ZONE_ID remain unchanged so the
later A/NS deletion logic can proceed.

Comment on lines +82 to +90
if [ "$CURRENT_A" != "[]" ]; then
TTL=$(echo "$CURRENT_A" | jq -r '.[0].TTL')
CHANGE_BATCH=$(jq -n \
--arg name "${NS_NAME}.${ZONE}" \
--arg ip "$COREDNS_IP" \
--argjson ttl "$TTL" \
'{Changes: [{Action: "DELETE", ResourceRecordSet: {Name: $name, Type: "A", TTL: $ttl, ResourceRecords: [{Value: $ip}]}}]}')
aws route53 change-resource-record-sets --hosted-zone-id "${ZONE_ID}" --change-batch "$CHANGE_BATCH"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

DELETE of the A record reuses the current service IP; this will fail if the IP changed.

Route53's DELETE action requires the ResourceRecords.Value in the change batch to match exactly what's stored in the zone. Here you read TTL from CURRENT_A but substitute $COREDNS_IP (from the current Service) for the value:

--arg ip "$COREDNS_IP" \

If the LoadBalancer IP has changed since the record was created (e.g. cluster recreated without a clean uninstall, LB reassigned), the DELETE call will error with InvalidChangeBatch and leave a stale A record behind. Derive the value from CURRENT_A instead:

🛠️ Proposed fix
       if [ "$CURRENT_A" != "[]" ]; then
         TTL=$(echo "$CURRENT_A" | jq -r '.[0].TTL')
+        CURRENT_A_RECORDS=$(echo "$CURRENT_A" | jq '.[0].ResourceRecords')
         CHANGE_BATCH=$(jq -n \
           --arg name "${NS_NAME}.${ZONE}" \
-          --arg ip "$COREDNS_IP" \
           --argjson ttl "$TTL" \
-          '{Changes: [{Action: "DELETE", ResourceRecordSet: {Name: $name, Type: "A", TTL: $ttl, ResourceRecords: [{Value: $ip}]}}]}')
+          --argjson records "$CURRENT_A_RECORDS" \
+          '{Changes: [{Action: "DELETE", ResourceRecordSet: {Name: $name, Type: "A", TTL: $ttl, ResourceRecords: $records}}]}')
         aws route53 change-resource-record-sets --hosted-zone-id "${ZONE_ID}" --change-batch "$CHANGE_BATCH"
       fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@charts/kuadrant-instances/templates/coredns/autodelegate/01-configMap-script.yaml`
around lines 82 - 90, The DELETE change-batch currently uses the live Service IP
($COREDNS_IP) which can differ from the value stored in the zone; modify the
block that builds CHANGE_BATCH (where CURRENT_A, TTL, CHANGE_BATCH and the aws
route53 change-resource-record-sets call are used) to extract the actual record
value from CURRENT_A (e.g. the ResourceRecords[0].Value) and use that extracted
IP for the --arg ip in the jq -n payload so the DELETE matches the exact
existing record.

Comment thread README.md
Comment thread tools-install.sh
Comment thread values.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add automatic job for publishing NS for coredns zone

2 participants