kubernetes-sigs / krew

📦 Find and install kubectl plugins
https://krew.sigs.k8s.io
Apache License 2.0
6.42k stars 369 forks source link

Krew seems to not download all the bytes of distribution archive #837

Closed vania-pooh closed 1 year ago

vania-pooh commented 1 year ago

I'm developing a manifest for my kubectl plugin that should will be soon published as custom Krew index. Currently manifest is as follows (omitted all platforms except Darwin AMD64 for simplicity):

apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
  name: vm-unstable
spec:
  version: v0.0.3
  homepage: https://some-url/
  shortDescription: Some short description
  description: Some description.
  platforms:
    - selector:
        matchLabels:
          os: darwin
          arch: amd64
      uri: https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
      sha256: eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df
      bin: kubectl-vm

Using latest stable release:

$ kubectl krew version
OPTION            VALUE
GitTag            v0.4.4
GitCommit         343e657
IndexURI          https://github.com/kubernetes-sigs/krew-index.git
BasePath          /Users/vania-pooh/.krew
IndexPath         /Users/vania-pooh/.krew/index/default
InstallPath       /Users/vania-pooh/.krew/store
BinPath           /Users/vania-pooh/.krew/bin
DetectedPlatform  darwin/amd64

Trying to test this manifest locally I get:

$ kubectl krew install --manifest plugins/vm-unstable.yaml -v=4
I0822 11:07:58.019874    8437 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew"
I0822 11:07:58.020019    8437 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/store"
I0822 11:07:58.020028    8437 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/bin"
I0822 11:07:58.020035    8437 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/index"
I0822 11:07:58.020043    8437 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/receipts"
I0822 11:07:58.020208    8437 migration.go:30] Checking if index migration is needed.
I0822 11:07:58.020211    8437 root.go:132] skipping upgrade check
I0822 11:07:58.020227    8437 migration.go:33] Index already migrated.
I0822 11:07:58.020239    8437 install.go:191] --manifest specified, not ensuring plugin index
I0822 11:07:58.023215    8437 install.go:148] Will install plugin: detached/vm-unstable
Installing plugin: vm-unstable
I0822 11:07:58.023245    8437 install.go:58] Looking for installed versions
I0822 11:07:58.023274    8437 platform.go:43] Matching platform for labels(arch=amd64,os=darwin)
I0822 11:07:58.023319    8437 platform.go:51] Found matching platform with index (0)
I0822 11:07:58.023326    8437 install.go:77] Install plugin vm-unstable at version=v0.0.3
I0822 11:07:58.023335    8437 install.go:95] Creating download staging directory
I0822 11:07:58.023511    8437 install.go:100] Successfully created download staging directory "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads3646757129"
I0822 11:07:58.023547    8437 fetch.go:39] Fetching "https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip"
I0822 11:07:58.488670    8437 downloader.go:41] Reading archive file into memory
I0822 11:07:59.746359    8437 downloader.go:46] Read 9989186 bytes from archive into memory
I0822 11:07:59.746400    8437 verifier.go:51] Compare sha256 (eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df) signed version
I0822 11:07:59.746459    8437 install.go:102] Deleting the download staging directory /var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads3646757129
W0822 11:07:59.746640    8437 install.go:164] failed to install plugin "vm-unstable": install failed: failed to unpack into staging dir: failed to unpack the plugin archive: checksum does not match, want: eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df, got a9082dafa614d6880eea9ce72d632ede56c9f2f76fc1d0f6296bc8d3f19fb5eb
F0822 11:07:59.746702    8437 root.go:80] checksum does not match, want: eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df, got a9082dafa614d6880eea9ce72d632ede56c9f2f76fc1d0f6296bc8d3f19fb5eb
sigs.k8s.io/krew/internal/download.sha256Verifier.Verify
    /home/runner/work/krew/krew/internal/download/verifier.go:55
sigs.k8s.io/krew/internal/download.download
    /home/runner/work/krew/krew/internal/download/downloader.go:48
sigs.k8s.io/krew/internal/download.Downloader.Get
    /home/runner/work/krew/krew/internal/download/downloader.go:228
sigs.k8s.io/krew/internal/installation.downloadAndExtract
    /home/runner/work/krew/krew/internal/installation/install.go:149
sigs.k8s.io/krew/internal/installation.install
    /home/runner/work/krew/krew/internal/installation/install.go:107
