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

Unable to customize CoreDNS configuration when provisioning via oke module #974

Open
ddevadat opened this issue Dec 18, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@ddevadat
Copy link
Contributor

ddevadat commented Dec 18, 2024

My requirement is during oke provisioning, i want to customize CoreDNS configuration like change minimum replica count.
My tfvars for cluster_addon variable looks

  cluster_addons = {
    "CoreDNS" = {
      remove_addon_resources_on_delete = true
      configurations = [
        {
          key   = "minReplica"
          value = "1"
        },
        {
          key   = "nodesPerReplica"
          value = "1"
        }
      ]
    }
  }

i am invoking oke like


module "oke_blue" {
  source                             = "oracle-terraform-modules/oke/oci" 
  version                            = "5.2.2"
....
....
  cluster_addons          = var.cluster_addons

Error received

 Error: 409-Conflict, addon CoreDNS exists
 Suggestion: The resource is in a conflicted state. Please retry again or contact support for help with service: Containerengine Addon
 Documentation: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/containerengine_addon
 API Reference: https://docs.oracle.com/iaas/api/#/en/containerengine/20180222/Cluster/InstallAddon
 Request Target: POST https://containerengine.ap-mumbai-1.oci.oraclecloud.com/20180222/clusters/ocid1.cluster.oc1.ap-mumbai-1.aaaaaaaa/addons
 Provider version: 6.20.0, released on 2024-12-11.
 Service: Containerengine Addon
 Operation Name: InstallAddon
 OPC request ID: 33753b4b49e2eb439c99237106fB9DF718AA4F847A


   with module.oke_blue[0].module.cluster-addons[0].oci_containerengine_addon.secondary_addon["CoreDNS"],
   on .terraform/modules/oke_blue/modules/cluster-addons/addons.tf line 53, in resource "oci_containerengine_addon" "secondary_addon":
   53: resource "oci_containerengine_addon" "secondary_addon" {

Potential solution
modules/cluster-addons/addons.tf

Add the flag
override_existing = true

resource "oci_containerengine_addon" "primary_addon" {
  for_each = { for k, v in local.addons_with_defaults : k => v if contains(local.primary_addons, k) }

  addon_name = each.key
  cluster_id = var.cluster_id

  remove_addon_resources_on_delete = lookup(each.value, "remove_addon_resources_on_delete", true)

  dynamic "configurations" {
    for_each = lookup(each.value, "configurations", [])
    iterator = config

    content {
      key   = tostring(lookup(config.value, "key"))
      value = tostring(lookup(config.value, "value"))
    }
  }
  override_existing = lookup(each.value, "override_existing", false)
  version = lookup(each.value, "version", null)

  lifecycle {

    precondition {
      condition     = contains(local.supported_addons, each.key)
      error_message = <<-EOT
      The addon ${each.key} is not supported.
      The list of supported addons is: ${join(", ", local.supported_addons)}.
      EOT
    }
  }
}

resource "oci_containerengine_addon" "secondary_addon" {
  for_each   = { for k, v in local.addons_with_defaults : k => v if !contains(local.primary_addons, k) }
  depends_on = [oci_containerengine_addon.primary_addon]
  addon_name = each.key
  cluster_id = var.cluster_id

  remove_addon_resources_on_delete = lookup(each.value, "remove_addon_resources_on_delete", true)

  dynamic "configurations" {
    for_each = lookup(each.value, "configurations", [])
    iterator = config

    content {
      key   = tostring(lookup(config.value, "key"))
      value = tostring(lookup(config.value, "value"))
    }
  }

  override_existing = lookup(each.value, "override_existing", false)
  version = lookup(each.value, "version", null)

  lifecycle {

    precondition {
      condition     = contains(local.supported_addons, each.key)
      error_message = <<-EOT
      The addon ${each.key} is not supported.
      The list of supported addons is: ${join(", ", local.supported_addons)}.
      EOT
    }
  }
}

Then define the cluster_addon variable like

  cluster_addons = {
    "CoreDNS" = {
      remove_addon_resources_on_delete = true
      override_existing                = true
      configurations = [
        {
          key   = "minReplica"
          value = "1"
        },
        {
          key   = "nodesPerReplica"
          value = "1"
        }
      ]
    }
  }
@ddevadat ddevadat added the bug Something isn't working label Dec 18, 2024
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

1 participant