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

[kubectl_manifest] panic: runtime error: slice bounds out of range #181

Closed
donovanmuller opened this issue Oct 17, 2024 · 6 comments
Closed
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@donovanmuller
Copy link

donovanmuller commented Oct 17, 2024

Version: 2.1.0
Terraform: 1.5.7

Given the following to apply Rancher manifests as part of importing a cluster:

data "http" "cluster_registration_manifest" {
  url = rancher2_cluster.eks_cluster_import.cluster_registration_token[0].manifest_url
}

data "kubectl_file_documents" "cluster_registration_manifest" {
  content = data.http.cluster_registration_manifest.response_body
}

resource "kubectl_manifest" "rancher_manifests" {
  count      = 9
  apply_only = true
  yaml_body  = element(data.kubectl_file_documents.cluster_registration_manifest.documents, count.index)

  lifecycle {
    ignore_changes = all
  }
}

When applied the first time there is no problem and works as expected. However, in subsequent terraform plans the following error is shown:

│ Error: Plugin did not respond
│
│   with module.rancher.kubectl_manifest.rancher_manifests[7],
│   on ../modules/rancher/eks_rancher.tf line 32, in resource "kubectl_manifest" "rancher_manifests":
│   32: resource "kubectl_manifest" "rancher_manifests" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-kubectl_v2.1.0 plugin:

panic: runtime error: slice bounds out of range [:14521] with length 14046

goroutine 680 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).patchMake2(0x14000b6cce0, {0x14001130000?, 0x28?}, {0x1400056c008?, 0x3c, 0x106124108?})
	github.com/sergi/[email protected]/diffmatchpatch/patch.go:171 +0x7ac
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0x14000b6cce0, {0x14000b6cbc0?, 0x322?, 0x355?})
	github.com/sergi/[email protected]/diffmatchpatch/patch.go:131 +0x278
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0x14000b6cce0, {0x14000acae28?, 0x2?, 0x14000acae78?})
	github.com/sergi/[email protected]/diffmatchpatch/patch.go:129 +0x238
github.com/alekc/terraform-provider-kubectl/kubernetes.resourceKubectlManifest.func6({0x104d02888?, 0x14000d80ab0?}, 0x1400103f180, {0xd?, 0x104295b98?})
	github.com/alekc/terraform-provider-kubectl/kubernetes/resource_kubectl_manifest.go:312 +0xac8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0x14000323620, {0x104d02888, 0x14000d80ab0}, 0x14000cab1e0, 0x14000d81c50, 0x104cd7220, {0x104a3c480, 0x140005206c8}, 0x0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:698 +0x3b8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0x104d027a8?, {0x104d02888?, 0x14000d80ab0?}, 0x14000cab1e0, 0x14000d80ae0?, {0x104a3c480?, 0x140005206c8?})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:962 +0x9c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0x14000656780, {0x104d02888?, 0x14000d809f0?}, 0x1400034e5f0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:780 +0x824
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0x1400078a820, {0x104d02888?, 0x1400073ba70?}, 0x140009b9810)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:824 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0x104bedac0, 0x1400078a820}, {0x104d02888, 0x1400073ba70}, 0x14000ca6b00, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:449 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001c9600, {0x104d02888, 0x1400073b920}, {0x104d10c40, 0x14000213500}, 0x14000cb6a20, 0x1400071e3f0, 0x105efebc0, 0x0)
	google.golang.org/[email protected]/server.go:1379 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x140001c9600, {0x104d10c40, 0x14000213500}, 0x14000cb6a20)
	google.golang.org/[email protected]/server.go:1790 +0xb20
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1029 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 51
	google.golang.org/[email protected]/server.go:1040 +0x13c

Error: The terraform-provider-kubectl_v2.1.0 plugin crashed!
@alekc alekc added the triage label Oct 20, 2024
@alekc
Copy link
Owner

alekc commented Oct 20, 2024

Thanks, I will have a look. Although thats not a proper way of using kubectl_file_documents.

You will be far better of with

data "kubectl_file_documents" "docs" {
    content = file("multi-doc-manifest.yaml")
}

resource "kubectl_manifest" "test" {
    for_each  = data.kubectl_file_documents.docs.manifests
    yaml_body = each.value
}

If you are using count and the number of documents changes, that will trigger destroy sequence (and potentially thats what have been causing the crash above).

@rodrigorfk
Copy link

Hi there, I am facing the same issue and it seems to be a bug in the upstream go-diff library related to the removal of some fields between "stateYaml" and "liveStateYaml". To be honest if you look into the the reported issues for that library, you will see that some other users are facing something similar.

Back to the issue when using it in the provider, I was able to create a minimal scenario, based on my usage case, and focusing directly on the usage of the go-diff library that might be useful to simulate the issue at your end.

  • file1.yaml
