Skip to content

Commit

Permalink
fix: allow component to deploy correctly when create_namespace is fal…
Browse files Browse the repository at this point in the history
…se (#1011)

Co-authored-by: Nuru <[email protected]>
  • Loading branch information
agfunderburg10 and Nuru committed Jun 2, 2024
1 parent 902271c commit b9380c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
5 changes: 2 additions & 3 deletions modules/eks/metrics-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ components:
|------|--------|---------|
| <a name="module_eks"></a> [eks](#module\_eks) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
| <a name="module_iam_roles"></a> [iam\_roles](#module\_iam\_roles) | ../../account-map/modules/iam-roles | n/a |
| <a name="module_metrics_server"></a> [metrics\_server](#module\_metrics\_server) | cloudposse/helm-release/aws | 0.10.0 |
| <a name="module_metrics_server"></a> [metrics\_server](#module\_metrics\_server) | cloudposse/helm-release/aws | 0.10.1 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
## Resources
| Name | Type |
|------|------|
| [kubernetes_namespace.default](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
| [aws_eks_cluster_auth.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source |
## Inputs
Expand All @@ -86,7 +85,7 @@ components:
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Specify the exact chart version to install. If this is not specified, the latest version is installed. | `string` | `"6.2.6"` | no |
| <a name="input_cleanup_on_fail"></a> [cleanup\_on\_fail](#input\_cleanup\_on\_fail) | Allow deletion of new resources created in this upgrade when upgrade fails. | `bool` | `true` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create the namespace if it does not yet exist. Defaults to `false`. | `bool` | `true` | no |
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create the namespace if it does not yet exist. Defaults to `true`. | `bool` | `true` | no |
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| <a name="input_eks_component_name"></a> [eks\_component\_name](#input\_eks\_component\_name) | The name of the eks component | `string` | `"eks/cluster"` | no |
Expand Down
40 changes: 19 additions & 21 deletions modules/eks/metrics-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ locals {
enabled = module.this.enabled
}

resource "kubernetes_namespace" "default" {
count = local.enabled && var.create_namespace ? 1 : 0

metadata {
name = var.kubernetes_namespace

labels = module.this.tags
}
moved {
from = kubernetes_namespace.default
to = module.metrics_server.kubernetes_namespace.default
}

module "metrics_server" {
source = "cloudposse/helm-release/aws"
version = "0.10.0"
version = "0.10.1"

name = "" # avoids hitting length restrictions on IAM Role names
chart = var.chart
repository = var.chart_repository
description = var.chart_description
chart_version = var.chart_version
wait = var.wait
atomic = var.atomic
cleanup_on_fail = var.cleanup_on_fail
timeout = var.timeout

name = "" # avoids hitting length restrictions on IAM Role names
chart = var.chart
repository = var.chart_repository
description = var.chart_description
chart_version = var.chart_version
kubernetes_namespace = join("", kubernetes_namespace.default.*.id)
create_namespace = false
wait = var.wait
atomic = var.atomic
cleanup_on_fail = var.cleanup_on_fail
timeout = var.timeout
kubernetes_namespace = var.kubernetes_namespace
create_namespace_with_kubernetes = var.create_namespace

eks_cluster_oidc_issuer_url = replace(module.eks.outputs.eks_cluster_identity_oidc_issuer, "https://", "")

Expand All @@ -47,7 +43,9 @@ module "metrics_server" {
# metrics-server-specific values
yamlencode({
podLabels = merge({
chart = var.chart
chart = var.chart
# TODO: These should be configurable
# Chart should default to https://kubernetes-sigs.github.io/metrics-server/
repo = "bitnami"
component = "hpa"
namespace = var.kubernetes_namespace
Expand Down
5 changes: 3 additions & 2 deletions modules/eks/metrics-server/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ variable "chart" {
variable "chart_repository" {
type = string
description = "Repository URL where to locate the requested chart."
default = "https://charts.bitnami.com/bitnami"
# TODO: Chart should default to https://kubernetes-sigs.github.io/metrics-server/
default = "https://charts.bitnami.com/bitnami"
}

variable "chart_version" {
Expand Down Expand Up @@ -53,7 +54,7 @@ variable "resources" {

variable "create_namespace" {
type = bool
description = "Create the namespace if it does not yet exist. Defaults to `false`."
description = "Create the namespace if it does not yet exist. Defaults to `true`."
default = true
}

Expand Down

0 comments on commit b9380c1

Please sign in to comment.