fix: move cluster pki and kubeconfig out of binary_dir - #3198
Merged
kubesphere-prow[bot] merged 1 commit intoAug 19, 2026
Merged
Conversation
When the same binary_dir is shared across multiple clusters (e.g. to reuse
the offline artifact package of binaries and images), the generated
{binary_dir}/pki and {binary_dir}/kubeconfig collide between clusters,
because these are cluster-specific artifacts rather than part of the
shareable offline package.
Move pki and kubeconfig to the per-cluster work_dir so that binary_dir can
stay cluster-agnostic. All affected references are local kk-host paths
(gen_cert writes, copy/fetch sources, local precheck); the certificates are
still copied to the correct remote paths (/etc/ssl/etcd/ssl,
/opt/harbor/*/ssl, /opt/docker-registry/*/ssl), so the install and
cert-renew flows are unchanged.
Signed-off-by: redscholar <blacktiledhouse@gmail.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: redscholar The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What type of PR is this?
/kind bug
What does this PR do
Moves the cluster-specific
pkiandkubeconfigartifacts frombinary_dirtowork_dir, so that a singlebinary_dircan be safely shared across multiple clusters.Background / Motivation
binary_diris meant to be a cluster-agnostic, shareable offline package (binaries + images). However,certs/init,kubernetes/init,certs/renew,image-registryandprecheckcurrently write/read the generatedpkiandkubeconfigunderbinary_dir. These are cluster-specific artifacts.When the same
binary_diris intentionally shared across clusters (to reuse the offline artifact package),{binary_dir}/pkiand{binary_dir}/kubeconfigcollide between clusters, corrupting the CA/kubeconfig of every cluster sharing that directory.Implementation
Replace all
{{ .binary_dir }}/pkiand{{ .binary_dir }}/kubeconfigreferences with{{ .work_dir }}/pkiand{{ .work_dir }}/kubeconfig.work_diris already per-cluster, so the artifacts are naturally isolated whilebinary_dirstays shareable.runtimewas deliberately not used as the target: it stores per-run execution state (CRs / variable caches) under a deep, run-scoped path and may be cleaned, whereas pki/kubeconfig must persist across runs (e.g.gen_certIfNotPresentreuse,certs/renew,join) and be referenced by independent playbooks.Key Changes
builtin/core/roles/certs/init/tasks/main.yamlgen_certout_key/out_cert+ finalchownnow use{{ .work_dir }}/pkibuiltin/core/roles/certs/renew/kubernetes/tasks/kube.yamlfetch/copykubeconfig now{{ .work_dir }}/kubeconfigbuiltin/core/roles/certs/renew/image-registry/*copysrc →{{ .work_dir }}/pkibuiltin/core/roles/kubernetes/init-kubernetes/tasks/main.yamlfetchadmin.conf →{{ .work_dir }}/kubeconfigbuiltin/core/roles/kubernetes/join-kubernetes/tasks/main.yamlcopykubeconfig src →{{ .work_dir }}/kubeconfigbuiltin/core/roles/image-registry/{harbor,docker-registry}/tasks/install.yamlcopysrc →{{ .work_dir }}/pkibuiltin/core/roles/precheck/image-registry/network/tasks/main.yamlcheck.sh+add_hostvarscert paths →{{ .work_dir }}/pkibuiltin/core/roles/defaults/defaults/main/02-image_registry.yamlca_file/cert_file/key_filedefaults →{{ .work_dir }}/pkibuiltin/core/roles/defaults/defaults/main/03-kubernetes.yaml{{ .work_dir }}/pkibuiltin/core/roles/defaults/defaults/main/04-etcd.yamlca_file/server_*/client_*→{{ .work_dir }}/pkidocs/en/reference/config.md,docs/zh/reference/config.mdpkg/const/workdir.gopki/andkubeconfigunderwork_dirImpact
certs,kubernetes,image-registry,precheck),defaults,const, docs.work_dirinstead of{{ work_dir }}/kubekey; rollback = revert this commit.Breaking Changes
None for the standard single-cluster flow. The change is a local-path-only template substitution: all
{{ .work_dir }}/pki/{{ .work_dir }}/kubeconfigreferences are on the kk control host (gen_certwrites,copy/fetchsources/destinations, localprecheckcheck.sh). The certificates are still copied to the same remote destinations (/etc/ssl/etcd/ssl,/opt/harbor/*/ssl,/opt/docker-registry/*/ssl), so install and cert-renew behavior is unchanged.Only external automation that explicitly read
{binary_dir}/pkior{binary_dir}/kubeconfigwould need to look underwork_dirinstead.Which issue(s) this PR fixes:
Fixes #
Testing
Verification performed
make test)make test)Steps to verify
make build(ormake kk) — embeds the updated builtin playbooks.kk create clusterwith a sharedbinary_diracross two clusters — confirmwork_dir/pkiandwork_dir/kubeconfigare isolated per cluster and no longer collide.kk create clustersingle-cluster (defaultbinary_dir = work_dir/kubekey) — confirm install,add node, andkk certs renewstill work.Test coverage
This is a mechanical path substitution in builtin YAML; no Go logic changed. Live-cluster verification (above) is the meaningful test and is pending.
Rollback
Plain revert of this commit restores the previous
binary_dir-scoped paths. No data migration required (artifacts are regenerated on next run).Does this PR introduce a user-facing change?
Checklist
.envfiles committedSigned-off-by)make build)Additional documentation, usage docs, etc.:
Notes for Reviewer
Please focus on whether any
binary_dir/pkiorbinary_dir/kubeconfigreference was missed, and whetherwork_diris guaranteed to exist/resolvable in every task context that uses these paths (it is a top-level config variable, same asbinary_dir). Thepkisubdirectory is created implicitly bygen_cert/fetch(os.MkdirAll), so no explicitmkdirwas needed.