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

container: Fix version for staged container updates #4951

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/daemon/rpmostreed-deployment-utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,25 @@ rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment,
g_autoptr (GPtrArray) rpmmd_modified_new = NULL;

bool container_changed = false;
if (refspectype == rpmostreecxx::RefspecType::Container)
{
// Make this an operation we allow to fail, see the other call
try
{
auto state = rpmostreecxx::query_container_image_commit (*repo, current_checksum);
container_changed
= rpmostreecxx::deployment_add_manifest_diff (*dict, state->cached_update_diff);
if (state->cached_update_diff.version.size () > 0)
g_variant_dict_insert (dict, "version", "s",
state->cached_update_diff.version.c_str ());
g_debug ("container changed: %d", container_changed);
}
catch (std::exception &e)
{
sd_journal_print (LOG_ERR, "failed to query container image base metadata: %s",
e.what ());
}
}

if (staged_deployment)
{
Expand Down Expand Up @@ -778,25 +797,6 @@ rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment,
if (!ostree_parse_refspec (r.refspec.c_str (), &origin_remote, &origin_ref, error))
return FALSE;
}
else
{
// Make this an operation we allow to fail, see the other call
try
{
auto state = rpmostreecxx::query_container_image_commit (*repo, current_checksum);
container_changed
= rpmostreecxx::deployment_add_manifest_diff (*dict, state->cached_update_diff);
if (state->cached_update_diff.version.size () > 0)
g_variant_dict_insert (dict, "version", "s",
state->cached_update_diff.version.c_str ());
g_debug ("container changed: %d", container_changed);
}
catch (std::exception &e)
{
sd_journal_print (LOG_ERR, "failed to query container image base metadata: %s",
e.what ());
}
}

/* check that it's actually layered (i.e. the requests are not all just dormant) */
if (sack && is_new_layered && rpmostree_origin_has_packages (origin))
Expand Down
61 changes: 57 additions & 4 deletions tests/kolainst/destructive/container-update-check
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ EOF
ostree container encapsulate --repo=/ostree/repo ${checksum} "${image}" --label ostree.bootable=TRUE

skopeo copy $image containers-storage:localhost/fcos
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
FROM localhost/fcos
RUN rpm-ostree install man
LABEL org.opencontainers.image.version 2
Expand All @@ -106,6 +106,7 @@ EOF
rm -vf /etc/resolv.conf
fi

# This tests that updates are properly found and cached
rpm-ostree upgrade --check > out.txt
assert_file_has_content_literal out.txt 'AvailableUpdate:'
assert_file_has_content_literal out.txt 'Total layers:'
Expand All @@ -123,4 +124,56 @@ EOF
assert_file_has_content_literal out.txt '"version": "2"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

# This tests that staged updates versions are properly reported
rpm-ostree upgrade
sudo systemctl restart rpm-ostreed.service
rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
assert_file_has_content_literal out.txt '"removed-size":'
assert_file_has_content_literal out.txt '"total-size":'
assert_file_has_content_literal out.txt '"total":'
assert_file_has_content_literal out.txt '"added-size":'
assert_file_has_content_literal out.txt '"version": "2"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

# This tests that a further update is properly reported if there is already a staged update
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
FROM localhost/fcos
RUN touch /usr/foo
LABEL org.opencontainers.image.version 3
EOF

touched_resolv_conf=0
if test '!' -f /etc/resolv.conf; then
podmanv=$(podman --version)
case "${podmanv#podman version }" in
3.*) touched_resolv_conf=1; touch /etc/resolv.conf;;
esac
fi
podman build --net=host -t localhost/fcos-derived --squash .
if test "${touched_resolv_conf}" -eq 1; then
rm -vf /etc/resolv.conf
fi

rpm-ostree upgrade --check > out.txt
assert_file_has_content_literal out.txt 'AvailableUpdate:'
assert_file_has_content_literal out.txt 'Total layers:'
assert_file_has_content_literal out.txt 'Size:'
assert_file_has_content_literal out.txt 'Removed layers:'
assert_file_has_content_literal out.txt 'Added layers:'

rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
assert_file_has_content_literal out.txt '"removed-size":'
assert_file_has_content_literal out.txt '"total-size":'
assert_file_has_content_literal out.txt '"total":'
assert_file_has_content_literal out.txt '"added-size":'
assert_file_has_content_literal out.txt '"version": "3"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

esac
Loading