Skip to content

Commit 4bea633

Browse files
authored
Merge pull request #2 from sparkfabrik/feat/add_create_default_pod_anti_affinity_var
feat: add default podAntiAffinity configuration that can be disabled using a new variable
2 parents 0f90aa5 + a259e4f commit 4bea633

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
## [0.3.0] - 2024-07-10
12+
13+
[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.2.0...0.3.0)
14+
15+
### Added
16+
17+
- Add the `create_default_pod_anti_affinity` variable to allow the creation of the default podAntiAffinity rule in the helm values.
18+
1119
## [0.2.0] - 2024-07-04
1220

1321
[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.1.0...0.2.0)
1422

23+
### Added
24+
1525
- Add dependency on the Gitlab variables to prevent their creation before the helm release.
1626
- Add the `gitlab_agent_append_to_config_file` variable to allow customizations to the agent configuration file keeping the access for the root namespace managed by the module.
1727

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ provider "gitlab" {
4949
|------|-------------|------|---------|:--------:|
5050
| <a name="input_agent_kas_address"></a> [agent\_kas\_address](#input\_agent\_kas\_address) | The address of the Gitlab Kubernetes Agent Server (KAS). | `string` | `"kas.gitlab.com"` | no |
5151
| <a name="input_agent_replicas"></a> [agent\_replicas](#input\_agent\_replicas) | The number of replicas of the Gitlab Agent. | `number` | `1` | no |
52+
| <a name="input_create_default_pod_anti_affinity"></a> [create\_default\_pod\_anti\_affinity](#input\_create\_default\_pod\_anti\_affinity) | Create default podAntiAffinity rules for the Gitlab Agent pods. | `bool` | `true` | no |
5253
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create namespace for the helm release. If false, the namespace must be created before using this module. | `bool` | `true` | no |
5354
| <a name="input_gitlab_agent_append_to_config_file"></a> [gitlab\_agent\_append\_to\_config\_file](#input\_gitlab\_agent\_append\_to\_config\_file) | Append the Gitlab Agent configuration to the configuration file created for the entire root namespace. This variable is only used when `gitlab_agent_grant_access_to_entire_root_namespace` is true. | `string` | `""` | no |
5455
| <a name="input_gitlab_agent_branch_name"></a> [gitlab\_agent\_branch\_name](#input\_gitlab\_agent\_branch\_name) | The branch name where the Gitlab Agent configuration will be stored. | `string` | `"main"` | no |

files/values.yaml.tftpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ resources:
1717
requests:
1818
cpu: 20m
1919
memory: 32Mi
20+
21+
%{~ if create_default_pod_anti_affinity }
22+
# We leverage the Helm standard labels for the helm release name (`app.kubernetes.io/instance`)
23+
# to create a default pod anti-affinity rule for the agent pods. Refer to the Helm documentation
24+
# about standard labels here: https://helm.sh/docs/chart_best_practices/labels/#standard-labels.
25+
affinity:
26+
podAntiAffinity:
27+
preferredDuringSchedulingIgnoredDuringExecution:
28+
- weight: 100
29+
podAffinityTerm:
30+
labelSelector:
31+
matchExpressions:
32+
- key: app.kubernetes.io/instance
33+
operator: In
34+
values:
35+
- "${helm_release_name}"
36+
topologyKey: kubernetes.io/hostname
37+
%{~ endif ~}

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ resource "helm_release" "this" {
129129
agent_replicas = var.agent_replicas
130130
agent_kas_address = var.agent_kas_address
131131
agent_token_secret_name = kubernetes_secret_v1.gitlab_agent_token_secret.metadata[0].name
132+
# Variables used to configure the default podAntiAffinity for the Gitlab Agent
133+
create_default_pod_anti_affinity = var.create_default_pod_anti_affinity
134+
helm_release_name = var.helm_release_name
132135
}
133136
),
134137
],

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,9 @@ variable "agent_kas_address" {
131131
type = string
132132
default = "kas.gitlab.com"
133133
}
134+
135+
variable "create_default_pod_anti_affinity" {
136+
description = "Create default podAntiAffinity rules for the Gitlab Agent pods."
137+
type = bool
138+
default = true
139+
}

0 commit comments

Comments
 (0)