sigs.k8s.io/krew/internal/installation.Install
    /home/runner/work/krew/krew/internal/installation/install.go:78
sigs.k8s.io/krew/cmd/krew/cmd.init.2.func1
    /home/runner/work/krew/krew/cmd/krew/cmd/install.go:156
github.com/spf13/cobra.(*Command).execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/krew/cmd/krew/cmd.Execute
    /home/runner/work/krew/krew/cmd/krew/cmd/root.go:78
main.main
    /home/runner/work/krew/krew/cmd/krew/main.go:25
runtime.main
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/proc.go:250
runtime.goexit
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/asm_amd64.s:1598
failed to unpack the plugin archive
sigs.k8s.io/krew/internal/installation.downloadAndExtract
    /home/runner/work/krew/krew/internal/installation/install.go:150
sigs.k8s.io/krew/internal/installation.install
    /home/runner/work/krew/krew/internal/installation/install.go:107
sigs.k8s.io/krew/internal/installation.Install
    /home/runner/work/krew/krew/internal/installation/install.go:78
sigs.k8s.io/krew/cmd/krew/cmd.init.2.func1
    /home/runner/work/krew/krew/cmd/krew/cmd/install.go:156
github.com/spf13/cobra.(*Command).execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/krew/cmd/krew/cmd.Execute
    /home/runner/work/krew/krew/cmd/krew/cmd/root.go:78
main.main
    /home/runner/work/krew/krew/cmd/krew/main.go:25
runtime.main
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/proc.go:250
runtime.goexit
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/asm_amd64.s:1598
failed to unpack into staging dir
sigs.k8s.io/krew/internal/installation.install
    /home/runner/work/krew/krew/internal/installation/install.go:108
sigs.k8s.io/krew/internal/installation.Install
    /home/runner/work/krew/krew/internal/installation/install.go:78
sigs.k8s.io/krew/cmd/krew/cmd.init.2.func1
    /home/runner/work/krew/krew/cmd/krew/cmd/install.go:156
github.com/spf13/cobra.(*Command).execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/krew/cmd/krew/cmd.Execute
    /home/runner/work/krew/krew/cmd/krew/cmd/root.go:78
main.main
    /home/runner/work/krew/krew/cmd/krew/main.go:25
runtime.main
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/proc.go:250
runtime.goexit
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/asm_amd64.s:1598
install failed
sigs.k8s.io/krew/internal/installation.Install
    /home/runner/work/krew/krew/internal/installation/install.go:85
sigs.k8s.io/krew/cmd/krew/cmd.init.2.func1
    /home/runner/work/krew/krew/cmd/krew/cmd/install.go:156
github.com/spf13/cobra.(*Command).execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/krew/cmd/krew/cmd.Execute
    /home/runner/work/krew/krew/cmd/krew/cmd/root.go:78
main.main
    /home/runner/work/krew/krew/cmd/krew/main.go:25
runtime.main
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/proc.go:250
runtime.goexit
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/asm_amd64.s:1598
failed to install some plugins: [vm-unstable]
sigs.k8s.io/krew/cmd/krew/cmd.init.2.func1
    /home/runner/work/krew/krew/cmd/krew/cmd/install.go:185
github.com/spf13/cobra.(*Command).execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940
github.com/spf13/cobra.(*Command).ExecuteC
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
sigs.k8s.io/krew/cmd/krew/cmd.Execute
    /home/runner/work/krew/krew/cmd/krew/cmd/root.go:78
main.main
    /home/runner/work/krew/krew/cmd/krew/main.go:25
runtime.main
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/proc.go:250
runtime.goexit
    /opt/hostedtoolcache/go/1.20.5/x64/src/runtime/asm_amd64.s:1598

Krew seems to be not downloading all the bytes of my archive, because content-length header is as follows:

$ curl -I https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
HTTP/2 200
content-type: application/zip
content-length: 9989259
date: Mon, 21 Aug 2023 17:21:23 GMT
last-modified: Mon, 21 Aug 2023 17:15:33 GMT
etag: "91e6faf3002617c72d360ac32c16d98c-2"
server: AmazonS3
x-cache: Hit from cloudfront
via: 1.1 befe3b8553d90339ecf78e5d7cefa60a.cloudfront.net (CloudFront)
x-amz-cf-pop: FRA53-C1
x-amz-cf-id: QvUdsxz_4S4rXWLvlIJI0VQeKEDMMc4DzR1pLXL9jhhcidbKLH6b5A==
age: 52118

