Add credential_namespace variable to harvester-integration#83
Add credential_namespace variable to harvester-integration#83HiranAdikari wants to merge 2 commits intowso2:mainfrom
Conversation
The SA and token Secret for the cloud credential were hardcoded to kube-system. Brownfield deployments that created these resources in a different namespace (e.g. default) would see a forced replacement on every apply due to the namespace drift. Expose credential_namespace (default: kube-system) so consumers can pin the value to match their existing state. Closes wso2#82
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughOverviewAdds a new credential_namespace variable to the harvester-integration module to support configurable Kubernetes namespaces for cloud credential resources, and improves CoreDNS ConfigMap handling to prevent unintended configuration loss. ChangesNew Variable
Cloud Credential Resources
CoreDNS ConfigMap Handling
Test Plan / Behavior
ImpactPrevents Terraform-detected namespace drift and unintended resource replacements in brownfield deployments, and ensures CoreDNS configuration remains intact when CoreDNS patching is toggled. Closes WalkthroughThis pull request adds a new input variable Sequence Diagram(s)sequenceDiagram
participant User
participant Terraform
participant HarvesterModule as "harvester-integration module"
participant KubernetesAPI as "Kubernetes API (cluster)"
participant Rancher as "Rancher (optional)"
User->>Terraform: terraform apply
Terraform->>HarvesterModule: render resources with vars (credential_namespace, patch_coredns, rancher_*)
HarvesterModule->>KubernetesAPI: create/update ServiceAccount & Secret in credential_namespace
HarvesterModule->>KubernetesAPI: create/update ClusterRoleBinding (namespace-aware)
alt patch_coredns = true
HarvesterModule->>KubernetesAPI: update CoreDNS ConfigMap with patched Corefile (includes rancher_lb_ip/hostname)
note right of HarvesterModule: Terraform check ensures rancher_lb_ip or rancher_hostname set
else patch_coredns = false
HarvesterModule->>KubernetesAPI: update CoreDNS ConfigMap with default Corefile
end
KubernetesAPI->>Terraform: acknowledge resource state
Terraform->>User: apply complete
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
modules/management/harvester-integration/variables.tf (1)
19-23: Add validation forcredential_namespaceinput.This variable is configurable, but invalid empty values are not rejected early. A small validation block will fail fast and prevent apply-time provider errors.
Proposed patch
variable "credential_namespace" { type = string description = "Kubernetes namespace for the cloud credential ServiceAccount and token Secret on Harvester. Override to match an existing namespace when importing brownfield state." default = "kube-system" + validation { + condition = trim(var.credential_namespace) != "" + error_message = "credential_namespace must be a non-empty Kubernetes namespace." + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@modules/management/harvester-integration/variables.tf` around lines 19 - 23, Add a Terraform validation block to the variable "credential_namespace" to reject empty values and fail fast; update the variable "credential_namespace" declaration to include a validation { condition = length(trim(var.credential_namespace)) > 0 error_message = "credential_namespace must not be empty" } so blank or whitespace-only inputs are refused before plan/apply.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@modules/management/harvester-integration/main.tf`:
- Around line 113-123: The CoreDNS patch template (_coredns_corefile_patched) is
interpolating var.rancher_lb_ip and var.rancher_hostname even when they are
empty; modify the logic that applies the patch (guarded by patch_coredns) to
also require non-empty var.rancher_lb_ip and var.rancher_hostname (e.g., add a
conditional check or use a Terraform validation/conditional expression) so that
when patch_coredns = true but either var.rancher_lb_ip or var.rancher_hostname
is empty the patch is blocked and a clear error is raised; update references
around patch_coredns, local._coredns_corefile_patched and any resource that uses
that local to respect this guard.
---
Nitpick comments:
In `@modules/management/harvester-integration/variables.tf`:
- Around line 19-23: Add a Terraform validation block to the variable
"credential_namespace" to reject empty values and fail fast; update the variable
"credential_namespace" declaration to include a validation { condition =
length(trim(var.credential_namespace)) > 0 error_message = "credential_namespace
must not be empty" } so blank or whitespace-only inputs are refused before
plan/apply.
🪄 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: a14e71f1-f8d5-417b-97c8-19d42e11af7c
📒 Files selected for processing (2)
modules/management/harvester-integration/main.tfmodules/management/harvester-integration/variables.tf
Add validation block to credential_namespace to reject empty or whitespace-only values before plan/apply. Add check block for coredns_patch_vars_set so that setting patch_coredns = true without both rancher_lb_ip and rancher_hostname fails early with a clear error instead of silently rendering an empty hosts entry in the CoreDNS Corefile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Both review comments addressed in the latest commit:
|
Summary
credential_namespacevariable to theharvester-integrationmodule, allowing the Kubernetes namespace for the cloud credential ServiceAccount and token Secret to be configured (default:kube-system)count = 0which would destroy the entire Corefile key and break cluster DNSWhy
The
credential_namespacevariable is needed for brownfield imports where the SA and Secret were originally created in a namespace other than the defaultkube-system(e.g.,default). Without this variable,terraform planforces a destroy+recreate of the SA, ClusterRoleBinding, and Secret — which would briefly break cloud credential authentication.The CoreDNS fix prevents a dangerous plan where
patch_coredns = falsewould destroy theCorefilekey entirely, leaving CoreDNS with no configuration and breaking cluster DNS.Test plan
terraform planwithcredential_namespace = "default"shows no changes for existing SA/Secret indefaultnamespacepatch_coredns = falserestores the standard Corefile (no hosts block) instead of destroying the keypatch_coredns = truecorrectly injectsrancher_lb_ip → rancher_hostnamein the hosts blockCloses #82
🤖 Generated with Claude Code