close
The Wayback Machine - https://web.archive.org/web/20201002020800/https://github.com/terraform-aws-modules/terraform-aws-eks/pull/858
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

feat: Ability to manage worker groups as maps #858

Open
wants to merge 2 commits into
base: master
from

Conversation

@grzegorzlisowski
Copy link

@grzegorzlisowski grzegorzlisowski commented May 3, 2020

PR o'clock

Description

Resolves #774

The change is intended to improve the ability to manage worker groups using maps. Which should allow to more flexibly add/remove worker groups (improve this: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/faq.md#how-do-i-safely-remove-old-worker-groups).

The change includes suggested in #774 changes which include:

  • create separate submodule for worker_groups
  • the submodule includes only LaunchTemplate support

Change to the worker groups definitions:

  • to use new worker groups definitions use:
    worker_groups = {}

Checklist

@barryib
Copy link
Member

@barryib barryib commented May 4, 2020

Thanks @grzegorzlisowski for opening this PR. Actually, this is something we want to add into this module and totally drop loops with count in favor of for/for_each.

With that said, it would be nice to split the feature into a new submodule. We started some discussion at #774.

@js-timbirkett is maybe busy actually, so if you can open a PR to address #774 it would be very appreciated.

aws_auth.tf Outdated
@@ -38,11 +37,27 @@ locals {
}
]

auth_launch_template_worker_roles_ext = [
for k, v in local.worker_group_launch_template_configurations_ext : {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.manage_worker_iam_resources ? aws_iam_instance_profile.workers_launch_template_ext[k].role : data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile_ext[k].role_name}"

This comment has been minimized.

@mbarrien

mbarrien May 6, 2020

Need to replace the :aws: portion of the ARN with :${data.aws_partition.current.partition}: (same in auth_worker_roles_ext below)

This comment has been minimized.

data.tf Outdated
name = each.value["iam_instance_profile_name"]
}

data "aws_region" "current" {}

This comment has been minimized.

@mbarrien

mbarrien May 6, 2020

Doesn't seem to be used. Remove?

This comment has been minimized.

@grzegorzlisowski grzegorzlisowski force-pushed the Worldremit:feature/devops-1421 branch 4 times, most recently from 9820bb7 to 695030c May 6, 2020

dynamic mixed_instances_policy {
iterator = item
for_each = ((lookup(var.worker_groups[each.key], "override_instance_types", null) != null) || (lookup(var.worker_groups[each.key], "on_demand_allocation_strategy", null) != null)) ? list(each.value) : []

This comment has been minimized.

@barryib

barryib May 8, 2020
Member

does var.worker_groups[each.key] different from each.value ? If not, I'll prefer to use that. It'll more consistant for readability.

This comment has been minimized.

@grzegorzlisowski

grzegorzlisowski May 8, 2020
Author

Unfortunately, it is different according to my analysis. This is only to avoid changing old logic. See here: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/workers_launch_template.tf#L93

This comment has been minimized.

@grzegorzlisowski

grzegorzlisowski May 8, 2020
Author

Sorry, responded too early.
This is what came as an argument from user: var.worker_groups_launch_template[count.index] while "each.value" represents what is already a merge with module defaults. Which IMHO could change original behaviour


dynamic launch_template {
iterator = item
for_each = ((lookup(var.worker_groups[each.key], "override_instance_types", null) != null) || (lookup(var.worker_groups[each.key], "on_demand_allocation_strategy", null) != null)) ? [] : list(each.value)

This comment has been minimized.

@barryib

barryib May 8, 2020
Member

does var.worker_groups[each.key] different from each.value ?

This comment has been minimized.

@grzegorzlisowski

grzegorzlisowski May 8, 2020
Author

This is the same as the previous case above

@barryib
Copy link
Member

@barryib barryib commented May 8, 2020

the old way of defining worker groups still possible for some backward compatibility and easier migration to the new version (after some time old way of defining worker_groups could be dropped entirely)

I was wondering if we shouldn't drop this directly. Because for existing worker group, users will have to move resources in the state. So why not move them directly into a map ?

For locals, shouldn't we move https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/local.tf#L34-L100 and into the submodule ?

@grzegorzlisowski
Copy link
Author

@grzegorzlisowski grzegorzlisowski commented May 8, 2020

My assumption was that users could apply the new module and add new worker groups using maps then migrate K8S resources to new nodes and then remove old groups simply by removing the list.

Those locals I have left in the original place as I assumed we still use them in "legacy" worker definitions. If we will just drop old worker_groups definitions then those should be moved.

@grzegorzlisowski grzegorzlisowski force-pushed the Worldremit:feature/devops-1421 branch from 695030c to d5582b6 May 14, 2020
@stevehipwell
Copy link

@stevehipwell stevehipwell commented May 21, 2020

Do we know what is blocking this?

@grzegorzlisowski
Copy link
Author

@grzegorzlisowski grzegorzlisowski commented May 21, 2020

I presume review and approval? I'm not sure why this "Semantic Pull Request" check is not executing

@venky999
Copy link

@venky999 venky999 commented Jun 4, 2020

we can use worker_groups as a list of maps with unique key name.. instead of map so that it would be more cleaner and we can do ..

worker_groups = { for worker_group in var.worker_groups : worker_group.name => worker_group }

worker_group_configurations = {
    for k, v in local.worker_groups : k => merge(
      local.workers_group_defaults,
      v,
    ) if var.create_workers
  }
}
}

