Skip to content

Commit d0293f4

Browse files
committed
feat: fully integrates kyverno
1 parent db7f953 commit d0293f4

File tree

111 files changed

+3341
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3341
-800
lines changed

packages/infrastructure/kube_argo/main.tf

+18-3
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ resource "kubernetes_config_map" "artifacts" {
223223
namespace = local.namespace
224224
labels = module.util_controller.labels
225225
annotations = {
226-
"workflows.argoproj.io/default-artifact-repository" = "s3"
227-
"reflector.v1.k8s.emberstack.com/reflection-allowed" = "true"
228-
"reflector.v1.k8s.emberstack.com/reflection-auto-enabled" = "true"
226+
"workflows.argoproj.io/default-artifact-repository" = "s3"
229227
}
230228
}
231229
data = {
@@ -239,6 +237,13 @@ resource "kubernetes_config_map" "artifacts" {
239237
}
240238
}
241239

240+
module "sync_artifact_config_map" {
241+
source = "../kube_sync_config_map"
242+
243+
config_map_name = kubernetes_config_map.artifacts.metadata[0].name
244+
config_map_namespace = kubernetes_config_map.artifacts.metadata[0].namespace
245+
}
246+
242247
/***************************************
243248
* Database Backend
244249
***************************************/
@@ -600,6 +605,13 @@ resource "kubectl_manifest" "pdb_server" {
600605
depends_on = [helm_release.argo]
601606
}
602607

608+
module "image_cache" {
609+
source = "../kube_node_image_cache"
610+
images = [
611+
"quay.io/argoproj/argoexec:v3.5.11"
612+
]
613+
}
614+
603615
/***************************************
604616
* Argo Events
605617
***************************************/
@@ -1093,3 +1105,6 @@ resource "kubectl_manifest" "test_workflow_template" {
10931105
force_conflicts = true
10941106
}
10951107

1108+
1109+
1110+

packages/infrastructure/kube_buildkit/main.tf

+7
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "autoscaler" {
311311
depends_on = [module.buildkit]
312312
}
313313

314+
module "image_cache" {
315+
source = "../kube_node_image_cache"
316+
images = [
317+
"docker.io/moby/buildkit:${var.buildkit_image_version}"
318+
]
319+
}
320+
314321
/***************************************
315322
* Buildkit Scale-To-Zero
316323
*

packages/infrastructure/kube_cert_issuers/main.tf

+7-4
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,19 @@ resource "kubernetes_config_map" "ca_bundle" {
280280
name = "internal-ca"
281281
labels = data.pf_kube_labels.labels.labels
282282
namespace = var.namespace
283-
annotations = {
284-
"reflector.v1.k8s.emberstack.com/reflection-auto-enabled" = "true"
285-
"reflector.v1.k8s.emberstack.com/reflection-allowed" = "true"
286-
}
287283
}
288284
data = {
289285
"ca.crt" = vault_pki_secret_backend_root_cert.pki_internal.issuing_ca
290286
}
291287
}
292288

289+
module "sync_ca_bundle" {
290+
source = "../kube_sync_config_map"
291+
292+
config_map_name = kubernetes_config_map.ca_bundle.metadata[0].name
293+
config_map_namespace = kubernetes_config_map.ca_bundle.metadata[0].namespace
294+
}
295+
293296
//////////////////////////////////
294297
/// Regular certs - RSA
295298
//////////////////////////////////

packages/infrastructure/kube_cloudnative_pg/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ resource "kubectl_manifest" "pdb" {
200200
depends_on = [helm_release.cnpg]
201201
}
202202

203+
# This needs to be updated when the helm version is updated
204+
module "image_cache" {
205+
source = "../kube_node_image_cache"
206+
images = [
207+
"ghcr.io/cloudnative-pg/cloudnative-pg:1.24.1",
208+
"ghcr.io/cloudnative-pg/postgresql:16.4-43"
209+
]
210+
}
211+
203212
/***************************************
204213
* Volume Snapshot Class (for backups)
205214
***************************************/

