helm/helm-mapkubeapis

Latest version of plugin mapkubeapis (v0.5.1) is failing with "[signal SIGSEGV: segmentation violation code=0x1 addr=0x280 pc=0x5df11a]"

Closed this issue ยท 3 comments

I noticed since the mapkubeapis v.0.5.1 was released while running the command:
helm mapkubeapis --help

The following error appears:

[root@test-ubi8 src]# helm plugin list
NAME            VERSION DESCRIPTION
mapkubeapis     0.5.1   Map release deprecated Kubernetes APIs in-place

[root@test-ubi8 src]# helm mapkubeapis --help
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x280 pc=0x5df11a]

goroutine 1 [running]:
github.com/spf13/cobra.(*Command).ExecuteC(0x0?)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1055 +0x1a
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
main.main()
        /home/runner/work/helm-mapkubeapis/helm-mapkubeapis/cmd/mapkubeapis/map_kube_apis.go:26 +0x59
Error: plugin "mapkubeapis" exited with error

I've tested the above plugin with 2 versions of helm, and I get the same error: helm v3.12.3 & helm v3.15.4 (latest) !

When I tested a previous version of this plugin like v0.5.0 which is actually downloading v0.4.1 instead (so there's no downloadable v0.5.0 ?!), the above error is not appearing anymore:

[root@test-ubi8 src]# helm plugin install https://github.com/helm/helm-mapkubeapis  --version v0.5.0
Downloading and installing helm-mapkubeapis v0.4.1 ...
https://github.com/helm/helm-mapkubeapis/releases/download/v0.4.1/helm-mapkubeapis_0.4.1_linux_amd64.tar.gz
Installed plugin: mapkubeapis
[root@test-ubi8 src]# helm plugin list
NAME            VERSION DESCRIPTION
mapkubeapis     0.4.1   Map release deprecated Kubernetes APIs in-place
[root@test-ubi8 src]# helm mapkubeapis --help
Map release deprecated or removed Kubernetes APIs in-place

Usage:
  mapkubeapis [flags] RELEASE

Flags:
      --dry-run               simulate a command
  -h, --help                  help for mapkubeapis
      --kube-context string   name of the kubeconfig context to use
      --kubeconfig string     path to the kubeconfig file
      --mapfile string        path to the API mapping file (default "/root/.local/share/helm/plugins/helm-mapkubeapis/config/Map.yaml")
      --namespace string      namespace scope of the release

Thanks for the issue. I was able to replicate the problem. I suspect I did not see this before because of a lack of testing with a completely fresh install.

I found the issue. It's only happening when --help is being called and was due to some linter cleanup/handling.

The reason for this is the --help command is undefined when flags.Parse(args) is called in map.go. There is an error for that and it causes nil to be returned. .Execute() called on nil is what's causing this error.

The easy fix is to remove the following lines from map.go.

	err := flags.Parse(args)
	if err != nil {
		return nil
	}

When .Execute() is called on a command the default help flag is added and the flags are parsed. It looks like this parsing can be safely removed.

I should be able to pick this one up this week.