kubeblocks icon indicating copy to clipboard operation
kubeblocks copied to clipboard

feat: replace image registry dynamically

Open cjc7373 opened this issue 1 year ago • 2 comments

When does image replcaement happen

Bascially, replacement will happen when workload resources (like pod, job, deployment, statefulset) are created.

Specifically, the replacement will inject to:

  • instanceset controller, so that it affects:

    • new cluster creation
    • cluster upgrade

    But it won't affect:

    • cluster scaling
    • instance template
  • addon controller, so that it affects helm install jobs

  • backup/restore controller

Replace Configs

sample config:

registries:
  defaultRegistry: foo.bar
  defaultNamespace: default
  registriyConfig:
  - from: docker.io
    to: docker-mirror.io
  - from: k8s.io
    to: company-registry.io
    registryDefaultNamespace: k8sio
    namespaces:
    - from: special-ns
      to: my-special-ns

The replacement rules are as follows:

  • If there's no specific registry config (registriyConfig field), or registry does not match any specific registry config, defaultRegistry and defaultNamespace will be used.
    • If defaultNamespace is not defined, namespace remains unchanged.
    • If defaultRegistry is not defined, registry remains unchanged.
  • If image's registry matches a specific registry config:
    • from and to should not be empty. Registry to will be used.
    • If there's no namespace config, or namespace does not match any specific namespace config, registryDefaultNamespace will be used. If registryDefaultNamespace is not defined, namespace remains unchanged.
    • If namespace matches a specific namespace config, namespace to will be used.
      • from and to of the namespace may be empty (empty namespace is legal)

Other things to note

One side effect of this change is that omitted image name (e.g. busybox) will be expanded to full format (e.g. docker.io/library/busybox). IMO this will not have any user facing change.

cjc7373 avatar Aug 23 '24 10:08 cjc7373

Codecov Report

Attention: Patch coverage is 77.60000% with 28 lines in your changes missing coverage. Please review.

Project coverage is 60.40%. Comparing base (d23e2e8) to head (5dda436). Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controllerutil/image_util.go 74.74% 24 Missing and 1 partial :warning:
pkg/dataprotection/backup/deleter.go 0.00% 2 Missing :warning:
pkg/dataprotection/utils/backuprepo.go 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8018      +/-   ##
==========================================
+ Coverage   60.26%   60.40%   +0.14%     
==========================================
  Files         377      378       +1     
  Lines       45781    45891     +110     
==========================================
+ Hits        27589    27722     +133     
+ Misses      15600    15592       -8     
+ Partials     2592     2577      -15     
Flag Coverage Δ
unittests 60.40% <77.60%> (+0.14%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 23 '24 11:08 codecov[bot]

@weicao @zjx20 PTAL

cjc7373 avatar Sep 10 '24 07:09 cjc7373

@cjc7373 Please resolve conflicts and cover the case at https://github.com/apecloud/kubeblocks/pull/8539 .

zjx20 avatar Nov 29 '24 02:11 zjx20

/cherry-pick release-1.0-beta

leon-inf avatar Dec 05 '24 09:12 leon-inf

🤖 says: cherry pick action finished successfully 🎉!
See: https://github.com/apecloud/kubeblocks/actions/runs/12176948165

apecloud-bot avatar Dec 05 '24 09:12 apecloud-bot