You can see that content-length = 9989259 whereas krew is saying:

I0822 11:07:59.746359    8437 downloader.go:46] Read 9989186 bytes from archive into memory

Now if I download the same file with curl and try to install with krew - everything works:

$ wget https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
--2023-08-22 11:11:58--  https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
Resolving download.aerokube.com (download.aerokube.com)... 2600:9000:214f:1a00:0:136c:3ac0:93a1, 2600:9000:214f:200:0:136c:3ac0:93a1, 2600:9000:214f:cc00:0:136c:3ac0:93a1, ...
Connecting to download.aerokube.com (download.aerokube.com)|2600:9000:214f:1a00:0:136c:3ac0:93a1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9989259 (9,5M) [application/zip]
Saving to: ‘kubectl-vm_latest_darwin_amd64.zip’

kubectl-vm_latest_darwin_amd64.zip            100%[==============================================================================================>]   9,53M  7,55MB/s    in 1,3s

2023-08-22 11:11:59 (7,55 MB/s) - ‘kubectl-vm_latest_darwin_amd64.zip’ saved [9989259/9989259]

$ shasum -a 256 kubectl-vm_latest_darwin_amd64.zip
eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df  kubectl-vm_latest_darwin_amd64.zip

$ kubectl krew install --manifest plugins/vm-unstable.yaml --archive kubectl-vm_latest_darwin_amd64.zip -v=4
I0822 11:12:28.678252    8461 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew"
I0822 11:12:28.678356    8461 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/store"
I0822 11:12:28.678365    8461 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/bin"
I0822 11:12:28.678370    8461 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/index"
I0822 11:12:28.678376    8461 root.go:238] Ensure creating dir: "/Users/vania-pooh/.krew/receipts"
I0822 11:12:28.678545    8461 migration.go:30] Checking if index migration is needed.
I0822 11:12:28.678557    8461 migration.go:33] Index already migrated.
I0822 11:12:28.678565    8461 install.go:191] --manifest specified, not ensuring plugin index
I0822 11:12:28.678591    8461 root.go:132] skipping upgrade check
I0822 11:12:28.679209    8461 install.go:148] Will install plugin: detached/vm-unstable
Installing plugin: vm-unstable
I0822 11:12:28.679222    8461 install.go:58] Looking for installed versions
I0822 11:12:28.679241    8461 platform.go:43] Matching platform for labels(arch=amd64,os=darwin)
I0822 11:12:28.679277    8461 platform.go:51] Found matching platform with index (0)
I0822 11:12:28.679281    8461 install.go:77] Install plugin vm-unstable at version=v0.0.3
I0822 11:12:28.679286    8461 install.go:95] Creating download staging directory
I0822 11:12:28.679566    8461 install.go:100] Successfully created download staging directory "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007"
I0822 11:12:28.679585    8461 fetch.go:55] Reading "kubectl-vm_latest_darwin_amd64.zip"
I0822 11:12:28.679608    8461 downloader.go:41] Reading archive file into memory
I0822 11:12:28.733934    8461 downloader.go:46] Read 9989259 bytes from archive into memory
I0822 11:12:28.733964    8461 verifier.go:51] Compare sha256 (eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df) signed version
I0822 11:12:28.733993    8461 downloader.go:203] detected "application/zip" file type
I0822 11:12:28.733998    8461 downloader.go:53] Extracting zip archive to "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007"
I0822 11:12:28.734977    8461 downloader.go:73] zip: ensuring parent dirs exist for regular file, dir=/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007
I0822 11:12:28.948993    8461 install.go:135] file operation not specified, assuming [{* .}]
I0822 11:12:28.951299    8461 move.go:156] Creating directory "/Users/vania-pooh/.krew/store/vm-unstable"
I0822 11:12:28.951747    8461 move.go:162] Creating temp plugin move operations dir "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-temp-move831907236"
I0822 11:12:28.951810    8461 move.go:124] Finding move targets from "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007" to "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-temp-move831907236" with file operation=index.FileOperation{From:"*", To:"."}
I0822 11:12:28.951844    8461 move.go:43] Trying to move single file directly from="/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007" to="/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-temp-move831907236" with file operation=index.FileOperation{From:"*", To:"."}
I0822 11:12:28.951892    8461 move.go:51] Wasn't a single file, proceeding with Glob move
I0822 11:12:28.952113    8461 move.go:131] Move file from "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007/kubectl-vm" to "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-temp-move831907236/kubectl-vm"
I0822 11:12:28.952472    8461 move.go:140] Move operations are complete
I0822 11:12:28.952528    8461 move.go:172] Move directory "/var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-temp-move831907236" to "/Users/vania-pooh/.krew/store/vm-unstable/v0.0.3"
I0822 11:12:28.952892    8461 install.go:214] No file found at "/Users/vania-pooh/.krew/bin/kubectl-vm_unstable"
I0822 11:12:28.952959    8461 install.go:201] Creating symlink to "/Users/vania-pooh/.krew/store/vm-unstable/v0.0.3/kubectl-vm" at "/Users/vania-pooh/.krew/bin/kubectl-vm_unstable"
I0822 11:12:28.953072    8461 install.go:205] Created symlink at "/Users/vania-pooh/.krew/bin/kubectl-vm_unstable"
I0822 11:12:28.953078    8461 install.go:102] Deleting the download staging directory /var/folders/g7/wg97qjq57f3f184tf39sf6wxwzjx4y/T/krew-downloads4187405007
I0822 11:12:28.953136    8461 install.go:88] Storing install receipt for plugin vm-unstable
Installed plugin: vm-unstable
\
 | Use this plugin:
 |  kubectl vm-unstable
 | Documentation:
 |  https://some-url/
 | Caveats:
 | \
 |  | You are using an unstable version of the plugin.
 | /
