Skip to content

feat(control): enable kubectl completion #492

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pau-hedgehog
Copy link
Contributor

No description provided.

@pau-hedgehog pau-hedgehog self-assigned this Mar 25, 2025
@pau-hedgehog pau-hedgehog force-pushed the kubectl_autocomplete branch from f3a9153 to addecef Compare March 25, 2025 14:10

versionStr := strings.TrimPrefix(string(Version(fab)), "v")

tempExtractDir := fmt.Sprintf("/tmp/bash-completion-%s", versionStr)
Copy link
Member

Choose a reason for hiding this comment

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

temp dir should be created using tmp, err := os.MkdirTemp("", "some") followed by deferred cleanup defer os.RemoveAll(tmp)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we embed the script it doesn't apply anymore


listCmd := exec.CommandContext(ctx, "tar", "-tvf", tarballPath)
listCmd.Dir = workDir
listCmd.Stdout = logutil.NewSink(ctx, slog.Debug, "tarball contents: ")
Copy link
Member

Choose a reason for hiding this comment

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

logutil's sink should always be used in a func with out ctx with deferred cancel as it spawns a background goroutine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was for debug purposes. The advice is very welcome, though. Thanks

@@ -208,6 +209,15 @@ func (b *ControlInstallBuilder) Build(ctx context.Context) error {
return fmt.Errorf("downloading cert-manager: %w", err)
}

slog.Info("Adding bash-completion to installer", "control", b.Control.Name)
if err := b.Downloader.FromORAS(ctx, installDir, bashcompletion.BashCompletionRef, bashcompletion.Version(b.Fab), []artificer.ORASFile{
Copy link
Member

Choose a reason for hiding this comment

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

how are we getting contents of that 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.

I pushed to zot manually for testing purposes. I wanted to discuss next steps when I make it work. I made a mistake with the artifact itself

@pau-hedgehog pau-hedgehog force-pushed the kubectl_autocomplete branch from 998278e to 4f4a937 Compare March 28, 2025 17:27
@@ -0,0 +1,3981 @@
# -*- shell-script -*-
Copy link
Member

Choose a reason for hiding this comment

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

scop/bash-completion seems to be under GPL-2.0 license, so we can't include it in our repo

Copy link
Contributor Author

@pau-hedgehog pau-hedgehog Mar 28, 2025

Choose a reason for hiding this comment

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

Oh, good catch. Removed it. We would need this artifact uploaded with tag v2.16.0, then:

bash_completion.zip

eg: oras push REG:PORT/githedgehog/bash-completion:v2.16.0 --artifact-type text/plain bash_completion

add bash completion as external component

control node completes kubectl commands and parameters
via bash completion

kubectl fabric will be autocompleted also when it is
supported

Signed-off-by: Pau Capdevila <pau@githedgehog.com>
@pau-hedgehog pau-hedgehog force-pushed the kubectl_autocomplete branch from 4f4a937 to 61bed38 Compare March 28, 2025 18:04
@Frostman
Copy link
Member

Frostman commented May 6, 2025

@pau-hedgehog that seems to become stale, should we close it for now? thx

@pau-hedgehog
Copy link
Contributor Author

pau-hedgehog commented May 6, 2025

@pau-hedgehog that seems to become stale, should we close it for now? thx

I think this one is quite convenient for usability. But I was blocked as I cannot push to m-pub:

Build fails because the artifact is not pushed in m-pub.

If you don't think this adds value now, you can close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants