Skip to content
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

✨ kubectl support ../../ & ..:..: #3088

Merged
merged 19 commits into from
Mar 31, 2024

Conversation

mjudeikis
Copy link
Contributor

@mjudeikis mjudeikis commented Mar 9, 2024

Summary

Enables to go back more than 1 workspace at the time ws use ../../
Enables to use tree in rootless clusters.

[mjudeikis@unknown2 kcp]$ k ws tree
.
kcp git:(mjudeikis/refactor.ws.use) k ws tree
.
└── kvdk2spgmbix
    └── test
        └── test1
            └── test2

➜  kcp git:(mjudeikis/refactor.ws.use) k ws use :
Current workspace is ':kvdk2spgmbix'.
➜  kcp git:(mjudeikis/refactor.ws.use) k ws use test:test1:test2
Current workspace is ':kvdk2spgmbix:test:test1:test2'.
➜  kcp git:(mjudeikis/refactor.ws.use) k ws use ../..
Current workspace is ':kvdk2spgmbix:test'.

Missing parts:

  1. ../../foo multiple actions together does not work
  2. no auto-completetion.

Related issue(s)

Release Notes

kcp ws use support for relative and absolute multi-step navigation 

@kcp-ci-bot kcp-ci-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 9, 2024
@mjudeikis
Copy link
Contributor Author

We need bigger story to refactor all this function to support syntax like:

ws use ../../foo
ws use ../../foo/bar

basically make it recursive and enable replace : with / for more linux native navigation,
and add alias to use ws cd :)

@kcp-ci-bot kcp-ci-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Mar 11, 2024
@mjudeikis
Copy link
Contributor Author

/test pull-kcp-test-e2e-shared

@mjudeikis mjudeikis changed the title ✨ kubectl support ../../ ✨ kubectl support ../../ & ..:..: Mar 11, 2024
@mjudeikis
Copy link
Contributor Author

@sttts is this missing smth?

@embik
Copy link
Member

embik commented Mar 14, 2024

Overall idea as per community meeting:

# absolute path
$ kubectl ws :adct:org-a:team-b
# relative path (called from within adct "root" workspace)
$ kubectl ws org-a:team-b
# relative path (starting from `.` current workspace)
$ kubectl ws .:org-a:team-b
# going from org-a "back" to org-a
$ kubectl ws ..:org-b:..:org-a

# we warn with this case because it's old behaviour
$ kubectl ws root:org-a
warn: did you mean :root:org-a?

@kcp-ci-bot kcp-ci-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 17, 2024
defer func() {
if err == nil {
_, err = fmt.Fprintf(o.Out, "Note: 'kubectl ws' now matches 'cd' semantics: go to home workspace. 'kubectl ws -' to go back. 'kubectl ws .' to print current workspace.\n")
}
}()
fallthrough

case "~", home:
homeWorkspace, err := o.kcpClusterClient.Cluster(core.RootCluster.Path()).TenancyV1alpha1().Workspaces().Get(ctx, "~", metav1.GetOptions{})
case o.Name == "~" || o.Name == home:
Copy link
Member

Choose a reason for hiding this comment

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

what about ~:foo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added support, just no test as need second run on it :/
~ not being resolved in tests to check if workspace exists gets bit complex in tests :./

@@ -407,7 +407,7 @@ func TestUse(t *testing.T) {
AuthInfos: map[string]*clientcmdapi.AuthInfo{"test": {Token: "test"}},
},
destination: "root:foo:bar",
wantStdout: []string{"Current workspace is \"root:foo:bar\""},
wantStdout: []string{"Current workspace is ':root:foo:bar'"},
Copy link
Member

Choose a reason for hiding this comment

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

am not convinced we want to print out the : at all. Let's keep the output always foo:bar:abc. The : prefix is only for navigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was one the line with this, so this pushes swings to same :) will remove

@mjudeikis mjudeikis closed this Mar 18, 2024
@kcp-ci-bot kcp-ci-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 18, 2024

case ".":
cfg, err := o.ClientConfig.ClientConfig()
case strings.Contains(o.Name, ".."):
Copy link
Member

Choose a reason for hiding this comment

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

this one looks fishy. Could see = "..", but anything beyond that needs some more logic, e.g. for ./../foo/../bar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this is not supported yet. Code code quite convoluted and wanna move it to separate pr. So this is not yet supported

// system is bit different. Usually when moving to system workspaces you
// need to have special access and "if workspace exists" checks fails.
// If merged to "absolute path check" code gets convoluted :/
case strings.HasPrefix(o.Name, ":system"):
Copy link
Member

Choose a reason for hiding this comment

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

We have a constant for system somewhere I believe.

Also here HasPrefix seems fishy. We have to properly split by ":".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea was not to trigger this path is somebody created root:system or foo:bar:system in any ways. So only way to access system from cli is to be explicit - :system.
Basically don't want this code path to be triggered by mistake by users.

Copy link
Member

Choose a reason for hiding this comment

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

My comment was about using string comparison. Convert it to a logical cluster path and operate on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated but this does not make it prettier in my opinion :D

@kcp-ci-bot kcp-ci-bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Mar 23, 2024
@mjudeikis
Copy link
Contributor Author

/retest

@mjudeikis
Copy link
Contributor Author

@sttts you ok merge without ../../foo ?


return currentWorkspace(o.Out, newServerHost, shortWorkspaceOutput(o.ShortWorkspaceOutput), nil)
// LEGACY(mjudeikis): Remove once everybody gets used to this
if o.Name == "home" || strings.HasPrefix(o.Name, core.RootCluster.String()+":") {
Copy link
Member

Choose a reason for hiding this comment

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

o.Name == home?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, that case is below. Did we have special "home" logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we did. I just kept it here. Maybe not needed anymore?

sttts and others added 4 commits March 31, 2024 11:02
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
✨ cli/workspace: implement full relative paths including . and ..
@kcp-ci-bot kcp-ci-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 31, 2024
@mjudeikis mjudeikis added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 31, 2024
@sttts
Copy link
Member

sttts commented Mar 31, 2024

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 31, 2024
@kcp-ci-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: bc436de3187f91a2036b315af462186fc0202c49

@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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

The pull request process is described 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

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2024
@mjudeikis mjudeikis merged commit e1c2fd9 into kcp-dev:main Mar 31, 2024
15 of 16 checks passed
@mjudeikis mjudeikis removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants