Skip to content

Fix set-namespace to fail on invalid configuration#1254

Open
aravindtga wants to merge 1 commit into
kptdev:mainfrom
Nordix:fix-set-namespace-empty-config-exit-code
Open

Fix set-namespace to fail on invalid configuration#1254
aravindtga wants to merge 1 commit into
kptdev:mainfrom
Nordix:fix-set-namespace-empty-config-exit-code

Conversation

@aravindtga
Copy link
Copy Markdown
Contributor

@aravindtga aravindtga commented May 29, 2026

set-namespace was exiting 0 and reporting [PASS] when configuration was invalid (e.g., empty namespace), while simultaneously emitting an error-severity result.

Closes #4547

Root cause:

The Run function in transformer/namespace.go returned true, nil on config error, signaling success to the framework:

  if err != nil {
      rl.Results = append(rl.Results, fn.ErrorConfigObjectResult(err, rl.FunctionConfig))
      return true, nil  // ← bug: should signal failure
  }

Fix:

Changed return true, nil to return false, nil so the framework correctly reports the function as failed (exit code 1, [FAIL]).

Before:

  [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest"
  [PASS] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s
  [Results]: [error] v1/ConfigMap/function-input: `data.namespace` should not be empty
  Exit code: 0

After:

  [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest"
  [FAIL] "ghcr.io/kptdev/krm-functions-catalog/set-namespace:latest" in 0s
  [Results]: [error] v1/ConfigMap/function-input: `data.namespace` should not be empty
  Exit code: 1

Testing:

  • Updated tests to test the behaviour

Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 29, 2026

Deploy Preview for krm-function-catalog canceled.

Name Link
🔨 Latest commit 34512bc
🔍 Latest deploy log https://app.netlify.com/projects/krm-function-catalog/deploys/6a19890a3c45420007645e9c

@aravindtga aravindtga self-assigned this May 29, 2026
@aravindtga aravindtga marked this pull request as ready for review May 29, 2026 12:51
Copilot AI review requested due to automatic review settings May 29, 2026 12:51
@aravindtga aravindtga requested a review from efiacor as a code owner May 29, 2026 12:51
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Changes the set-namespace function to return a failure exit code when the function configuration is invalid or missing, instead of silently succeeding.

Changes:

  • Return false (failure) from Run when tc.Config fails, so the function exits non-zero.
  • Updated expected test results to reflect the new non-zero exit code and error output.

Reviewed changes

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

File Description
functions/go/set-namespace/transformer/namespace.go Return false on config error to signal failure.
functions/go/set-namespace/tests/no-fnconfig-resource/.expected/results.yaml Updated expected exitCode/stderr to 1.
functions/go/set-namespace/tests/no-fnconfig-resource/.expected/diff.patch Updated expected Kptfile rendered status to RenderFailed.
functions/go/set-namespace/tests/no-fnconfig-resource/.expected/config.yaml New expected config with exitCode 1.

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

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.

set-namespace exits 0 and reports [PASS] when config is invalid

2 participants