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

Fix: Using the ./manage-offline-container-images.sh register command does not create a new container but registers the image in the existing container registry. #11964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DearJey
Copy link

@DearJey DearJey commented Feb 10, 2025

What type of PR is this?
/kind bug

What this PR does / why we need it:

Since I have already created a container registry, I would like to register the image there. However, when I try to register the image using the command below, a new container named 'registry' is created, and the image is registered there instead.

# export DESTINATION_REGISTRY=192.168.122.155:5000 #Specify an existing container registry
# ./manage-offline-container-images.sh register
  • check containers
# podman ps -a
CONTAINER ID  IMAGE                              COMMAND               CREATED             STATUS       PORTS                   NAMES
d90b84b7c726  docker.io/library/registry:2.8.2   /etc/docker/regis...  15 hours ago        Up 15 hours  0.0.0.0:5000->5000/tcp  docker-distribution
b2ab51819745  docker.io/library/nginx:alpine     nginx -g daemon o...  15 hours ago        Up 15 hours  0.0.0.0:8080->80/tcp    nginx
61997afcca9e  docker.io/library/registry:latest  /etc/docker/regis...  About a minute ago  Created      0.0.0.0:5000->5000/tcp  registry

When I checked the script file (manage-offline-container-images.sh), it seemed that the container registry was being created using the following steps.

if [ "${create_registry}" ]; then
		sudo ${runtime} load -i ${IMAGE_DIR}/registry-latest.tar
		set +e

		sudo ${runtime} container inspect registry >/dev/null 2>&1
		if [ $? -ne 0 ]; then
			sudo ${runtime} run --restart=always -d -p "${REGISTRY_PORT}":"${REGISTRY_PORT}" --name registry registry:latest
		fi
		set -e
	fi

The create_registry above is determined by the following.

function register_container_images() {
	create_registry=false
	REGISTRY_PORT=${REGISTRY_PORT:-"5000"}

	if [ -z "${DESTINATION_REGISTRY}" ]; then
		echo "DESTINATION_REGISTRY not set, will create local registry"
		create_registry=true
		DESTINATION_REGISTRY="$(hostname):${REGISTRY_PORT}"
	fi
	echo "Images will be pushed to ${DESTINATION_REGISTRY}"

Originally, if a registry already exists and you want to push the image there, you need to set the registry address in REGISTRY_PORT. I understand that if REGISTRY_PORT is not set, it means a container registry is created in the local registry and the image is pushed there.

Based on the above settings, it is correct to not execute the procedure if create_registry is false, but to execute it if it is true. However, as shown in if [ "${create_registry}" ]; then, the procedure is designed to create a registry if the create_registry variable is set, meaning a local registry is created regardless of whether a push destination container registry is specified or not.

To fix the issue, the following changes are necessary.

if ${create_registry}; then

Which issue(s) this PR fixes:

Fixes #11867

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fix: Using the ./manage-offline-container-images.sh register command does not create a new container but registers the image in the existing container registry.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Feb 10, 2025
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 10, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DearJey
Once this PR has been reviewed and has the lgtm label, please assign ant31 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Hi @DearJey. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2025
@yankay
Copy link
Member

yankay commented Feb 12, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
3 participants