Skip to content

Conversation

@mzihlmann
Copy link
Collaborator

This is a refactoring in preparation for #334

Description

When we create KanikoStage's we replace all baseImage references with numeric references. But we keep both named and numeric references in COPY --from. ie COPY --from=base or COPY --from=0 (yes this is valid syntax). Later we replace those references a bit hidden as part of ResolveCrossStageInstructions. With this change we just move that transformation to the beginning, so when you have a KanikoStage you are guaranteed to only have numeric references to other stages.

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.

See the contribution guide for more details.

Reviewer Notes

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

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Examples of user facing changes:
- kaniko adds a new flag `--registry-repo` to override registry

@mzihlmann
Copy link
Collaborator Author

mzihlmann commented Oct 25, 2025

note that this temporarily makes the whole ONBUILD situation worse #332
Maybe we should fix that first as a priority before taking this refactoring. On the other hand I don't expect a single person to actually run into this bug as it appears a pretty useless feature in the spec to me.

Well no, currently you can workaround that issue by not taking any optimizations, ie. --skip-unused-stages=false. If we do this refactoring that is no longer possible and it starts to break for them too. So let's push this out a bit.

@mzihlmann mzihlmann force-pushed the mz334-cache-lookahead-refactoring-part-2 branch from c4959c5 to 21a4da2 Compare October 25, 2025 07:32
@mzihlmann mzihlmann marked this pull request as draft October 25, 2025 07:34
@babs babs requested a review from Copilot October 28, 2025 07:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the handling of cross-stage command resolution by moving the transformation of named stage references to numeric indices earlier in the build process. Instead of resolving COPY --from=<stage_name> to COPY --from=<index> later during ResolveCrossStageInstructions, this transformation now happens immediately when KanikoStage objects are created in MakeKanikoStages.

Key changes:

  • Cross-stage command resolution moved from ResolveCrossStageInstructions to MakeKanikoStages
  • Simplified fetchExtraStages to only handle numeric stage references and remote images
  • Updated skipUnusedStages to remove named reference handling logic

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
pkg/executor/build.go Removed named stage tracking in fetchExtraStages and call to ResolveCrossStageCommands in ResolveCrossStageInstructions
pkg/dockerfile/dockerfile.go Made ResolveCrossStageCommands private, added stage name resolution in MakeKanikoStages, simplified skipUnusedStages
pkg/dockerfile/dockerfile_test.go Updated tests to use MakeKanikoStages and set feature flag environment variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mzihlmann mzihlmann force-pushed the mz334-cache-lookahead-refactoring-part-2 branch from f287003 to 456a9cf Compare November 3, 2025 11:05
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