Skip to content

[CLI] feat: implement namespace-independent config storage for CLI #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

divyansh42
Copy link
Member

@divyansh42 divyansh42 commented Aug 18, 2025

Changes

This change ensures configuration persists across namespace operations, eliminating the need to reconfigure after switching namespaces.

  • Store CLI configuration in dedicated default namespace context to prevent loss during namespace switches (kubectl/oc project commands)
  • Use default/{cluster}/{user} context naming
  • Update unit test to include the behaviour changes
  • Update documentation to clarify one-time configuration per cluster/user

Fixes: Configuration loss when using 'oc project' or 'kubectl config set-context --namespace'

/kind feature

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you review them:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Tested your changes locally (if this is a code change)
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user-facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contain the string "action required" if the change requires additional action from users switching to the new release

Release Notes

[CLI] feat: Configuration now persists across namespace switches - no need to run 'tkn-results config set' again after switching namespaces

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Aug 18, 2025
@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign adambkaplan after the PR has been reviewed.
You can assign the PR to them by writing /assign @adambkaplan in a comment when ready.

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

Needs approval from an approver in each of these files:

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

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 18, 2025
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-results-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cli/config/config.go 65.9% 66.7% 0.7

@khrm khrm requested a review from Copilot August 18, 2025 08:30
Copy link

@Copilot 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 implements namespace-independent configuration storage for the Tekton Results CLI to prevent configuration loss when switching namespaces using commands like kubectl config set-context --namespace or oc project.

  • Store CLI configuration in dedicated default namespace contexts with the format default/{cluster}/{user}
  • Update configuration loading and persistence logic to use namespace-independent storage
  • Add comprehensive test coverage for namespace independence behavior and config context creation

Reviewed Changes

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

Show a summary per file
File Description
pkg/cli/config/config.go Implements namespace-independent config storage using dedicated contexts
pkg/cli/testutils/kubeconfig.go Adds test utilities for namespace handling and kubeconfig manipulation
pkg/cli/config/config_test.go Updates test calls to use new kubeconfig creation signature
pkg/cli/cmd/config/set_test.go Adds comprehensive tests for namespace independence behavior
pkg/cli/cmd/config/view_test.go Updates test calls to use new kubeconfig creation signature
pkg/cli/cmd/config/reset_test.go Updates test calls to use new kubeconfig creation signature
pkg/cli/cmd/config/set.go Updates documentation to explain namespace-independent storage
docs/man/man1/tkn-results-config-set.1 Updates man page with configuration storage explanation
docs/cli/tkn-results_config_set.md Updates CLI documentation with configuration storage explanation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// Construct the config context name (default namespace context for config storage)
configContextName = "default/" + clusterName + "/" + userName
return configContextName, clusterName, userName, nil
}

Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The cluster and user names are used directly in the context name without validation. If these contain forward slashes or other special characters, it could lead to naming conflicts or unexpected behavior.

Suggested change
// Sanitize clusterName and userName to avoid problematic characters
safeClusterName := sanitizeName(clusterName)
safeUserName := sanitizeName(userName)
// Construct the config context name (default namespace context for config storage)
configContextName = "default/" + safeClusterName + "/" + safeUserName
return configContextName, clusterName, userName, nil
}
// sanitizeName replaces any character that is not a-z, A-Z, 0-9, dash, or underscore with an underscore.
func sanitizeName(name string) string {
re := regexp.MustCompile(`[^a-zA-Z0-9_-]`)
return re.ReplaceAllString(name, "_")
}

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed this for the user field, I don't see a use case in removing the special characters.

@divyansh42 divyansh42 force-pushed the store-default-ns branch 2 times, most recently from e94a049 to d8616f2 Compare August 18, 2025 11:32
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-results-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cli/common/utils.go Do not exist 0.0%
pkg/cli/config/config.go 65.9% 66.5% 0.5

@divyansh42
Copy link
Member Author

/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 18, 2025
- Store CLI configuration in dedicated default namespace context to prevent
  loss during namespace switches (kubectl/oc project commands)
- Use default/{cluster}/{user} context naming
- Update unit test to include the behaviour changes
- Update documentation to clarify one-time configuration per cluster/user

This change ensures configuration persists across namespace operations,
eliminating the need to reconfigure after switching namespaces.

Fixes: Configuration loss when using 'oc project' or 'kubectl config set-context --namespace'

Signed-off-by: divyansh42 <[email protected]>
@divyansh42
Copy link
Member Author

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 22, 2025
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-results-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cli/common/utils.go Do not exist 0.0%
pkg/cli/config/config.go 65.9% 66.5% 0.5

@divyansh42
Copy link
Member Author

/cc @khrm @enarha @aThorp96

@tekton-robot tekton-robot requested a review from khrm August 22, 2025 19:18
@tekton-robot
Copy link

@divyansh42: GitHub didn't allow me to request PR reviews from the following users: aThorp96.

Note that only tektoncd members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @khrm @enarha @aThorp96

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/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants