Repository navigation
feat(registry): add support for overriding image registry in Helm cha… #4261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: tekton-pipelines-controller | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: tekton-pipelines-controller | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: tekton-pipelines-controller | ||
| spec: | ||
| containers: | ||
| - name: tekton-pipelines-controller | ||
| image: ghcr.io/tektoncd/pipeline/controller-10a3e32792f33651396d02b6855a6e36:v1.15.0@sha256:aaaa | ||
| args: [ | ||
| "-entrypoint-image", "ghcr.io/tektoncd/pipeline/entrypoint-bff0a22da108bc2f16c818c97641a296:v1.15.0@sha256:bbbb", | ||
| "-nop-image", "ghcr.io/tektoncd/pipeline/nop-8eac7c133edad5df719dc37b36b62482:v1.15.0@sha256:cccc", | ||
| "-sidecarlogresults-image", "ghcr.io/tektoncd/pipeline/sidecarlogresults-7501c6a20d741631510a448b48ab098f:v1.15.0@sha256:dddd", | ||
| "-workingdirinit-image", "ghcr.io/tektoncd/pipeline/workingdirinit-0c558922ec6a1b739e550e349f2d5fc1:v1.15.0@sha256:eeee", | ||
| "-shell-image", "cgr.dev/chainguard/busybox@sha256:ffff", | ||
| "-shell-image-win", "mcr.microsoft.com/powershell:nanoserver@sha256:9999", | ||
| "-disable-ha=false", | ||
| "-trailing-image" | ||
| ] | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: tekton-triggers-controller | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: tekton-triggers-controller | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: tekton-triggers-controller | ||
| spec: | ||
| containers: | ||
| - name: tekton-triggers-controller | ||
| image: ghcr.io/tektoncd/triggers/controller-13c3e5ef5e0ad5a6b2a5de1fa6d5a9a4:v0.37.0 | ||
| args: [ | ||
| "-logtostderr", | ||
| "-stderrthreshold", "INFO", | ||
| "-el-image", "ghcr.io/tektoncd/triggers/eventlistenersink-7ad1faa98cddbcb0c24990303b220bb8:v0.37.0@sha256:1111", | ||
| "-el-port", "8080", | ||
| "-el-security-context=true", | ||
| "-el-events", "disable" | ||
| ] | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: StatefulSet | ||
| metadata: | ||
| name: tekton-results-postgres | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: tekton-results-postgres | ||
| serviceName: tekton-results-postgres | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: tekton-results-postgres | ||
| spec: | ||
| containers: | ||
| - name: postgres | ||
| image: bitnami/postgresql@sha256:2222 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,15 +210,27 @@ func overrideImageRegistry(registry, imageName string) string { | |
| if strings.Contains(imageName, "$(") { | ||
| return imageName | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to make this fonction idemptotent
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the logic for idempotent function. It helps in cases registry already set i.e. registries that include a path. With TEKTON_REGISTRY_OVERRIDE=myreg.io/mirror, an image that had already been rewritten (myreg.io/mirror/tektoncd/x) was treated as having the host myreg.io, so it became myreg.io/mirror/mirror/tektoncd/x. |
||
| } | ||
| // Already under the override registry: leave it alone so that a second | ||
| // pass (e.g. an image pre-rewritten by the Helm chart) is a no-op. | ||
| registry = strings.TrimSuffix(registry, "/") | ||
| if strings.HasPrefix(imageName, registry+"/") { | ||
| return imageName | ||
| } | ||
| parts := strings.Split(imageName, "/") | ||
| if len(parts) > 1 { | ||
| if len(parts) > 1 && isRegistryHost(parts[0]) { | ||
| // if image has registry part, replace it | ||
| return registry + "/" + strings.Join(parts[1:], "/") | ||
| } | ||
| // if image does not have registry part, add it | ||
| // no registry part (e.g. "bitnami/postgresql"): prepend the registry | ||
| return registry + "/" + imageName | ||
| } | ||
|
|
||
| // isRegistryHost uses the Docker rule: a registry host contains "." or ":", | ||
| // or is "localhost". Otherwise it is a namespace, e.g. "bitnami". | ||
| func isRegistryHost(component string) bool { | ||
| return strings.ContainsAny(component, ".:") || component == "localhost" | ||
| } | ||
|
|
||
| // ToLowerCaseKeys converts key value to lower cases. | ||
| func ToLowerCaseKeys(keyValues map[string]string) map[string]string { | ||
| newMap := map[string]string{} | ||
|
|
@@ -330,8 +342,14 @@ func replaceContainerImages(containers []corev1.Container, images map[string]str | |
| // matches a given "*-image*" flag (e.g. "-shell-image-win"), it falls back | ||
| // to rewriting just the registry domain, so TEKTON_REGISTRY_OVERRIDE alone | ||
| // also applies to arg-based images and not only to container.Image. | ||
| // Only flags are matched; a flag's value is never treated as a flag. | ||
| func replaceContainersArgsImage(container *corev1.Container, images map[string]string, registry string) { | ||
| for a, arg := range container.Args { | ||
| for a := 0; a < len(container.Args); a++ { | ||
| arg := container.Args[a] | ||
| if !strings.HasPrefix(arg, "-") { | ||
| continue | ||
| } | ||
|
|
||
| if argVal, hasArg := SplitsByEqual(arg); hasArg { | ||
| argument := formKey(ArgPrefix, argVal[0]) | ||
| if url, exist := images[argument]; exist { | ||
|
|
@@ -342,12 +360,18 @@ func replaceContainersArgsImage(container *corev1.Container, images map[string]s | |
| continue | ||
| } | ||
|
|
||
| if a+1 >= len(container.Args) || strings.HasPrefix(container.Args[a+1], "-") { | ||
| // flag without a value | ||
| continue | ||
| } | ||
|
|
||
| argument := formKey(ArgPrefix, arg) | ||
| if url, exist := images[argument]; exist { | ||
| container.Args[a+1] = url | ||
| } else if strings.Contains(argument, "_image") { | ||
| container.Args[a+1] = overrideImageRegistry(registry, container.Args[a+1]) | ||
| } | ||
| a++ // skip the value | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for pruner image we shoulndt call withRegistry, otherwise there will be double override (the second is done pruner.go with TEKTON_REGISTRY_OVERRIDE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i missed it... thx!