Skip to content
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

tk apply|diff ... panics with panic: runtime error: slice bounds out of range [:200] with length 197 #973

Closed
maoueh opened this issue Dec 11, 2023 · 2 comments

Comments

@maoueh
Copy link
Contributor

maoueh commented Dec 11, 2023

Versions info:

$ kubectl version
Client Version: v1.28.4
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.5-gke.200

$ tk --version
tk version v0.22.1-4-g172a56f-dirty
# Locally compiled for debugging purposes

Doing tk apply <file> leads to:

panic: runtime error: slice bounds out of range [:200] with length 197

goroutine 1 [running]:
github.com/grafana/tanka/pkg/kubernetes/client.splitRow({0x14001049ff9, 0xc5}, {0x140008a0500, 0x7, 0x4?})
	/Users/maoueh/work/github/grafana_tanka/pkg/kubernetes/client/resources.go:149 +0x4d0
github.com/grafana/tanka/pkg/kubernetes/client.UnmarshalTable({0x14001046000?, 0x14000dde000?}, {0x103059e80, 0x14000402468})
	/Users/maoueh/work/github/grafana_tanka/pkg/kubernetes/client/resources.go:95 +0x268
github.com/grafana/tanka/pkg/kubernetes/client.Kubectl.Resources({{0x140003321e0, 0x14000332370, {{{...}, {...}}, {{...}, {...}}}}})
	/Users/maoueh/work/github/grafana_tanka/pkg/kubernetes/client/resources.go:64 +0x1ec
github.com/grafana/tanka/pkg/kubernetes.(*Kubernetes).Diff(0x14000a52000, {0x14000a9f580, 0x10, 0x10}, {0x0?, 0x0?, {0x0?, 0x0?}})
	/Users/maoueh/work/github/grafana_tanka/pkg/kubernetes/diff.go:39 +0x198
github.com/grafana/tanka/pkg/tanka.Apply({0x16d351661?, _}, {{{0x0, 0x140002a7260, 0x140002a7290, {0x0, 0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...})
	/Users/maoueh/work/github/grafana_tanka/pkg/tanka/workflow.go:92 +0x21c
main.applyCmd.func1(0x140001a6600?, {0x140002f8120, 0x1, 0x1?})
	/Users/maoueh/work/github/grafana_tanka/cmd/tk/workflow.go:70 +0x258
github.com/go-clix/cli.(*Command).execute(0x14000284640, {0x140002f8100, 0x1, 0x1})
	/Users/maoueh/go/pkg/mod/github.com/go-clix/cli@v0.2.0/command.go:118 +0x390
github.com/go-clix/cli.(*Command).Execute(0x140002845a0)
	/Users/maoueh/go/pkg/mod/github.com/go-clix/cli@v0.2.0/command.go:76 +0xc8
main.main()
	/Users/maoueh/work/github/grafana_tanka/cmd/tk/main.go:59 +0x540

Unsure why but the one line in the kubectl api-resources output was shorter than all the rest:

...
Splitting line "volumeattachments                                     storage.k8s.io/v1                      false        VolumeAttachment                 create,delete,deletecollection,get,list,patch,update,watch   " of length 200
Splitting line "audits                                                warden.gke.io/v1                       false        Audit                            delete,deletecollection,get,list,patch,create,update,watch" of length 197

Headers:

Headers matches [NAME                               SHORTNAMES           APIVERSION                              NAMESPACED    KIND                              VERBS                                                         CATEGORIES] 7 34

(From log line fmt.Println("Headers matches", header, len(header), len(header[0]))).

I fixed the issue by changing splitRow to:

diff --git a/pkg/kubernetes/client/resources.go b/pkg/kubernetes/client/resources.go
index 9b4d5bc..b707ecf 100644
--- a/pkg/kubernetes/client/resources.go
+++ b/pkg/kubernetes/client/resources.go
@@ -134,8 +134,15 @@ func splitRow(s string, header []string) (elems []string) {
 		}
 
 		lim := len(h)
+
+		if pos+lim > len(s) {
+			elems = append(elems, s[pos:])
+			pos = len(s)
+			continue
+		}
+
 		elems = append(elems, s[pos:pos+lim])
 		pos += lim
 	}
 	return elems
-}
+}
\ No newline at end of file

Unsure if it's the right logic, if it's something weird because maybe I a client more recent than the server version. Let me know.

@zerok
Copy link
Contributor

zerok commented May 27, 2024

Hi :) I think this was solved with #796 . Feel free to reopen if it's still broken for you :)

@zerok zerok closed this as completed May 27, 2024
@maoueh
Copy link
Contributor Author

maoueh commented May 27, 2024

Np, I had my fix locally, I'll be able to switch back to stock version, perfect!

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

No branches or pull requests

2 participants