-
Notifications
You must be signed in to change notification settings - Fork 85
[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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
The following is the coverage report on the affected files.
|
There was a problem hiding this 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 | ||
} | ||
|
There was a problem hiding this comment.
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.
// 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.
There was a problem hiding this comment.
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.
e94a049
to
d8616f2
Compare
The following is the coverage report on the affected files.
|
/hold |
d8616f2
to
68ca4f3
Compare
- 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]>
68ca4f3
to
059e9fd
Compare
/hold cancel |
The following is the coverage report on the affected files.
|
@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. |
Changes
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'
/kind feature
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you review them:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes