sozercan / kubectl-ai

✨ Kubectl plugin to create manifests with LLMs
MIT License
1.01k stars 74 forks source link

Krew broken? error: unknown command "ai" for "kubectl" #46

Open sfxworks opened 1 year ago

sfxworks commented 1 year ago

Installs just fine

kubectl krew install kubectl-ai/kubectl-ai                                                                                                                                  INT ✘  home ⎈ 

Updated the local copy of plugin index.
Updated the local copy of plugin index "kubectl-ai".
Installing plugin: kubectl-ai
W0524 21:17:37.247983   11130 install.go:160] Skipping plugin "kubectl-ai", it is already installed

Though I get an error when calling it

kubectl ai "Create a minecraft server statefulset using the image from itgz/minecraft"                                                                                          ✔  home ⎈ 
error: unknown command "ai" for "kubectl"

Did you mean this?
        cp
        wait

But my other plugins such as the rook-ceph one work fine

kubectl rook-ceph ceph status                                                                                                                                                 1 ✘  home ⎈ 
  cluster:
    id:     d191c5d8-41e0-4324-a575-3718963d1a57
    health: HEALTH_WARN
            1 pool(s) have no replicas configured

  services:
    mon: 3 daemons, quorum d,e,f (age 3d)
    mgr: a(active, since 3d)
    mds: 1/1 daemons up, 1 hot standby
    osd: 6 osds: 6 up (since 19h), 6 in (since 3d)
    rgw: 1 daemon active (1 hosts, 1 zones)

  data:
    volumes: 1/1 healthy
    pools:   18 pools, 18 pgs
    objects: 3.28M objects, 9.9 TiB
    usage:   15 TiB used, 8.6 TiB / 24 TiB avail
    pgs:     18 active+clean

  io:
    client:   446 KiB/s rd, 61 KiB/s wr, 457 op/s rd, 1 op/s wr
sfxworks commented 1 year ago

Upon further inspection

total 0
drwxr-xr-x 2 sam sam 125 May 24 21:13 .
drwxr-xr-x 6 sam sam  59 May 13 22:53 ..
lrwxrwxrwx 1 sam sam  49 May 13 22:54 kubectl-change_ns -> /home/sam/.krew/store/change-ns/v1.0.0/kubectl-ns
lrwxrwxrwx 1 sam sam  38 May 13 22:53 kubectl-krew -> /home/sam/.krew/store/krew/v0.4.3/krew
lrwxrwxrwx 1 sam sam  51 May 24 21:13 kubectl-kubectl_ai -> /home/sam/.krew/store/kubectl-ai/v0.0.10/kubectl-ai
lrwxrwxrwx 1 sam sam  59 May 13 22:57 kubectl-rook_ceph -> /home/sam/.krew/store/rook-ceph/v0.4.0/kubectl-rook-ceph.sh
lrwxrwxrwx 1 sam sam  52 May 13 22:56 kubectl-who_can -> /home/sam/.krew/store/who-can/v0.4.0/kubectl-who-can
sfxworks commented 1 year ago

Looks like to fix this

  1. The generated binary would need to be renamed to ai instead of kubect-ai
  2. https://github.com/sozercan/kubectl-ai/blob/main/plugins/kubectl-ai.yaml would need to target said binary instead of kubect-ai

I could make a PR later after investigating your build process

sozercan commented 1 year ago

@sfxworks thanks for the report! i can repro this behavior.

It seems like krew is trying to be clever by adding a kubectl- in front of the executable and then replacing - with _. Looks like normally this can be solved with specifying files to rename the binary. https://krew.sigs.k8s.io/docs/developer-guide/plugin-manifest/

However, in this case, we are autogenerating the krew manifest using goreleaser (https://github.com/sozercan/kubectl-ai/blob/main/.goreleaser.yaml) Unfortunately, I don't see a way in goreleaser to rename the binaries: https://goreleaser.com/customization/krew/

If we rename the binary to be just ai, it will break the other installation methods, like brew or archives. Quickest workaround for this seems to be mv $HOME/.krew/bin/kubectl-kubectl_ai $HOME/.krew/bin/kubectl-ai (guessing this will need to be done after every upgrade ☹️) Another option is to add a new build for ai in goreleaser only to be used in krews.

Let me know if you find any other solutions or interested in contributing one of the workarounds.

sfxworks commented 1 year ago

If you're intent on using goreleaser, you may want to raise an issue in their PR requesting this feature. It looks like homebrew offers a post install scrip though that could conduct the rename if needed. A third option could be to switch to some prewritten github actions for homebrew and krew that already offer the features you'd need here. Krew is a popular plugin manager for kubectl, so I'd at least note the current post-install step required in the readme. I just adjusted the symlink myself (Mine was a symlink rather than the binary).