Skip to content
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

Add flag to remap registries for any registry mirror #2935

Merged
merged 5 commits into from
Feb 14, 2024

Conversation

babs
Copy link
Contributor

@babs babs commented Jan 7, 2024

Description

The purpose of this PR is to add an option to remap registries, a kind of generalized --registry-mirror. This is helpful for air-gapped environments and/or when local registry mirrors are available (not limited to docker.io). This allows user to reference any images without having to change their location. It also permit to separate infra related configuration (the mirrors) from CI/CD pipeline definition by using an environment variable for example (the reason behind the early return if flag provided but empty). Therefore you can have a pipeline calling kaniko with --registry-map=$REGISTRY_MAP and have the REGISTRY_MAP populated via the runner's env by another team, and the absence of env wouldn't trigger a failure, it makes the pipeline env independent.

I've also considered the option of environment variables directly but it doesn't seems to be in kaniko's philosophy. (see update 1)

This makes quite some duplicated code :/ One option to keep the mirror flag and behavior would be to use only one codebase and convert --registry-mirror=VALUE to --registry-map=index.docker.io=VALUE internally.(see update 1)
Suggestions welcome!

[UPDATE 1]
As there is a KANIKO_REGISTRY_MIRROR, I added KANIKO_REGISTRY_MAP.
I've also replaced the mirror logic with map, keeping the original behavior.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

- kaniko adds a new flag `--registry-map` to provide a map of mirrors to use as pull-through cache instead. Expected format is 'orignal.registry=new.registry;other-original.registry=other-remap.registry'

The purpose of this PR is to add an option to remap registries, a kind of generalized `--registry-mirror`.
This is helpful for air-gapped environments and/or when local registry mirrors are available (not limited to docker.io).
This allows user to reference any images without having to change their location.
It also permit to separate infra related configuration (the mirrors) from CI/CD pipeline definition by using an environment variable for example (the reason behind the early return if flag provided but empty).
Therefore you can have a pipeline calling kaniko with `--registry-map=$REGISTRY_MAP` and have the `REGISTRY_MAP` populated via the runner's env by another team, and the absence of env wouldn't trigger a failure, it makes the pipeline env independent.

I've also considered the option of environment variables directly but it doesn't seems to be in kaniko's philosophy.

This makes quite some duplicated code :/ One option to keep the mirror flag and behavior would be to use only one codebase and convert `--registry-mirror=VALUE` to `--registry-map=index.docker.io=VALUE` internally. Suggestions welcome!
Copy link

google-cla bot commented Jan 7, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@babs
Copy link
Contributor Author

babs commented Jan 20, 2024

Still open to suggestions ;-)

@babs
Copy link
Contributor Author

babs commented Feb 5, 2024

I've finally decided to replace registry mirror with map logic and allow use of environment variable as KANIKO_REGISTRY_MIRROR existed in the code

@babs
Copy link
Contributor Author

babs commented Feb 7, 2024

Related issue #2990

Copy link
Collaborator

@aaron-prindle aaron-prindle left a comment

Choose a reason for hiding this comment

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

Appreciate your patience here @babs. Thanks for the PR, LGTM

@aaron-prindle aaron-prindle merged commit 1bf529e into GoogleContainerTools:main Feb 14, 2024
10 checks passed
@babs
Copy link
Contributor Author

babs commented Feb 15, 2024

Np, happy to see it merged.
If I can help ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants