Skip to content

fix: Add stdin support to kpt fn doc for KRM functions expecting input#4352

Open
pmady wants to merge 1 commit intokptdev:mainfrom
pmady:fix/fn-doc-help-flag-support
Open

fix: Add stdin support to kpt fn doc for KRM functions expecting input#4352
pmady wants to merge 1 commit intokptdev:mainfrom
pmady:fix/fn-doc-help-flag-support

Conversation

@pmady
Copy link

@pmady pmady commented Jan 15, 2026

Some KRM functions fail with 'kpt fn doc' because they try to parse input from stdin even when --help flag is provided, resulting in the error: 'failed to parse input bytes: expected exactly one object, got 0'

This fix provides an empty ResourceList as stdin when running containers with --help flag, allowing functions that expect input to work properly while still displaying help documentation.

Changes:

  • Add -i and --stdin flags to docker run command
  • Provide empty ResourceList YAML structure as stdin
  • Prevents 'expected exactly one object' errors for functions like set-namespace, set-labels, etc.

Fixes #4278

Some KRM functions fail with 'kpt fn doc' because they try to parse
input from stdin even when --help flag is provided, resulting in the
error: 'failed to parse input bytes: expected exactly one object, got 0'

This fix provides an empty ResourceList as stdin when running containers
with --help flag, allowing functions that expect input to work properly
while still displaying help documentation.

Changes:
- Add -i and --stdin flags to docker run command
- Provide empty ResourceList YAML structure as stdin
- Prevents 'expected exactly one object' errors for functions like
  set-namespace, set-labels, etc.

Fixes kptdev#4278

Signed-off-by: pmady <[email protected]>
@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 5d35100
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69691eece836e4000746a791
😎 Deploy Preview https://deploy-preview-4352--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@efiacor
Copy link
Contributor

efiacor commented Jan 21, 2026

Hi @pmady ,
Thanks for your contribution.
Should we not try to address the underlying failure on the relevant krm functions.
The list of failing functions (that need a fix) is probably quite a bit smaller as we not longer support some of them.
ie. set-gcp-resource-ids
#4278

@pmady
Copy link
Author

pmady commented Jan 22, 2026

Hi @efiacor, thanks for the feedback!

You raise a valid point. I considered both approaches:

Option 1: Fix individual KRM functions (your suggestion)

  • Pros: Addresses the root cause in each function
  • Cons: Requires changes across multiple function repositories/images, and each function maintainer would need to update their code to handle --help without requiring stdin

Option 2: Fix in kpt fn doc (this PR)

  • Pros: Single fix that works for all functions (current and future), backward-compatible, no changes needed in individual function repositories
  • Cons: Slightly masks the underlying behavior of functions that don't handle --help gracefully

I went with Option 2 because:

  • It provides immediate relief for users hitting this issue
  • It's a common pattern - many CLI tools provide empty/minimal input when invoking help
  • It doesn't break any existing functionality
  • Future KRM functions automatically benefit without needing to implement special --help handling

That said, I'm happy to close this PR if the team prefers fixing the individual functions instead. Let me know which approach you'd like to proceed with!

@efiacor
Copy link
Contributor

efiacor commented Jan 22, 2026

Hi @efiacor, thanks for the feedback!

You raise a valid point. I considered both approaches:

Option 1: Fix individual KRM functions (your suggestion)

* Pros: Addresses the root cause in each function

* Cons: Requires changes across multiple function repositories/images, and each function maintainer would need to update their code to handle `--help` without requiring stdin

Option 2: Fix in kpt fn doc (this PR)

* Pros: Single fix that works for all functions (current and future), backward-compatible, no changes needed in individual function repositories

* Cons: Slightly masks the underlying behavior of functions that don't handle `--help` gracefully

I went with Option 2 because:

* It provides immediate relief for users hitting this issue

* It's a common pattern - many CLI tools provide empty/minimal input when invoking help

* It doesn't break any existing functionality

* Future KRM functions automatically benefit without needing to implement special `--help` handling

That said, I'm happy to close this PR if the team prefers fixing the individual functions instead. Let me know which approach you'd like to proceed with!

Hey,
Thanks for the clarification.
I'm ok with going ahead with this, but we should prob try to capture the functions that remain to be fixed properly.
This is the "official" list of supported functions. I think a lot of the broken ones listed previously have been deprecated/unsupported.
Could we create an issue to track those changes?

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.

The "kpt fn doc" command only works on some krm functions

2 participants