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

block managed_namespace_metadata panic #492

Open
Nello-Angelo opened this issue Nov 10, 2024 · 15 comments
Open

block managed_namespace_metadata panic #492

Nello-Angelo opened this issue Nov 10, 2024 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@Nello-Angelo
Copy link

    sync_policy {

      managed_namespace_metadata {
        labels      = each.value.managed_namespace_metadata_labels
        annotations = each.value.managed_namespace_metadata_annotations
      }
    }
variable "multiple_sources_app" {
  type = map(object({
    managed_namespace_metadata_labels      = optional(map(string))
    managed_namespace_metadata_annotations = optional(map(string))
  }))
  default = {}
}
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
Stack trace from the terraform-provider-argocd_v7.0.3 plugin:
panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 122 [running]:
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSyncPolicy({0x2f7e060, 0xc0023a0bd0})
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:407 +0xa65
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSpec(0x0?)
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:43 +0x213
github.com/oboukili/terraform-provider-argocd/argocd.expandApplication(_)
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:16 +0x10d
github.com/oboukili/terraform-provider-argocd/argocd.resourceArgoCDApplicationUpdate({0x3c00[320](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7370002#L320)?, 0xc000038620}, 0xc002377e00, {0x32d5ec0?, 0xc000828a00?})
	github.com/oboukili/terraform-provider-argocd/argocd/resource_argocd_application.go:262 +0x325
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc0007b3b20, {0x3c00278, 0xc00159f290}, 0xd?, {0x32d5ec0, 0xc000828a00})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:840 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0007b3b20, {0x3c00278, 0xc00159f290}, 0xc000faa9c0, 0xc000ef8980, {0x32d5ec0, 0xc000828a00})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:947 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000981e60, {0x3c00278?, 0xc00159f0e0?}, 0xc000f44000)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x3c1b840?, 0xc000981e60?}}, {0x3c00278, 0xc00159f0e0}, 0x0?)
	github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:38 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x3c002b0?, {0x3c00278?, 0xc00159ede0?}, 0xc000c01f90)
	github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc0009261e0, {0x3c00278?, 0xc00159e180?}, 0xc00076fdc0)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x[340](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7370002#L340)da20?, 0xc0009261e0}, {0x3c00278, 0xc00159e180}, 0xc0014dc480, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000042600, {0x3c00278, 0xc00159e0c0}, {0x3c0f940, 0xc0002ba180}, 0xc001c12ea0, 0xc000da2900, 0x5904858, 0x0)
	google.golang.org/[email protected]/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000042600, {0x3c0f940, 0xc0002ba180}, 0xc001c12ea0)
	google.golang.org/[email protected]/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 78
	google.golang.org/[email protected]/server.go:1030 +0x135
Error: The terraform-provider-argocd_v7.0.3 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.
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1
@Nello-Angelo Nello-Angelo added the bug Something isn't working label Nov 10, 2024
@Nello-Angelo
Copy link
Author

the same error

    source_plugin_name                                 = optional(string)
    source_kustomize_common_annotations                = optional(map(string))
    source_kustomize_common_labels                     = optional(map(string))
    source_kustomize_images                            = optional(set(string))
    source_kustomize_name_prefix                       = optional(string)
    source_kustomize_name_suffix                       = optional(string)
    source_kustomize_version                           = optional(string)
      kustomize {
        name_prefix        = each.value.source_kustomize_name_prefix
        name_suffix        = each.value.source_kustomize_name_suffix
        version            = each.value.source_kustomize_version
        common_annotations = each.value.source_kustomize_common_annotations
        common_labels      = each.value.source_kustomize_common_labels
        images             = each.value.source_kustomize_images
      }

      plugin {
        name = each.value.source_plugin_name

        dynamic "env" {
          for_each = { for i in each.value.env : format("%s-%s", i.name, i.value) => i }
          content {
            name  = env.value.name
            value = env.value.value
          }
        }
      }

@the-technat
Copy link
Collaborator

So what exactly are you trying to acomplish that let's the provider crash? Would you mind adding some steps to reproduce the issue (including a full example resource)?

@Nello-Angelo
Copy link
Author