/
I0822 11:12:28.956843    8461 root.go:180] Upgrade check was skipped or has not finished
chriskim06 commented 1 year ago

it works for me. not sure what could be causing this but could it be something about your local networking?

$ pbpaste > vm-unstable.yml && cat vm-unstable.yml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
  name: vm-unstable
spec:
  version: v0.0.3
  homepage: https://some-url/
  shortDescription: Some short description
  description: Some description.
  platforms:
    - selector:
        matchLabels:
          os: darwin
          arch: amd64
      uri: https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
      sha256: eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df
      bin: kubectl-vm

$ wget https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
--2023-08-22 14:24:04--  https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
Resolving download.aerokube.com (download.aerokube.com)... 18.244.214.2, 18.244.214.30, 18.244.214.73, ...
Connecting to download.aerokube.com (download.aerokube.com)|18.244.214.2|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9988544 (9.5M) [application/zip]
Saving to: ‘kubectl-vm_latest_darwin_amd64.zip’

kubectl-vm_latest_darwin_amd64.zip                    100%[========================================================================================================================>]   9.53M  37.1MB/s    in 0.3s

2023-08-22 14:24:05 (37.1 MB/s) - ‘kubectl-vm_latest_darwin_amd64.zip’ saved [9988544/9988544]

$ shasum -a 256 kubectl-vm_latest_darwin_amd64.zip
cc6c22b877ab03add1ccb58f3421ca9e7cffd886b3edd2c7a0010c87be13f890  kubectl-vm_latest_darwin_amd64.zip

$ sed 's/eb0995d97bf37735e2daa8a615b7fac2f4c3524303c553ed4501707adfdd88df/cc6c22b877ab03add1ccb58f3421ca9e7cffd886b3edd2c7a0010c87be13f890/' -i vm-unstable.yml

$ cat vm-unstable.yml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
  name: vm-unstable
spec:
  version: v0.0.3
  homepage: https://some-url/
  shortDescription: Some short description
  description: Some description.
  platforms:
    - selector:
        matchLabels:
          os: darwin
          arch: amd64
      uri: https://download.aerokube.com/boot/kubectl-vm/latest/kubectl-vm_latest_darwin_amd64.zip
      sha256: cc6c22b877ab03add1ccb58f3421ca9e7cffd886b3edd2c7a0010c87be13f890
      bin: kubectl-vm

$ kubectl krew install --manifest vm-unstable.yml
Installing plugin: vm-unstable
Installed plugin: vm-unstable
\
 | Use this plugin:
 |      kubectl vm-unstable
 | Documentation:
 |      https://some-url/
/

i had to update the sha and i omitted the verbose logging

vania-pooh commented 1 year ago

@chriskim06 yeah, seems to be. Now it works for me too. Probably related to caching in our CDN.