apiVersion=fba77d3af20ba3386138d7851bdac85325348e50f246eff0fe9c284431afea8f
kind=d4de62ce997784f9417e3ab9a392f383f1c2e26caefc2825828e8625155cdd16
spec.syscalls.2.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.2.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.2.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.2.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.2.args.0.value=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.2.args.0.valueTwo=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.2.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.2.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.3.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.3.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.3.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.3.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.3.args.0.value=2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3
spec.syscalls.3.args.0.valueTwo=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.3.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.3.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.4.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.4.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.4.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.4.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.4.args.0.value=ca102ce50c58f506fb59534e5344abf9930de2cef2d5b38ddb345bd8ec80a151
spec.syscalls.4.args.0.valueTwo=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.4.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.4.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.5.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.5.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.5.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.5.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.5.args.0.value=f807212b6748a8300fc3702322caa515edf0a6ed9bbc86e94c451e351b080c60
spec.syscalls.5.args.0.valueTwo=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.5.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.5.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
  • file2.yaml
apiVersion=fba77d3af20ba3386138d7851bdac85325348e50f246eff0fe9c284431afea8f
kind=d4de62ce997784f9417e3ab9a392f383f1c2e26caefc2825828e8625155cdd16
spec.syscalls.2.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.2.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.2.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.2.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.2.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.2.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.3.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.3.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.3.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.3.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.3.args.0.value=2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3
spec.syscalls.3.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.3.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.4.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.4.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.4.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.4.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.4.args.0.value=ca102ce50c58f506fb59534e5344abf9930de2cef2d5b38ddb345bd8ec80a151
spec.syscalls.4.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.4.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
spec.syscalls.5.action=f7db9c9c0b5b57797794e28f464146436a947a11aef267cb32c80cc548563763
spec.syscalls.5.args.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.5.args.0.index=5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
spec.syscalls.5.args.0.op=53f3a4af44fe76f39a74d70129cf32faff1ee1ae8af0538e3de879010960fe6a
spec.syscalls.5.args.0.value=f807212b6748a8300fc3702322caa515edf0a6ed9bbc86e94c451e351b080c60
spec.syscalls.5.names.#=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
spec.syscalls.5.names.0=f046cfb2d0788f93898ec2a8d208570ceb29acfa467e33194373af154b46f671
  • main.go
package main

import (
	"github.com/sergi/go-diff/diffmatchpatch"
	"log"
	"os"
)

func main() {

	bytes, err := os.ReadFile("file1.yaml")
	if err != nil {
		log.Fatalf("Failed to read file: %v", err)
	}
	stateYaml := string(bytes)
	bytes, err = os.ReadFile("file2.yaml")
	if err != nil {
		log.Fatalf("Failed to read file: %v", err)
	}
	liveStateYaml := string(bytes)

	dmp := diffmatchpatch.New()
	patches := dmp.PatchMake(stateYaml, liveStateYaml)
	patchText := dmp.PatchToText(patches)
	log.Printf("[DEBUG] DETECTED YAML INCLUSTER STATE DIFFERENCE. Patch diff: %s", patchText)
}

It will produce the following error:

panic: runtime error: slice bounds out of range [2794:2726]

goroutine 1 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).patchMake2(0x14000107e50, {0x140000d8c00?, 0x1?}, {0x14000178000?, 0xd, 0x10000010240bcdc?})
        /dev/go/pkg/mod/github.com/sergi/[email protected]/diffmatchpatch/patch.go:171 +0x7a4
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0x14000107e50?, {0x14000107dc8?, 0x96?, 0xaa?})
        /dev/go/pkg/mod/github.com/sergi/[email protected]/diffmatchpatch/patch.go:131 +0x278
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0x1024bf581?, {0x140000cded8?, 0xa17?, 0x0?})
        /dev/go/pkg/mod/github.com/sergi/[email protected]/diffmatchpatch/patch.go:129 +0x238
main.main()
        /dev/projects/sre/playground/yaml-diff-go-test/main.go:23 +0x18c

Process finished with the exit code 2

The content of the files1 and file2 were obtained from the [TRACE] DETECTED YAML STATE DIFFERENCE message when running the provider with TF_LOG=trace

@alekc
Copy link
Owner

alekc commented Oct 25, 2024

that sucks, by the look of it, that library is no longer maintained (at least I do not see any activity), so might be worthwhile investigate an alternative.

@alekc alekc added bug Something isn't working dependencies Pull requests that update a dependency file and removed triage labels Oct 25, 2024
@alekc
Copy link
Owner

alekc commented Oct 25, 2024

I've checked in the code. By the look of it, that library was used only for printing a diff in the tracing. Given that, it should be safe to remove it for now until a valid alternative is found.

@rodrigorfk
Copy link

Thanks for swift response @alekc.

@alekc
Copy link
Owner

alekc commented Oct 25, 2024

Closing this ticket off. Expect a new version with a fix being released next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

3 participants