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

Plugin crash kubernetes_job - interface conversion #2654

Open
argeiger opened this issue Dec 18, 2024 · 3 comments · May be fixed by #2657
Open

Plugin crash kubernetes_job - interface conversion #2654

argeiger opened this issue Dec 18, 2024 · 3 comments · May be fixed by #2657
Assignees

Comments

@argeiger
Copy link

Terraform Version, Provider Version and Kubernetes Version

Terraform v1.5.7
+ provider registry.terraform.io/hashicorp/kubernetes v2.35.0
Kubernetes Version: v1.29.9

Affected Resource(s)

  • kubernetes_job_v1
  • kubernetes_job

Most likely affects all schemas that are empty

Terraform Configuration Files

resource "kubernetes_job" "cloud_pak_deployer_job" {
  metadata {
    labels = {
      App = "deployer"
    }
    name      = "deployer"
    namespace = "deployer"
  }
  spec {
    parallelism   = 1
    completions   = 1
    backoff_limit = 0
    template {
      metadata {
        name ="deployer"
        labels = {
          App = "deployer"
        }
      }
      spec {
        image_pull_secrets {
          name = var.deployer_secret != null ? "cpd-docker-cfg" : ""
        }
        container {
          name                       = "deployer"
          image                      = local.deployer.image
          image_pull_policy          = "Always"
          termination_message_path   = "/dev/termination-log"
          termination_message_policy = "File"
          command = ["/bin/sh", "-xc"]
          args    = ["sleep infinity"]
        }
        restart_policy = "Never"
        security_context {
          run_as_user = 0
        }
      }
    }
  }
}

Debug Output

Panic Output

│ Error: Plugin did not respond
│ 
│   with module.cloudpak_data.module.cloud_pak_deployer.kubernetes_job.cloud_pak_deployer_job,
│   on ../../solutions/deploy/cloud-pak-deployer/main.tf line 180, in resource "kubernetes_job" "cloud_pak_deployer_job":
│  180: resource "kubernetes_job" "cloud_pak_deployer_job" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-kubernetes_v2.35.0_x5 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 126 [running]:
github.com/hashicorp/terraform-provider-kubernetes/kubernetes.expandLocalObjectReferenceArray(...)
        github.com/hashicorp/terraform-provider-kubernetes/kubernetes/structures.go:610
github.com/hashicorp/terraform-provider-kubernetes/kubernetes.expandPodSpec({0x1400189f9f0, 0x1, 0x10396d19c?})
        github.com/hashicorp/terraform-provider-kubernetes/kubernetes/structures_pod.go:803 +0x13b0
github.com/hashicorp/terraform-provider-kubernetes/kubernetes.expandPodTemplate({0x1400189f950, 0x1, 0x1039722a3?})
        github.com/hashicorp/terraform-provider-kubernetes/kubernetes/structures_deployment.go:120 +0x19c
github.com/hashicorp/terraform-provider-kubernetes/kubernetes.expandJobV1Spec({_, _, _})
        github.com/hashicorp/terraform-provider-kubernetes/kubernetes/structure_job.go:123 +0x5f4
github.com/hashicorp/terraform-provider-kubernetes/kubernetes.resourceKubernetesJobV1Create({0x104238eb0, 0x14000295570}, 0x140002cda80, {0x104128f00, 0x140016220e0})
        github.com/hashicorp/terraform-provider-kubernetes/kubernetes/resource_kubernetes_job_v1.go:79 +0x1cc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14000d39420, {0x104238e08, 0x14000c763f0}, 0x140002cda80, {0x104128f00, 0x140016220e0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:806 +0xe4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000d39420, {0x104238e08, 0x14000c763f0}, 0x14000db65b0, 0x140013bcb00, {0x104128f00, 0x140016220e0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:937 +0x884
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14000410330, {0x104238e08?, 0x14000c76210?}, 0x140000c8910)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1155 +0xaa4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0x140002d0500, {0x104238e08?, 0x14000d1dec0?}, 0x140000c8910)
        github.com/hashicorp/[email protected]/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x1400038c3c0, {0x104238e08?, 0x14000d1d2f0?}, 0x140002f50a0)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:865 +0x2b4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10419e440, 0x1400038c3c0}, {0x104238e08, 0x14000d1d2f0}, 0x140013bc080, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:611 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140000f8c00, {0x104238e08, 0x14000d1d260}, {0x1042425e0, 0x14000f03520}, 0x14000e98000, 0x14000b53620, 0x1052f9a98, 0x0)
        google.golang.org/[email protected]/server.go:1394 +0xb78
google.golang.org/grpc.(*Server).handleStream(0x140000f8c00, {0x1042425e0, 0x14000f03520}, 0x14000e98000)
        google.golang.org/[email protected]/server.go:1805 +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 71
        google.golang.org/[email protected]/server.go:1040 +0x13c

Error: The terraform-provider-kubernetes_v2.35.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Steps to Reproduce

Set the following in the spec -

image_pull_secrets {
          name =  ""
        }

The value is based on a variable that is passed in.

Expected Behavior

What should have happened?

No crash. Plan is created just fine

Actual Behavior

What actually happened?

Important Factoids

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@argeiger
Copy link
Author

Utilized dynamic / content to get past this

@arybolovlev
Copy link
Contributor

arybolovlev commented Dec 19, 2024

Hi @argeiger,

If you have a workaround, please share it here. Kubernetes accepts an empty string as a name for imagePullSecret, however, it throws a warning. I think we should be able to fix this.

Thanks.

@argeiger
Copy link
Author

Hi @arybolovlev,

Thank you very much for jumping on this issue. For the workaround, I put the secret within a map and I utilized a dynamic block like the following -

 spec {
        dynamic "image_pull_secrets" {
          for_each = local.image_secret_map

          content {
            name = image_pull_secrets.value
          }
       }
 }

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

Successfully merging a pull request may close this issue.

2 participants