Skip to content

Commit 105faa8

Browse files
committed
Add the ability to inject labels on the kustomization controller pods
Also remove an unused variable.
1 parent d176eec commit 105faa8

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

kustomization.yaml.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ patches:
1515
kind: ServiceAccount
1616
name: kustomize-controller
1717
labelSelector: app.kubernetes.io/part-of=flux
18+
- patch: |
19+
apiVersion: apps/v1
20+
kind: Deployment
21+
metadata:
22+
name: kustomize-controller
23+
spec:
24+
template:
25+
metadata:
26+
labels: ${pod_labels}
27+
target:
28+
kind: Deployment
29+
name: kustomize-controller
1830
- patch: |
1931
apiVersion: kustomize.toolkit.fluxcd.io/v1
2032
kind: Kustomization

main.tf

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
################################################################################
44
resource "kubernetes_namespace" "flux_system_ns" {
55
metadata {
6-
name = var.namespace
7-
annotations = var.annotations
6+
name = var.namespace
87
}
98

109
lifecycle {
@@ -14,9 +13,8 @@ resource "kubernetes_namespace" "flux_system_ns" {
1413

1514
resource "kubernetes_secret" "flux_system_secret" {
1615
metadata {
17-
name = "flux-system"
18-
namespace = var.namespace
19-
annotations = var.annotations
16+
name = "flux-system"
17+
namespace = var.namespace
2018
}
2119

2220
data = {
@@ -32,9 +30,8 @@ resource "kubernetes_config_map" "flux_cluster_variables" {
3230
count = length(var.cluster_variables) > 0 ? 1 : 0
3331

3432
metadata {
35-
name = "terraform-flux-cluster-variables"
36-
namespace = var.namespace
37-
annotations = var.annotations
33+
name = "terraform-flux-cluster-variables"
34+
namespace = var.namespace
3835
}
3936
data = var.cluster_variables
4037

@@ -53,6 +50,7 @@ resource "flux_bootstrap_git" "this" {
5350
kustomization_override = templatefile("${path.module}/kustomization.yaml.tpl", {
5451
service_account_annotations = yamlencode(var.service_account_annotations)
5552
service_account_labels = yamlencode(var.service_account_labels)
53+
pod_labels = yamlencode(var.pod_labels)
5654
})
5755
version = var.fluxcd_version
5856
depends_on = [kubernetes_secret.flux_system_secret]

main.tftest.hcl

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ variables {
1919
service_account_labels = {
2020
"foo" = "bar"
2121
}
22+
pod_labels = {
23+
"some.cloud.provider/identity" = "true"
24+
}
2225
}
2326

2427
run "validate" {

variables.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ variable "service_account_labels" {
3131
default = {}
3232
}
3333

34+
variable "pod_labels" {
35+
description = "Labels to add to the kustomize-controller pods"
36+
type = map(string)
37+
default = {}
38+
}
39+
3440
variable "controller_ssh_known_hosts" {
3541
description = "SSH known hosts for flux controller. Defaults to github.com ECDSA key."
3642
type = string
@@ -43,12 +49,6 @@ variable "namespace" {
4349
default = "flux-system"
4450
}
4551

46-
variable "annotations" {
47-
description = "Annotations to add to created kubernetes resources"
48-
type = map(string)
49-
default = {}
50-
}
51-
5252
variable "cluster_variables" {
5353
description = "Key-value pairs to create 'terraform-flux-cluster-variables' ConfigMap for flux/Kustomization postBuild use"
5454
type = map(string)

0 commit comments

Comments
 (0)