diff --git a/.krew.yaml b/.krew.yaml index bfa7696..6fa0374 100644 --- a/.krew.yaml +++ b/.krew.yaml @@ -30,19 +30,14 @@ spec: arch: arm64 {{addURIAndSha "https://github.com/machine424/vifal/releases/download/{{ .TagName }}/kubectl-vifal_{{ .TagName }}_darwin_arm64.tar.gz" .TagName }} bin: kubectl-vifal - shortDescription: exposing and unifying Kubernetes container filesystems locally + shortDescription: Expose and unify container filesystems locally description: | - FUSE mount that exposes and unifies Kubernetes container filesystems locally. - Browse namespaces, pods, and containers as directories, read files, and diff - configs across pods using standard shell tools. + FUSE filesystem that exposes Kubernetes container filesystems locally. + Browse namespaces, pods, and containers as directories, read files, + and diff configs across pods using standard shell tools. caveats: | Requires FUSE: - Linux: install fuse3 - macOS: install macFUSE (https://github.com/macfuse/macfuse) Containers must have sh, stat, find, and dd available. - - Usage: - kubectl vifal /mnt/my-cluster - ls /mnt/my-cluster//// - kubectl vifal unmount /mnt/my-cluster diff --git a/main.go b/main.go index 5c8409d..ad57780 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ import ( "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" listerscorev1 "k8s.io/client-go/listers/core/v1" + _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" @@ -60,6 +61,16 @@ var ( statCmdSuffix = "-maxdepth 1 -exec stat -c '%n\x1d%i\x1d%s\x1d%b\x1d%X\x1d%Y\x1d%Z\x1d%f\x1d%h\x1d%u\x1d%g\x1d%t\x1d%T\x1d%o\x1d%N' {} +" ) +// cmdName returns the user-facing command name: "kubectl vifal" when invoked +// as a kubectl plugin, or the plain binary name otherwise. +func cmdName() string { + bin := filepath.Base(os.Args[0]) + if name, ok := strings.CutPrefix(bin, "kubectl-"); ok { + return fmt.Sprintf("kubectl %s", name) + } + return bin +} + func main() { if len(os.Args) > 1 && os.Args[1] == subcmdUnmount { cmdUnmount(os.Args[2:]) @@ -98,7 +109,7 @@ func cmdMount() { fsName := pflag.String("fsname", defaultFSName, "filesystem name") cacheTTL := pflag.Duration("attr-ttl", attrTTL, "TTL for attribute and directory caches") - bin := filepath.Base(os.Args[0]) + bin := cmdName() pflag.Usage = func() { fmt.Fprintf(os.Stderr, `Usage: %[1]s [flags] MOUNTPOINT %[1]s %[2]s [--rm] [--force] MOUNTPOINT @@ -244,7 +255,7 @@ func cmdUnmount(args []string) { rm := f.Bool("rm", false, "remove the mountpoint directory even if unmount fails") force := f.Bool("force", false, "force unmount even if busy (lazy unmount)") - bin := filepath.Base(os.Args[0]) + bin := cmdName() f.Usage = func() { fmt.Fprintf(os.Stderr, `Usage: %[1]s %[2]s [--rm] [--force] MOUNTPOINT