packages/infrastructure/kube_core_dns/main.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ module "core_dns" {
163163
var.monitoring_enabled ? [
164164
{
165165
name = "proxy"
166-
image_registry = module.pull_through.quay_registry
166+
image_registry = "quay.io"
167+
image_registry = "quay.io"
167168
image_repository = "brancz/kube-rbac-proxy"
168169
image_tag = "v0.17.1"
169170

@@ -215,8 +216,8 @@ module "core_dns" {
215216
service_ip = var.service_ip
216217
service_name = "kube-dns" // By convention, this must be available at kube-system/kube-dns
217218

218-
vpa_enabled = var.vpa_enabled
219-
219+
vpa_enabled = var.vpa_enabled
220+
node_image_cached_enabled = false // This is deployed before Kyverno is available
220221

221222
extra_pod_labels = {
222223
"k8s-app" = "kube-dns"

packages/infrastructure/kube_cron_job/main.tf

+6
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,9 @@ resource "kubectl_manifest" "pdb" {
182182
depends_on = [kubectl_manifest.cron_job]
183183
}
184184

185+
module "image_cache" {
186+
count = var.node_image_cached_enabled ? 1 : 0
187+
source = "../kube_node_image_cache"
188+
189+
images = tolist(toset([for container in var.containers : "${container.image_registry}/${container.image_repository}:${container.image_tag}"]))
190+
}

packages/infrastructure/kube_cron_job/vars.tf

+6
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,9 @@ variable "pull_through_cache_enabled" {
307307
type = bool
308308
default = true
309309
}
310+
311+
variable "node_image_cached_enabled" {
312+
description = "Whether to add the container images to the node image cache for faster startup times"
313+
type = bool
314+
default = false
315+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Maintainer Notes
2+
3+
No notes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Kubernetes DaemonSet
2+
3+
Provides a production-hardened instance of a Kubernetes [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/)
4+
with the following enhancements:
5+
6+
- Standardized resource labels
7+
- Pod and container security hardening
8+
- Temporary directory mounting
9+
- [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) and [Secret](https://kubernetes.io/docs/concepts/configuration/secret/) mounting
10+
- [Downward-API](https://kubernetes.io/docs/concepts/workloads/pods/downward-api/) integrations
11+
- Service account configuration with default permissions
12+
- [Readiness and liveness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) configurations
13+
- Automatic reloading via the [Reloader](https://github.com/stakater/Reloader)
14+
- [Vertical pod autoscaling](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler)
15+
- [Pod disruption budget](https://kubernetes.io/docs/tasks/run-application/configure-pdb/)
16+
- [Toleration](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) switches for the various Panfactum node classes
17+
18+
## Usage
19+
20+
### Basics
21+
22+
This module follows the basic workload deployment patterns describe in [this guide](/docs/main/guides/deploying-workloads/basics).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: submodule
2+
status: stable
3+
group: kubernetes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
terraform {
2+
required_providers {
3+
kubernetes = {
4+
source = "hashicorp/kubernetes"
5+
version = "2.27.0"
6+
}
7+
kubectl = {
8+
source = "alekc/kubectl"
9+
version = "2.0.4"
10+
}
11+
random = {
12+
source = "hashicorp/random"
13+
version = "3.6.0"
14+
}
15+
pf = {
16+
source = "panfactum/pf"
17+
version = "0.0.3"
18+
}
19+
}
20+
}
21+
22+
locals {
23+
all_ports = merge([for container_name, config in var.containers : config.ports]...)
24+
service_ports = { for name, config in local.all_ports : name => {
25+
pod_port = config.port
26+
service_port = config.service_port
27+
protocol = config.protocol
28+
} if config.expose_on_service }
29+
}
30+
31+
// This is needed b/c this can never
32+
// change without destroying the deployment first
33+
resource "random_id" "daemon_set_id" {
34+
byte_length = 8
35+
}
36+
37+
data "pf_kube_labels" "labels" {
38+
module = "kube_daemon_set"
39+
}
40+
41+
module "pod_template" {
42+
source = "../kube_pod"
43+
44+
# Pod metadata
45+
namespace = var.namespace
46+
service_account = kubernetes_service_account.service_account.metadata[0].name
47+
workload_name = var.name
48+
match_labels = { id = random_id.daemon_set_id.hex }
49+
dns_policy = var.dns_policy
50+
host_network = var.host_network
51+
extra_pod_annotations = var.extra_pod_annotations
52+
extra_pod_labels = var.extra_pod_labels
53+
pod_version_labels_enabled = var.pod_version_labels_enabled
54+
extra_labels = data.pf_kube_labels.labels.labels
55+
56+
# Container configuration
57+
common_env = var.common_env
58+
common_secrets = var.common_secrets
59+
common_env_from_secrets = var.common_env_from_secrets
60+
common_env_from_config_maps = var.common_env_from_config_maps
61+
containers = var.containers
62+
pull_through_cache_enabled = var.pull_through_cache_enabled
63+
64+
# Mount configuration
65+
config_map_mounts = var.config_map_mounts
66+
secret_mounts = var.secret_mounts
67+
tmp_directories = var.tmp_directories
68+
mount_owner = var.mount_owner
69+
70+
# Scheduling params
71+
priority_class_name = var.priority_class_name
72+
burstable_nodes_enabled = var.burstable_nodes_enabled
73+
spot_nodes_enabled = var.spot_nodes_enabled
74+
arm_nodes_enabled = var.arm_nodes_enabled
75+
controller_nodes_enabled = var.controller_nodes_enabled
76+
instance_type_anti_affinity_required = false
77+
az_anti_affinity_required = false
78+
host_anti_affinity_required = false
79+
extra_tolerations = var.extra_tolerations
80+
controller_nodes_required = false
81+
node_requirements = var.node_requirements
82+
node_preferences = {}
83+
az_spread_preferred = false
84+
az_spread_required = false
85+
panfactum_scheduler_enabled = false
86+
termination_grace_period_seconds = var.termination_grace_period_seconds
87+
restart_policy = var.restart_policy
88+
}
89+
90+
resource "kubernetes_service_account" "service_account" {
91+
metadata {
92+
name = random_id.daemon_set_id.hex
93+
namespace = var.namespace
94+
labels = module.pod_template.labels
95+
}
96+
}
97+
98+
resource "kubectl_manifest" "daemon_set" {
99+
yaml_body = yamlencode({
100+
apiVersion = "apps/v1"
101+
kind = "DaemonSet"
102+
metadata = {
103+
namespace = var.namespace
104+
name = var.name
105+
labels = module.pod_template.labels
106+
annotations = {
107+
"reloader.stakater.com/auto" = "true"
108+
}
109+
}
110+
spec = {
111+
minReadySeconds = var.min_ready_seconds
112+
updateStrategy = {
113+
type = var.update_type
114+
}
115+
selector = {
116+
matchLabels = module.pod_template.match_labels
117+
}
118+
template = module.pod_template.pod_template
119+
}
120+
})
121+
server_side_apply = true
122+
force_conflicts = true
123+
wait_for_rollout = var.wait_for_rollout
124+
}
125+
126+
resource "kubectl_manifest" "vpa" {
127+
count = var.vpa_enabled ? 1 : 0
128+
yaml_body = yamlencode({
129+
apiVersion = "autoscaling.k8s.io/v1"
130+
kind = "VerticalPodAutoscaler"
131+
metadata = {
132+
name = var.name
133+
namespace = var.namespace
134+
labels = module.pod_template.labels
135+
}
136+
spec = {
137+
targetRef = {
138+
apiVersion = "apps/v1"
139+
kind = "DaemonSet"
140+
name = var.name
141+
}
142+
updatePolicy = {
143+
updateMode = "Auto"
144+
}
145+
resourcePolicy = {
146+
containerPolicies = [for config in var.containers : {
147+
containerName = config.name
148+
minAllowed = {
149+
memory = "${config.minimum_memory}Mi"
150+
cpu = "${config.minimum_cpu}m"
151+
}
152+
maxAllowed = { for k, v in {
153+
memory = config.maximum_memory != null ? "${config.maximum_memory}Mi" : null
154+
cpu = config.maximum_cpu != null ? "${config.maximum_cpu}Mi" : null
155+
} : k => v if v != null }
156+
}]
157+
}
158+
}
159+
})
160+
depends_on = [kubectl_manifest.daemon_set]
161+
}
162+
163+
resource "kubectl_manifest" "pdb" {
164+
yaml_body = yamlencode({
165+
apiVersion = "policy/v1"
166+
kind = "PodDisruptionBudget"
167+
metadata = {
168+
name = "${var.name}-pdb"
169+
namespace = var.namespace
170+
labels = module.pod_template.labels
171+
}
172+
spec = {
173+
selector = {
174+
matchLabels = module.pod_template.match_labels
175+
}
176+
minAvailable = var.min_available # Needs to be minAvailable as daemonset does not implement the scale subresource
177+
unhealthyPodEvictionPolicy = var.unhealthy_pod_eviction_policy
178+
}
179+
})
180+
force_conflicts = true
181+
server_side_apply = true
182+
depends_on = [kubectl_manifest.daemon_set]
183+
}
184+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "match_labels" {
2+
description = "The labels unique to this Deployment that can be used to select any pods in this DaemonSet"
3+
value = module.pod_template.match_labels
4+
}
5+
6+
output "labels" {
7+
description = "The default labels assigned to all resources in this DaemonSet"
8+
value = module.pod_template.labels
9+
}
10+
11+
output "service_account_name" {
12+
description = "The service account used for the pods"
13+
value = kubernetes_service_account.service_account.metadata[0].name
14+
}

0 commit comments

Comments
 (0)