Skip to content

fix cks cluster stuck starting when a private registry is set - #14408

Open
Damans227 wants to merge 3 commits into
apache:mainfrom
Damans227:fix-cks-private-registry-11596
Open

Damans227 wants to merge 3 commits into
apache:mainfrom
Damans227:fix-cks-private-registry-11596

Conversation

@Damans227

@Damans227 Damans227 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #11596

With a private registry set, a new CKS cluster stays in Starting. The control node setup script for the registry is wrapped in {% if registry is defined %}, but registry is never a cloud-init variable. The server fills in the registry details as plain text, so the check is never true and the script is never written. The server still swaps the line that writes the containerd config for a call to that script, so containerd keeps its default config with the image service off and kubeadm never runs. This keeps the jinja header and changes the check to {% if "{{ registry.enabled }}" == "true" %}, and the server fills in true or false when it builds the user data.

Test:

  • Added unit tests for a cluster with and without a registry. The lab run below was on the first commit.

  • On a KVM lab with 2 hosts and cloud.kubernetes.cluster.experimental.features.enabled=true, create a CKS cluster (v1.36.0, 1 control node, 1 worker) with dockerregistryurl=https://index.docker.io/v1/ and a registry username and password.

Before: the cluster stays in Starting. On the control node:

bash: /opt/bin/setup-containerd: No such file or directory
disabled_plugins = ["cri"]
kubelet: open /var/lib/kubelet/config.yaml: no such file or directory

After: the cluster goes to Running and both nodes are Ready. On the control node:

$ ls /opt/bin | grep setup-containerd
setup-containerd
$ grep -E "disabled_plugins|index.docker.io" /etc/containerd/config.toml
disabled_plugins = []
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."index.docker.io/v1/"]
  endpoint = ["https://index.docker.io/v1/"]
$ kubectl get nodes
NAME                             STATUS   ROLES           AGE   VERSION
after11596-control-1a14050986c   Ready    control-plane   67s   v1.36.0
after11596-node-1a14050ede7      Ready    <none>          55s   v1.36.0

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 20.93%. Comparing base (85ca17a) to head (da7b86d).

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14408      +/-   ##
============================================
+ Coverage     20.92%   20.93%   +0.01%     
- Complexity    21142    21154      +12     
============================================
  Files          6057     6057              
  Lines        549556   549559       +3     
  Branches      73477    73477              
============================================
+ Hits         114991   115052      +61     
+ Misses       421116   421057      -59     
- Partials      13449    13450       +1     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.38% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Damans227
Damans227 requested a review from nvazquez October 15, 2026 16:19
@Damans227
Damans227 marked this pull request as ready for review October 15, 2026 16:19

@Pearl1594 Pearl1594 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code lgtm - havent tested this.

@DaanHoogland DaanHoogland added this to the 24.0 milestone Nov 14, 2026
@bhouse-nexthop

bhouse-nexthop commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Tested this on a KVM lab with a private registry set. The control node came up with no SSH key and no Kubernetes: cloud-init dropped the whole cloud-config.

Cause: cloud-init renders the template with trim_blocks. That removes the newline after a block tag but keeps the spaces before it. So the two spaces in front of {% if %} get prepended to the next line, putting - path: /opt/bin/setup-containerd at indent 4, and the YAML no longer parses.

The indent was already there on main, but the block never rendered (registry is defined was never true), so it didn't matter. With this PR the block renders for the first time.

Fix: put both tags at column 0 in k8s-control-node.yml:

{% if "{{ registry.enabled }}" == "true" %}
  - path: /opt/bin/setup-containerd
  ...
{% endif %}

With that change the rendered cloud-config parses again.

Update: re-tested with the fix: the registry cluster reaches Running, containerd uses the registry as mirror on every node, and all images are pulled through it. A unit test that renders the template the way cloud-init does (trim_blocks) and parses the result as YAML would catch this.

Smaller things in the same code path. They're older than this PR, so they may be better as follow-ups:

Issue Effect
Registry password / user values are rendered through jinja {%, {{ or {# in a password breaks the config
Credentials go into sed and shell unescaped /, &, ' etc. in a password break setup-containerd
registryUrl.split("://")[1] A URL without a scheme throws ArrayIndexOutOfBoundsException

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CKS cluster doesn't come up if "cloud.kubernetes.cluster.experimental.features.enabled" setting is enabled

5 participants