Add kubectl bootstrap script #30
Labels
No labels
blocked
bug
duplicate
effort
high
effort
low
effort
medium
effort
minimal
enhancement
help wanted
invalid
pr
feedback
pr
reviewing
question
status
backlog
status
document
status
done
status
implement
status
pending
status
planning
status
reviewing
waiting
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
tepichord/milner#30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Naina:
Overview
Add a
control-plane/use-kubectl.shscript that wires kubectl to the Milner Talos cluster, mirroringuse-talos.shpatterns. The script reads the kubeconfig from Terraform output, manages a named context in the user's kubeconfig, and stays idempotent across repeated runs.Technical Approach
Create
control-plane/use-kubectl.shfollowing theuse-talos.shskeleton:Verified (in-repo):
use-talos.shexists at control-plane/use-talos.sh with#!/usr/bin/env bash,set -e,cd "$(dirname "$0")", and color helpers (RED, GREEN, YELLOW, NC, log_info, log_warn, log_error)Fetch kubeconfig from Terraform output:
Extract context name from the kubeconfig:
The kubeconfig YAML has
current-context: milner— same as the context/cluster/user names.Unverified: The
current-context: milnerclaim depends on Terraform output which cannot be inspected without state. The resource naming (talos_cluster_kubeconfig.this) makes this plausible but not confirmed.Set target kubeconfig path:
Merge strategy — KUBECONFIG env var +
--flatten:kubectl config mergedoes not exist (kubernetes/kubectl#1868). Use the KUBECONFIG merge trick instead:Verified (external):
kubectl config mergedoes not exist — kubernetes/kubectl#1868 is an open feature requestSet current context and warn on switch:
Update
tests/test_static.py— add to the shellcheck script list:Verified (in-repo):
tests/test_static.pyexists withscriptslist at line 17 — note: the plan says "edit line 13" but thescriptslist starts at line 17 (line 13 is the@requires("shellcheck")decorator)Update
README.md— replace the manual kubeconfig step in runbook section 3:Verified (in-repo): README.md runbook section 3 at line 58-62 currently has the manual
terraform -chdir=control-plane output -raw kubeconfig > kubeconfigstep that needs replacementImplementation Details
control-plane/use-kubectl.shuse-talos.shstructuretests/test_static.py"control-plane/use-kubectl.sh"toscriptslist — note: thescriptslist is actually at line 17, not 13README.mdterraform -chdir=control-plane output -raw kubeconfig > kubeconfig+kubectl --kubeconfig kubeconfig get nodeswith./control-plane/use-kubectl.sh+kubectl get nodesOut-of-scope notes:
Verified (external): Talos kubeconfig uses mTLS certs with 1-year validity — terraform-provider-talos#47 comment confirms `validity_period_hours = 24 * 365 # same 1 year period that talosctl kubeconfig uses
--kubeconfigflag passthrough — the script writes directly to the default config, likeuse-talos.shdoes for talosctlVerified (in-repo):
use-talos.shusestalosctl --talosconfig "$target_config"and writes directly viacp "$tmp_config" "$target_config"— control-plane/use-talos.shsensitive = truein Terraform); the script never commits or logs itVerified (in-repo):
sensitive = trueat control-plane/main.tf:419Acceptance Criteria
control-plane/use-kubectl.shexists, ischmod +x, and has#!/usr/bin/env bash+set -eterraform output -raw kubeconfigand exits with a clear error when output is empty~/.kube/config(or$KUBECONFIG) is created with correct permissions (0600)milnerare removed before merge — no duplicates accumulateshellcheck control-plane/use-kubectl.shpasses cleantest_shellchecktest passes with the new script in the listTesting Plan
shellcheck control-plane/use-kubectl.sh— catches quoting, globbing, unused-variable issues./control-plane/use-kubectl.shafterterraform apply, thenkubectl get nodesreturns the control-plane nodekubectl config get-contextsmilnercontext, run the script, verify only onemilnercontext remains~/.kube/configaside, run the script, verify it creates a new config with themilnercontext set as currentRelated Issues/PRs
use-talos.sh(the reference implementation this mirrors)Research Findings
kubectl config mergedoes not exist. It's an open feature request (kubernetes/kubectl#1868). The idiomatic workaround isKUBECONFIG=a:b kubectl config view --flatten > merged— supported since kubectl v1.0.Verified (external): kubectl#1868 confirms the feature does not exist
Verified (external): terraform-provider-talos#47 comment confirms 1-year validity period
current-context: milner, context/cluster/user all namedmilner— extracted viased -n 's/^current-context: *//p'(source: terraform-provider-talos issues #47).Unverified: The exact
current-context: milnerstructure depends on Terraform state and provider behavior; the extraction method is sound but the value cannot be confirmed without running terraform output