data "aws_ami" "eks_worker" {
filter {

This comment has been minimized.

@venky999

venky999 Jun 4, 2020

can we use for_each and add support for worker_node_version for each workers_group and the default value will be cluster_version if worker_node_version not specified

This comment has been minimized.

@grzegorzlisowski

grzegorzlisowski Jun 23, 2020
Author

What do you mean by 'worker_node_version'?

@grzegorzlisowski
Copy link
Author

@grzegorzlisowski grzegorzlisowski commented Jun 23, 2020

we can use worker_groups as a list of maps with unique key name.. instead of map so that it would be more cleaner and we can do ..

worker_groups = { for worker_group in var.worker_groups : worker_group.name => worker_group }

worker_group_configurations = {
    for k, v in local.worker_groups : k => merge(
      local.workers_group_defaults,
      v,
    ) if var.create_workers
  }
}

It could be done but I presume it might make sense to keep the same approach as for node_groups where maps are used as an input.

@grzegorzlisowski grzegorzlisowski force-pushed the Worldremit:feature/devops-1421 branch 3 times, most recently from bf35ebe to 8d8bd48 Jun 24, 2020
@ZeroDeth
Copy link

@ZeroDeth ZeroDeth commented Jul 4, 2020

Error sometimes appear randomly without changing anything in code.

Error: Inconsistent conditional result types

  on .terraform/modules/eks_0/modules/worker_groups/data.tf line 5, in data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile":
   5:   for_each = var.manage_worker_iam_resources ? {} : local.worker_group_configurations
    |----------------
    | local.worker_group_configurations is object with 3 attributes
    | var.manage_worker_iam_resources is false

The true and false result expressions must have consistent types. The given
expressions are object and object, respectively.
@ZeroDeth
Copy link

@ZeroDeth ZeroDeth commented Jul 4, 2020

Error sometimes appear randomly without changing anything in code.

Error: Inconsistent conditional result types

  on .terraform/modules/eks_0/modules/worker_groups/data.tf line 5, in data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile":
   5:   for_each = var.manage_worker_iam_resources ? {} : local.worker_group_configurations
    |----------------
    | local.worker_group_configurations is object with 3 attributes
    | var.manage_worker_iam_resources is false

The true and false result expressions must have consistent types. The given
expressions are object and object, respectively.

Issues happen when adding a second group to worker_grpups

@grzegorzlisowski
Copy link
Author

@grzegorzlisowski grzegorzlisowski commented Jul 9, 2020

@ZeroDeth
Could you share your setup so I will try to recreate the issue?

@grzegorzlisowski grzegorzlisowski force-pushed the Worldremit:feature/devops-1421 branch 3 times, most recently from 1cbf970 to 87edcca Aug 3, 2020
- Create separate defaults for node groups
- Workers IAM management left outside of module as both node_group and worker_groups uses them
…nation and improve logic when cluster is disabled
@grzegorzlisowski grzegorzlisowski force-pushed the Worldremit:feature/devops-1421 branch from 87edcca to da785fc Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.