#8361·k0s

images.repository: the #6243 idempotency guard doesn't cover a *changed* repository(subpath still duplicated)

Author: sakshisharma84Created Sep 22, 2026Updated Sep 24, 2026
Labelsbug

Before creating an issue, make sure you've checked the following:

  • You are running the latest released version of k0s
  • Make sure you've searched for existing issues, both open and closed
  • Make sure you've searched for PRs too, a fix might've been merged already
  • You're looking at docs for the released version, "main" branch docs are usually ahead of released versions.

First box is unchecked deliberately as this was observed on v1.35.4+k0s.0, not the newest release. It applies regardless: overrideRepository in pkg/apis/k0s/v1beta1/images.go is unchanged on main and the reproduction below runs against the v1beta1 API with no cluster involved.

#6230 reported subpath duplication with a custom repository and was fixed by #6243. That fix handles re-applying the same repository. This is the changed-repository case, which it doesn't reach.

Platform

bash
linux/amd64
Amazon Linux 2023.12.20260918
kernel 6.18.48-109.150.amzn2023.x86_64
containerd://1.7.31

Version

v1.35.4+k0s.0 (includes #6243)

Sysinfo

`k0s sysinfo`

Omitted — nothing here depends on the host. The failure is entirely in config
handling and reproduces from a unit test against pkg/apis/k0s/v1beta1.

What happened?

overrideRepository replaces only the host of an image name:

if host := getHostName(originalImage); host != "" {
    return strings.Replace(originalImage, host, repository, 1)
}

That is correct while the image's repository is its host. So, true of k0s's own quay.io/k0sproject/* defaults. It stops being true of the function's own output once repository carries a subpath:

quay.io/k0sproject/pause  +  repository=example.com/org
  → example.com/org/k0sproject/pause                      ✅
example.com/org/k0sproject/pause  +  repository=other.example.com/org2
  → other.example.com/org2/org/k0sproject/pause           ❌  "org" stranded

The #6243 guard catches the first case but not the second, since it only matches an unchanged prefix:

if strings.HasPrefix(originalImage, repository) { return originalImage }

This is reachable in practice because with --enable-dynamic-config the resolved names are persisted in the in-cluster ClusterConfig alongside the repository they were resolved against. When something later updates only repository, k0smotron's ReconcileDynamicConfig merge-patches exactly that field. Thus, the stored names stay stale and the next read re-applies the override on top of them. The second override becomes the normal path, not an edge case.

Steps to reproduce

This reproduces with a unit test, no cluster needed. Add the following to pkg/apis/k0s/v1beta1/images_test.go and run go test ./pkg/apis/k0s/v1beta1/...

func TestOverrideRepositoryIsSafeToChange(t *testing.T) {
      const want = "other.example.com/org2/k0sproject/pause"

      ci := DefaultClusterImages()
      json.Unmarshal([]byte(`{"repository":"example.com/org"}`), ci)

      // persist, change only `repository`, re-read — what dynamic config does
      persisted, _ := json.Marshal(ci)
      var doc map[string]any
      json.Unmarshal(persisted, &doc)
      doc["repository"] = "other.example.com/org2"
      changed, _ := json.Marshal(doc)

      got := DefaultClusterImages()
      json.Unmarshal(changed, got)

      if got.Pause.Image != want {
              t.Errorf("pause image after repository change:\n  got  %s\n  want %s", got.Pause.Image, want)
      }
}

On a cluster: deploy with --enable-dynamic-config and images.repository set to a value containing a subpath, then change that value and inspect the resulting image references.

Expected behavior

repository resolves against k0s's default image names, so changing it to other.example.com/org2 should produce other.example.com/org2/k0sproject/pause, the same result as setting that value on a fresh config.

Actual behavior

got  other.example.com/org2/org/k0sproject/pause
want other.example.com/org2/k0sproject/pause

The segment contributed by the previous repository is carried forward as though it were part of the image name.

Screenshots and logs

Observed on a k0smotron-managed CAPI cluster after changing the registry. MKE 4 mirrors the k0s images under ghcr.io/mirantiscontainers, so mirantiscontainers is the stranded segment:

Failed to pull image "<newRegistry>/mirantiscontainers/k0sproject/coredns:1.14.2-0": not found
Failed to pull image "<newRegistry>/mirantiscontainers/k0sproject/kube-proxy:v1.35.4": not found
Failed to pull image "<newRegistry>/mirantiscontainers/k0sproject/metrics-server:v0.8.1-0": not found
Failed to pull image "<newRegistry>/mirantiscontainers/k0sproject/pushgateway-ttl:1.4.0-k0s.0": not found
failed to get sandbox image "<newRegistry>/mirantiscontainers/k0sproject/pause:3.10.1": not found

Replacement control-plane nodes never become Ready (NetworkPluginNotReady) and the rolling update wedges.

Additional context

A cluster without dynamic config is unaffected. Our management cluster rebuilds its config from DefaultClusterImages() on every apply, so the override only ever sees pristine defaults, and the same subpath-bearing registry works correctly there. Both conditions are required: a repository with a subpath and the override re-running on its own output.

Possible directions:

  • Persist/keep the declared image names rather than the resolved ones, resolving at use time.
  • Reset to DefaultClusterImages() before applying a changed repository.
  • Record the repository the names were resolved against and strip that prefix, rather than the host, extending #6243's approach to cover the changed case.

Happy to open a PR if you can point at a preferred direction.