Nello-Angelo commented Nov 10, 2024

what my resource looks like doesn’t matter; I get this error if the values ​​of the passed variables remain empty and optional

in the plugin block for example if i use dynamic and do apply

env = optional(list(object({
  name  = string
  value = string
})), [])

@Nello-Angelo
Copy link
Author

Nello-Angelo commented Nov 10, 2024

i resolve with example below but now i get this

│ rpc error: code = Unknown desc = error validating and normalizing app:
│ error validating the repo: error verifying source type: multiple
│ application sources defined: Helm,Plugin
resource "argocd_application" "multiple_sources" {
  for_each = { for key, value in var.multiple_sources_app : key => value }
....
}
    env = optional(list(object({
      name  = string
      value = string
    })), [{ "name" = "", "value" = "" }])

@Nello-Angelo
Copy link
Author

+ create
Terraform will perform the following actions:
  # module.argocd-resources.argocd_application.multiple_sources["gitlab-runner-infra"] will be created
  + resource "argocd_application" "multiple_sources" {
      + cascade  = true
      + id       = (known after apply)
      + status   = (known after apply)
      + validate = true
      + wait     = false
      + metadata {
          + generation       = (known after apply)
          + name             = "gitlab-runner-infra"
          + namespace        = "argocd"
          + resource_version = (known after apply)
          + uid              = (known after apply)
        }
      + spec {
          + project                = "default"
          + revision_history_limit = 10
          + destination {
                name      = null
              + namespace = "gitlab-runner"
              + server    = "https://kubernetes.default.svc"
            }
          + source {
              + chart           = "gitlab-runner"
              + path            = "."
              + repo_url        = "http://charts.gitlab.io/"
              + target_revision = "0.70.1"
              + helm {
                  + value_files = [
                      + null,
                    ]
                }
            }
          + sync_policy {
              + sync_options = [
                  + "CreateNamespace=true",
                ]
              + automated {
                  + prune     = true
                  + self_heal = true
                }
              + managed_namespace_metadata {
                  + annotations = {
                      + "argocd.argoproj.io/managed-by" = "argocd"
                    }
                  + labels      = {
                      + "argocd.argoproj.io/managed-by" = "argocd"
                    }
                }
              + retry {
                  + limit = "5"
                  + backoff {
                      + duration     = "5s"
                      + factor       = "2"
                      + max_duration = "3m"
                    }
                }
            }
        }
      + timeouts {}
    }
Plan: 1 to add, 0 to change, 0 to destroy.
module.argocd-resources.argocd_application.multiple_sources["gitlab-runner-infra"]: Creating...
╷
│ Warning: Value for undeclared variable
│ 
│ The root module does not declare a variable named "cloudflare_token" but a
│ value was found in file ".secrets.auto.tfvars". If you meant to use this
│ value, add a "variable" block to the configuration.
│ 
│ To silence these warnings, use TF_VAR_... environment variables to provide
│ certain "global" settings to all configurations in your organization. To
│ reduce the verbosity of these warnings, use the -compact-warnings option.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
Stack trace from the terraform-provider-argocd_v7.0.3 plugin:
panic: interface conversion: interface {} is nil, not string
goroutine 95 [running]:
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSourceHelm({0xc000fe4130, 0xc000fd3380?, 0x3534eed?})
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:250 +0x994
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSource({0xc000fe40d0, 0x1, 0x3537ddd?})
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:88 +0x29d
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSpec(0x0?)
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:54 +0x33f
github.com/oboukili/terraform-provider-argocd/argocd.expandApplication(_)
	github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:16 +0x10d
