Skip to content

Fix Kptfile pipeline merge for function images from a registry with a port - #4889

Open
bhavishyajain545 wants to merge 3 commits into
kptdev:mainfrom
bhavishyajain545:fix/kptfile-merge-key-registry-port
Open

bhavishyajain545 wants to merge 3 commits into
kptdev:mainfrom
bhavishyajain545:fix/kptfile-merge-key-registry-port

Conversation

@bhavishyajain545

Copy link
Copy Markdown

Description

When the functions in a Kptfile pipeline have no name, MergeKptfiles (used by kpt pkg update) merges them by a synthesized key: the function image without its tag. shouldAddFnKeyUtil and addName in pkg/kptfile/kptfileutil/util.go took that key as the text before the first colon:

key = strings.Split(fn.Image, ":")[0]

For an image from a registry with a port, such as registry.example.com:5000/krm/apply-setters:v0.2, the key is registry.example.com. Two functions from that registry get the same key, shouldAddFnKeyUtil sees a duplicate and returns false, and no merge keys are used at all.

This PR adds imageMergeKey, which strips the tag only when its colon comes after the last /, and also strips a digest. Results for images without a registry port are unchanged.

Motivation

Without merge keys the local pipeline is replaced by the upstream one, so local changes are lost on kpt pkg update. The new TestMerge case shows it: two functions from registry.example.com:5000, upstream adds a setter, local changes tag to 1.2.0. On main the result has tag: 1.0.1 (the local change is gone); with this PR it has the upstream setter and tag: 1.2.0, the same as the existing ghcr.io case.

Fixes

No linked issue. I searched the issues and PRs for this and found no report.

Tests

  • New TestMerge case functions from a registry with a port are merged by image name (fails on main, passes with the fix).
  • New TestImageMergeKey table test.
  • go vet ./pkg/kptfile/kptfileutil/ and go test ./pkg/kptfile/... pass locally.

Use of AI

I have used AI in the creation of this PR.

I have used the following AI tools:

  • Claude Code to find the bug, write the fix and the tests, and draft this description

… port

The merge key of a function without a name is its image without the tag.
It was taken as the text before the first colon, so every image from a
registry with a port, such as registry.example.com:5000/krm/apply-setters:v0.2,
got the key "registry.example.com". With two such functions the keys
collided, no merge keys were used, and kpt pkg update replaced the local
pipeline with the upstream one, dropping local changes.

Strip the tag after the last colon that follows the last slash, and strip a
digest.

Signed-off-by: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com>
@bhavishyajain545
bhavishyajain545 requested review from a team and a balanced review from Copilot November 21, 2026 11:45
@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kptdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c18356b
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6b096a0451f83ebfe394f994
😎 Deploy Preview https://deploy-preview-4889--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the registry-port pipeline merge fix.

No open issues 🎉

What changed in this PR

This PR fixes pipeline merging during kpt pkg update for unnamed functions whose images come from registries with ports, preserving local configuration changes alongside upstream updates.

Changes:

  • Adds a shared image merge-key helper that preserves registry ports while removing tags and digests.
  • Uses the helper for duplicate detection and synthesized function names.
  • Adds a merge regression test and table-driven tests for image formats.
File Description
pkg/​kptfile/​kptfileutil/​util.go Centralizes image merge-key generation and preserves registry ports.
pkg/​kptfile/​kptfileutil/​util_test.go Adds registry-port merge coverage and image merge-key tests; updates the copyright year range.

Review effort: Balanced

@bhavishyajain545

Copy link
Copy Markdown
Author

The failing Go, Live Apply and Live E2E jobs do not come from this change. main at 30c8999 fails the same way on its own:

$ go build ./pkg/lib/krmvalidate/
pkg/lib/krmvalidate/iskrm.go:41:15: undefined: kptfilev1.IsKustomization

The root go.mod requires github.com/kptdev/kpt/api v1.1.1-pre.2 (the replace => ./api line is commented out), and that published version does not have IsKustomization; it only exists in api/ on main. This PR only touches pkg/kptfile/kptfileutil. I can rebase once main builds again.

…-registry-port

Signed-off-by: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com>
@bhavishyajain545

Copy link
Copy Markdown
Author

main builds again after #4891, so I merged it into this branch (894ecef). The build and the pkg/kptfile and pkg/lib/krmvalidate tests pass locally on Linux. Could a maintainer approve the workflow runs?

Comment thread pkg/kptfile/kptfileutil/util_test.go Resolved
Signed-off-by: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com>
@aravindtga

Copy link
Copy Markdown
Contributor

@bhavishyajain545 Thanks for the fix and your contribution.

Could you please join our slack and one of the weekly community meetings to talk about your PR briefly?

(See https://github.com/kptdev/kpt#contact on how to join)

@sonarqubecloud

Copy link
Copy Markdown

@bhavishyajain545

Copy link
Copy Markdown
Author

Thanks! I have requested an invite to the Kubernetes Slack and it is still pending; I will join #kpt as soon as it comes through, and I will join one of the weekly community meetings to talk about the PR. If the invite takes long, is there another way to reach you before the meeting?

This branch has not been deployed

No deployments
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.

3 participants