Skip to content

Conversation

@pablintino
Copy link
Contributor

This change extracts some containers/image common logic to a dedicated image utils package to improve reusability.

- What I did

Extract shared image utilities into pkg/imageutils to eliminate code duplication

- How to verify it

pre-submit tests and UTs should cover the changes.

- Description for the changelog

Extract shared image utilities into pkg/imageutils to eliminate code duplication

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 10, 2025
return nil, nil, fmt.Errorf("error retrieving image digest: %q: %w", imageName, err)
}

defer src.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this line a bit earlier as I think that the previous error conditions may make the function return without proper cleanup.


if err := retry.RetryIfNecessary(ctx, func() error {
var imgInspect *types.ImageInspectInfo
if err := retry.IfNecessary(ctx, func() error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to IfNecessary as I saw we were already using it and RetryIfNecessary is deprecated.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch! 💯 I think there are a few things we use in our code base that are deprecated. Maybe a good task for AI would be getting it to find what's deprecated and suggest solutions. 🤔 Maybe I'll try that out once the release freeze is behind us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I catched it myself this time, but Claude has already told me about deprecated code. When I was coding the mco-sanitize Claude told me the GPG packet was about to be discontinued.
If you have the time... Everybody will welcome your effort :)

temporalDir: temporalDir,
}

certsDir, err := sysContext.buildCertsFromControllerConfig(cc)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really relevant change in this copied code: We were using a Deepcopy of the ControllerConfig as we were calling UpdateControllerConfigCerts.
That function, UpdateControllerConfigCerts, would require a revisit to clean up it (I don't know why it's removing certs from the controller FS, well, I know, it's because the remove logic was used as part ofr UTs, that never were shipped, but.... The cleanup logic and the wrongly performed computation of the modified flag require a cleanup too).
From the point of view of this function, it consumed the Spec side of the ControllerConfig, that is never modified so calling UpdateControllerConfigCerts makes no effect on Spec.ImageRegistryBundleData or Spec.ImageRegistryBundleUserData and thus, calling UpdateControllerConfigCerts is not required.

Copy link
Member

@cheesesashimi cheesesashimi Nov 10, 2025

Choose a reason for hiding this comment

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

So, the reason why the previous code used a DeepCopy() was to avoid accidentally mutating the lister cache when we mutate the ControllerConfig. I just wanted to add that extra bit of context here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// writeCertFromImageRegistryBundle writes a certificate from an image registry bundle
// to the specified certificates directory. Path traversal attempts (..) are sanitized to colons.
func writeCertFromImageRegistryBundle(certsDir string, irb mcfgv1.ImageRegistryBundle) error {
caFile := strings.ReplaceAll(irb.File, "..", ":")
Copy link
Member

Choose a reason for hiding this comment

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

praise: Great idea!

In general, I think we all could do a lot better with practices like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. It's just a copy of what you did, and what I see we are doing in the daemon. It can be improved, as that replace may lead to some awful paths, but I'd prefer to stick to what we have to, at least, be consistent.

Copy link
Member

Choose a reason for hiding this comment

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

Another thing we could consider in the future is this: https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516. As a caveat, we won't be able to backport anything that uses it beyond 4.19 since it requires Golang 1.24+.

(Just to be clear: I'm not asking you to adopt that solution here. 😄)

legacySecret := `{"registry.hostname.com": {"username": "user", "password": "s3kr1t", "auth": "s00pers3kr1t", "email": "[email protected]"}}`
newSecret := `{"auths":` + legacySecret + `}`

testCert := []byte(`-----BEGIN CERTIFICATE-----
Copy link
Member

Choose a reason for hiding this comment

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

thought (non-blocking): We may need to add a comment here to make the linter happy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which linter is blaming? The CI ones are passing.

Copy link
Member

Choose a reason for hiding this comment

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

If it's happy, then we don't need anything 😄. I just thought I'd mention it preemptively since I've had gosec complain about things like that in the past.


// fakeImageInspector is a fake image inspector implementation used for testing
// the ImagePruner without requiring an actual image registry.
type fakeImageInspector struct {
Copy link
Member

Choose a reason for hiding this comment

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

issue: We may want to keep this fakeImageInspector implementation around along with a subset of the assertions that we make about the ImagePruner doing its job. However, they can be much higher-level than they are before making this change. They can just ensure that ImageInspect() and DeleteImage() get called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I'll fix this tomorrow's morning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This change extracts some containers/image common logic to a dedicated
image utils package to improve reusability.
@pablintino pablintino changed the title [MCO-1956] Extract image utils from build package MCO-1956: Extract image utils from build package Nov 12, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Nov 12, 2025
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Nov 12, 2025

@pablintino: This pull request references MCO-1956 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

In response to this:

This change extracts some containers/image common logic to a dedicated image utils package to improve reusability.

- What I did

Extract shared image utilities into pkg/imageutils to eliminate code duplication

- How to verify it

pre-submit tests and UTs should cover the changes.

- Description for the changelog

Extract shared image utilities into pkg/imageutils to eliminate code duplication

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 openshift-eng/jira-lifecycle-plugin repository.

Copy link
Member

@isabella-janssen isabella-janssen left a comment

Choose a reason for hiding this comment

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

/lgtm

This change looks clean to me & previous comments have been addressed.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 12, 2025
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: isabella-janssen, pablintino

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [isabella-janssen,pablintino]

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

@pablintino
Copy link
Contributor Author

/test e2e-gcp-op-ocl

@sergiordlr
Copy link
Contributor

/payload periodic-ci-openshift-openshift-tests-private-release-4.21-amd64-nightly-aws-ipi-longduration-mco-p3-f7

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 13, 2025

@sergiordlr: it appears that you have attempted to use some version of the payload command, but your comment was incorrectly formatted and cannot be acted upon. See the docs for usage info.

@sergiordlr
Copy link
Contributor

/payload-job periodic-ci-openshift-openshift-tests-private-release-4.21-amd64-nightly-aws-ipi-longduration-mco-p3-f7

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 13, 2025

@sergiordlr: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-openshift-tests-private-release-4.21-amd64-nightly-aws-ipi-longduration-mco-p3-f7

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/82a1d740-c070-11f0-94a5-37979c3da954-0

@sergiordlr
Copy link
Contributor

No issues found in the automated regression. All failed tests were known.

/label qe-approved
/verified by @sergiordlr

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Nov 14, 2025
@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Nov 14, 2025
@openshift-ci-robot
Copy link
Contributor

@sergiordlr: This PR has been marked as verified by @sergiordlr.

In response to this:

No issues found in the automated regression. All failed tests were known.

/label qe-approved
/verified by @sergiordlr

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Nov 14, 2025

@pablintino: This pull request references MCO-1956 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

In response to this:

This change extracts some containers/image common logic to a dedicated image utils package to improve reusability.

- What I did

Extract shared image utilities into pkg/imageutils to eliminate code duplication

- How to verify it

pre-submit tests and UTs should cover the changes.

- Description for the changelog

Extract shared image utilities into pkg/imageutils to eliminate code duplication

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD ca0c19d and 2 for PR HEAD e712da2 in total

@pablintino
Copy link
Contributor Author

/test e2e-hypershift

@pablintino
Copy link
Contributor Author

/override ci/prow/e2e-hypershift

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 17, 2025

@pablintino: Overrode contexts on behalf of pablintino: ci/prow/e2e-hypershift

In response to this:

/override ci/prow/e2e-hypershift

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.

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD 661e30e and 1 for PR HEAD e712da2 in total

@isabella-janssen
Copy link
Member

/retest-required

1 similar comment
@pablintino
Copy link
Contributor Author

/retest-required

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD b3e3c8a and 0 for PR HEAD e712da2 in total

@openshift-ci-robot
Copy link
Contributor

/hold

Revision e712da2 was retested 3 times: holding

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 18, 2025
@pablintino
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 18, 2025
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD b3e3c8a and 2 for PR HEAD e712da2 in total

@pablintino
Copy link
Contributor Author

/retest-required

1 similar comment
@pablintino
Copy link
Contributor Author

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 18, 2025

@pablintino: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/bootstrap-unit e712da2 link false /test bootstrap-unit

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD d151372 and 1 for PR HEAD e712da2 in total

@openshift-merge-bot openshift-merge-bot bot merged commit 3ca2fc0 into openshift:main Nov 19, 2025
8 of 16 checks passed
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD 3ca2fc0 and 0 for PR HEAD e712da2 in total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. qe-approved Signifies that QE has signed off on this PR verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants