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

Add ctx command #455

Merged
merged 2 commits into from
Apr 15, 2024
Merged

Add ctx command #455

merged 2 commits into from
Apr 15, 2024

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Mar 27, 2024

2024-03-29 20 05 54

@sttts sttts force-pushed the sttts-poc-ctx branch 7 times, most recently from 587ebe6 to 778f75a Compare March 29, 2024 19:05
@sttts sttts changed the title WIP: Prototype ctx Add ctx command Mar 29, 2024
@sttts sttts force-pushed the sttts-poc-ctx branch 3 times, most recently from 87f677c to eb4042f Compare April 2, 2024 09:37
@sttts sttts force-pushed the sttts-poc-ctx branch 2 times, most recently from 4715dff to c024f97 Compare April 12, 2024 11:48
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Copy link
Member

@tnthornton tnthornton left a comment

Choose a reason for hiding this comment

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

Thanks @sttts ! Generally looks good to me. I'm not seeing anything fundamentally blocking, so I'm ok with moving forward with this and addressing my comments as follow ups 👍 (windows support, co-locating/isolating the kubeconfig interactions).


case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "ctrl+c", "esc":
Copy link
Member

Choose a reason for hiding this comment

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

Do we detect OS anywhere? If not we may need to since we have binaries being produced for mac, linux, and windows and this keypress can vary in expectation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aren't ctrl-c and esc universal?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't ctrl c in windows (copy) or did that change?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this is outdated. It's been awhile since I've worked in a windows environment 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cwilhit can you test the command with Windows (can be after merge) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, absolutely. ctrl + c sends SIGINT on Windows

kongCtx.Bind(upCtx)

if !upCtx.Profile.IsSpace() {
// TODO: add legacy support
Copy link
Member

Choose a reason for hiding this comment

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

This comment is instead in reference to SaaS rather than legacy?

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, SaaS. But we will rework all commands soonish, this included to talk to the Space API of cloud.

if err := os.MkdirAll(dir, 0755); err != nil { // nolint:gosec // it's ok
return errors.Wrap(err, "failed to create parent directories")
}
return os.WriteFile(path, []byte(value), 0644) // nolint:gosec // it's ok
Copy link
Member

Choose a reason for hiding this comment

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

Is this state file just tracking a single string?

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, the code is taken from kubectx.

if err != nil {
return "", err
}
if err := writeLastContext(prevContext); err != nil { // nolint:staticcheck
Copy link
Member

Choose a reason for hiding this comment

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

Something that's not quite clear yet, if we're storing the previous context in the kubeconfig, why do we also need to store its name in the ctx state file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make kubectl ctx - work.

return nil
}

func (c *Cmd) RunSwap(ctx context.Context, upCtx *upbound.Context) error { // nolint:gocyclo // TODO: shorten
Copy link
Member

@tnthornton tnthornton Apr 13, 2024

Choose a reason for hiding this comment

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

Between some of the logic I'm seeing in mergeIntoKubeConfig and the logic in here, I wonder if it would be beneficial to move these operations to the kubeconfig package and add functions like (simply examples):

  • Swap(a, b)
  • MergeInto(cfg, new, prev)

And then we can test those operations on their own and simplify some of these calling functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got more confused by the shared functions that exist, but are actually pretty special. I don't think these functions are suitable really for being shared.

Copy link
Member

Choose a reason for hiding this comment

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

I see. When I was reading through the operations, I mostly had an urge to:

  1. Not want to have to jump through these hopes somewhere else 😅
  2. Add tests specific to the operations - if for nothing else to ensure if something changes they fail.

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 lots of tests to the swap command. It was needed 😇

Signed-off-by: Dr. Stefan Schimanski <[email protected]>
@sttts sttts merged commit 879808e into upbound:main Apr 15, 2024
6 checks passed
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.

3 participants