This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
87 lines (84 loc) · 2.51 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
locals {
name = "slo-generator"
client_name = format("%s-client", local.name)
labels = {
"app.kubernetes.io/name" = local.name
"app.kubernetes.io/component" = "client"
"app.kubernetes.io/managed-by" = "terraform-kubernetes-google-slo-generator-client"
"app.kubernetes.io/version" = "1.0.7"
}
}
data "kubernetes_service_account" "slo-generator" {
metadata {
name = local.name
namespace = var.namespace
}
}
data "kubernetes_service" "slo-generator" {
metadata {
name = local.name
namespace = var.namespace
}
}
resource "kubernetes_cron_job_v1" "slo-generator-client" {
metadata {
name = local.client_name
namespace = var.namespace
labels = local.labels
}
spec {
concurrency_policy = "Allow"
failed_jobs_history_limit = 3
schedule = "* * * * *"
starting_deadline_seconds = 30
successful_jobs_history_limit = 5
job_template {
metadata {
labels = local.labels
name = local.client_name
}
spec {
# If something goes wrong, we don't want to have thousands of job running.
active_deadline_seconds = 90
backoff_limit = 0
template {
metadata {
labels = local.labels
name = local.client_name
}
spec {
service_account_name = data.kubernetes_service_account.slo-generator.metadata[0].name
node_selector = {
"iam.gke.io/gke-metadata-server-enabled": "true"
}
container {
name = local.client_name
image = "google/cloud-sdk:latest"
command = ["bash"]
args = [
"-c",
"gcloud alpha storage ls gs://${var.bucket-name} | tr ' ' '\n' | xargs -I {} -n1 -P10 curl -s --output /dev/null -XPOST --max-time 60 -d \"{}\" http://${data.kubernetes_service.slo-generator.metadata[0].name}:8080"
]
resources {
requests = var.requests
limits = var.limits
}
volume_mount {
mount_path = "/tmp"
name = "tmp"
}
security_context {
allow_privilege_escalation = false
read_only_root_filesystem = true
}
}
volume {
name = "tmp"
empty_dir {}
}
}
}
}
}
}
}