github.com/oboukili/terraform-provider-argocd/argocd.resourceArgoCDApplicationCreate({0x3c00320?, 0xc0003bb960}, 0x0?, {0x32d5ec0?, 0xc0001b8500})
	github.com/oboukili/terraform-provider-argocd/argocd/resource_argocd_application.go:86 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000641b20, {0x3c00278, 0xc000ecccf0}, 0xd?, {0x32d5ec0, 0xc0001b8500})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:806 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000641b20, {0x3c00278, 0xc000ecccf0}, 0xc000d01520, 0xc0002a1e80, {0x32d5ec0, 0xc0001b8500})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000a01890, {0x3c00278?, 0xc000eccb40?}, 0xc0003340f0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x3c1b[84](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7376317#L84)0?, 0xc000a01890?}}, {0x3c00278, 0xc000eccb40}, 0x0?)
	github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:38 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x3c002b0?, {0x3c00278?, 0xc000ecc840?}, 0xc0003340a0)
	github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc00099fb80, {0x3c00278?, 0xc000e97e30?}, 0xc0000f27e0)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x340da20?, 0xc00099fb80}, {0x3c00278, 0xc000e97e30}, 0xc0002a1200, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000184600, {0x3c00278, 0xc000e97da0}, {0x3c0f940, 0xc000982000}, 0xc000ec4a20, 0xc000d9c930, 0x5904[85](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7376317#L85)8, 0x0)
	google.golang.org/[email protected]/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000184600, {0x3c0f940, 0xc000982000}, 0xc000ec4a20)
	google.golang.org/[email protected]/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 40
	google.golang.org/[email protected]/server.go:1030 +0x135
Error: The terraform-provider-argocd_v7.0.3 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.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: command terminated with exit code 1

@Nello-Angelo
Copy link
Author

can we ignore this block if fields are null ?

              + helm {
                  + value_files = [
                      + null,
                    ]
                }
            }

@Nello-Angelo
Copy link
Author

Nello-Angelo commented Nov 11, 2024

@the-technat

@Nello-Angelo
Copy link
Author

@the-technat can you watch this panic?

@the-technat
Copy link
Collaborator

Will do, but will take some days before I get time for it.

@the-technat the-technat self-assigned this Nov 11, 2024
@Nello-Angelo
Copy link
Author

does it correct behavior?

@Nello-Angelo
Copy link
Author

any update?
@the-technat

@the-technat
Copy link
Collaborator

I can reproduce the panic using the following TF config:

terraform {
  required_providers {
    argocd = {
      source  = "argoproj-labs/argocd"
      version = "7.1.0"
    }
  }
}

provider "argocd" {
  port_forward_with_namespace = "argocd"
  username = "admin"
  password = "acceptancetesting"
  kubernetes {
    config_context = "kind-argocd"
  }
}

variable "multiple_sources_app" {
  type = map(object({
    managed_namespace_metadata_labels      = optional(map(string))
    managed_namespace_metadata_annotations = optional(map(string))
  }))
  default = {
    managed_namespace_metadata_labels = {"foo" = "bar"}
  }
}

resource "argocd_application" "reproduce" {
 for_each = var.multiple_sources_app
 metadata {
    name      = "kustomize-app"
    namespace = "argocd"
    labels = {
      test = "true"
    }
  }

  cascade = false # disable cascading deletion
  wait    = true

  spec {
    project = "default"

    destination {
      server    = "https://kubernetes.default.svc"
      namespace = "foo"
    }

    source {
      repo_url        = "https://github.com/kubernetes-sigs/kustomize"
      path            = "examples/helloWorld"
      target_revision = "master"
    }

    sync_policy {
       managed_namespace_metadata {
        labels      = each.value.managed_namespace_metadata_labels
        annotations = each.value.managed_namespace_metadata_annotations
      }
      automated {
        prune       = true
        self_heal   = true
        allow_empty = true
      }
      sync_options = ["Validate=false","CreateNamespace=true"]
    }
  }
}

However I have no clue what this tells us. Will have to dig into this further.

@the-technat
Copy link
Collaborator

This type-conversion seems to cause the panic: https://github.com/argoproj-labs/terraform-provider-argocd/blob/main/argocd/structure_application.go#L406-L407. But I don't yet understand what kind of input it doesn't handle/expect and if that's actually something we need to catch there or something we don't expect to be passed in.

@Nello-Angelo
Copy link
Author

maybe you should add a condition if the values ​​of these variables are empty and nothing is passed to them, then simply ignore this block and perhaps indicate in the code that they are optional

@Nello-Angelo
Copy link
Author

Nello-Angelo commented Dec 8, 2024

#513

this feature will help to resolve the error

@the-technat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants