Skip to content

Commit

Permalink
feat: add podAntiaffinity
Browse files Browse the repository at this point in the history
  • Loading branch information
Monska85 committed May 13, 2024
1 parent 0fc84ff commit caa5266
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 49 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.5.0] - 2024-05-13

[Compare with previous version](https://github.com/sparkfabrik/terraform-helm-ingress-nginx/compare/0.4.0...0.5.0)

### Added

- Default value for chart version. The values file shipped with the module refers to the declared version of the chart.
- `podAntiAffinity` configuration enabled by default. It is possible to disable it by setting the new `set_default_pod_anti_affinity` variable to `false`.
- Add the `common_labels` variable to allow the user to set common labels for all resources created by the chart.

## [0.4.0] - 2023-12-22

[Compare with previous version](https://github.com/sparkfabrik/terraform-helm-ingress-nginx/compare/0.3.0...0.4.0)
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ This is Terraform module to install and configure the Nginx Ingress Controller.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_values"></a> [additional\_values](#input\_additional\_values) | Additional values to pass to the helm chart | `list(string)` | `[]` | no |
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Chart version of the ingress controller | `string` | n/a | yes |
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create namespace for the ingress controller. If false, the namespace must be created before using this module | `bool` | `true` | no |
| <a name="input_helm_release_name"></a> [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm release | `string` | `"ingress-nginx"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of the ingress controller | `string` | n/a | yes |
| <a name="input_namespace_additional_labels"></a> [namespace\_additional\_labels](#input\_namespace\_additional\_labels) | Additional labels for the namespace of the ingress controller | `map(string)` | `{}` | no |
| <a name="input_additional_values"></a> [additional\_values](#input\_additional\_values) | Additional values to pass to the helm chart. | `list(string)` | `[]` | no |
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Chart version of the ingress controller. Consider the default value the reference version of the module and the base of the values.yaml.tftpl file. | `string` | `"4.10.1"` | no |
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create namespace for the ingress controller. If false, the namespace must be created before using this module. | `bool` | `true` | no |
| <a name="input_helm_release_name"></a> [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm release. | `string` | `"ingress-nginx"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of the ingress controller. | `string` | n/a | yes |
| <a name="input_namespace_additional_labels"></a> [namespace\_additional\_labels](#input\_namespace\_additional\_labels) | Additional labels for the namespace of the ingress controller. | `map(string)` | `{}` | no |
| <a name="input_set_default_pod_anti_affinity"></a> [set\_default\_pod\_anti\_affinity](#input\_set\_default\_pod\_anti\_affinity) | Set the podAntiAffinity for the ingress controller. | `bool` | `true` | no |

## Outputs

Expand Down
33 changes: 0 additions & 33 deletions files/values.yaml

This file was deleted.

63 changes: 63 additions & 0 deletions files/values.yaml.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# https://github.com/kubernetes/ingress-nginx/blob/helm-chart-4.10.1/charts/ingress-nginx/values.yaml

%{~ if length(common_labels) > 0 }
%{~ for lbl_k, lbl_v in common_labels }
commonLabels:
${lbl_k}: "${lbl_k}"
%{~ endfor }
%{~ endif }

controller:
resources:
requests:
cpu: 50m
memory: 64Mi
autoscaling:
enabled: "true"
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
config:
body-size: "0"
hsts-include-subdomains: "true"
hsts-max-age: "63072000"
hsts-preload: "true"
proxy-body-size: "0"
proxy-buffer-size: "128k"
proxy-connect-timeout: "15"
proxy-read-timeout: "600"
proxy-send-timeout: "600"
server-name-hash-bucket-size: "256"
ssl-redirect: "true"
ssl-reject-handshake: "true"
service:
externalTrafficPolicy: "Local"
%{~ if set_default_pod_anti_affinity }
# Set the default antiaffinity. If you eneable the hpa, the pods will be distributed in different nodes.
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- ingress-nginx
- key: app.kubernetes.io/instance
operator: In
values:
- ingress-nginx
- key: app.kubernetes.io/component
operator: In
values:
- controller
topologyKey: "kubernetes.io/hostname"
%{~ endif ~}

defaultBackend:
enabled: true
resources:
requests:
cpu: 10m
memory: 20Mi
10 changes: 9 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ resource "helm_release" "this" {
namespace = var.create_namespace ? kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name

values = concat(
[file("${path.module}/files/values.yaml")],
[
templatefile(
"${path.module}/files/values.yaml.tftpl",
{
common_labels = var.common_labels
set_default_pod_anti_affinity = var.set_default_pod_anti_affinity
}
)
],
var.additional_values
)
}
33 changes: 24 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
variable "helm_release_name" {
description = "Name of the helm release."
type = string
default = "ingress-nginx"
}

variable "chart_version" {
description = "Chart version of the ingress controller"
description = "Chart version of the ingress controller. Consider the default value the reference version of the module and the base of the values.yaml.tftpl file."
type = string
default = "4.10.1"
}

variable "create_namespace" {
description = "Create namespace for the ingress controller. If false, the namespace must be created before using this module"
description = "Create namespace for the ingress controller. If false, the namespace must be created before using this module."
type = bool
default = true
}

variable "namespace" {
description = "Namespace of the ingress controller"
description = "Namespace of the ingress controller."
type = string
}

variable "namespace_additional_labels" {
description = "Additional labels for the namespace of the ingress controller"
description = "Additional labels for the namespace of the ingress controller."
type = map(string)
default = {}
}

variable "additional_values" {
description = "Additional values to pass to the helm chart"
description = "Additional values to pass to the helm chart."
type = list(string)
default = []
}

variable "helm_release_name" {
description = "Name of the helm release"
type = string
default = "ingress-nginx"
variable "set_default_pod_anti_affinity" {
description = "Set the podAntiAffinity for the ingress controller."
type = bool
default = true
}

variable "common_labels" {
description = "Set of labels to apply to all resources."
type = map(string)
default = {
managed-by = "terraform"
}
}

0 comments on commit caa5266

Please sign in to comment.