-
Notifications
You must be signed in to change notification settings - Fork 7
/
k8s-path-cleanup.tf
165 lines (145 loc) · 5 KB
/
k8s-path-cleanup.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Copyright (C) 2019-2021 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
locals {
path_cleanup_name = "path-cleanup"
path_cleanup_full_name = "${local.k8s_app_alias}-path-cleanup"
path_cleanup_labels = {
"app.kubernetes.io/name" = "${local.k8s_app_alias}-path-cleanup"
"app.kubernetes.io/instance" = "${local.k8s_app_alias}-path-cleanup"
"app.kubernetes.io/version" = var.path_cleanup_docker_image_version
"app.kubernetes.io/managed-by" = local.k8s_app_alias
}
path_cleanup_label_name_instance = {
"app.kubernetes.io/name" = "${local.k8s_app_alias}-path-cleanup"
"app.kubernetes.io/instance" = "${local.k8s_app_alias}-path-cleanup"
}
}
resource "kubernetes_deployment_v1" "beekeeper_path_cleanup" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.path_cleanup_full_name
namespace = var.k8s_namespace
labels = local.path_cleanup_labels
}
spec {
# setting the number of replicas to greater than 1 is currently untested
replicas = var.k8s_path_cleanup_replicas
selector {
match_labels = local.path_cleanup_label_name_instance
}
template {
metadata {
labels = local.path_cleanup_label_name_instance
annotations = {
"ad.datadoghq.com/${local.path_cleanup_full_name}.check_names": "[\"openmetrics\"]"
"ad.datadoghq.com/${local.path_cleanup_full_name}.init_configs": "[{}]"
"ad.datadoghq.com/${local.path_cleanup_full_name}.instances": "[{ \"prometheus_url\": \"http://%%host%%:8008/actuator/prometheus\", \"namespace\": \"${local.instance_alias}\", \"metrics\": [ \"${join("\",\"", var.beekeeper_path_cleanup_metrics)}\"] }]"
"prometheus.io/scrape" : var.prometheus_enabled
"prometheus.io/port" : var.k8s_path_cleanup_port
"prometheus.io/path" : "/actuator/prometheus"
}
}
spec {
service_account_name = kubernetes_service_account_v1.beekeeper_path_cleanup.metadata.0.name
automount_service_account_token = true
container {
name = local.path_cleanup_full_name
image = "${var.path_cleanup_docker_image}:${var.path_cleanup_docker_image_version}"
image_pull_policy = var.k8s_image_pull_policy
port {
name = local.path_cleanup_name
container_port = var.k8s_path_cleanup_port
}
liveness_probe {
http_get {
path = "/actuator/health"
port = var.k8s_path_cleanup_port
}
initial_delay_seconds = var.k8s_path_cleanup_liveness_delay
}
resources {
limits = {
memory = var.k8s_path_cleanup_memory
cpu = var.k8s_path_cleanup_cpu
}
requests = {
memory = var.k8s_path_cleanup_memory
cpu = var.k8s_path_cleanup_cpu
}
}
env {
name = local.aws_region_key
value = var.aws_region
}
env {
name = local.aws_default_region_key
value = var.aws_region
}
env {
name = local.db_password_key
value_from {
secret_key_ref {
name = var.k8s_db_password_secret
key = local.db_password_key
}
}
}
env {
name = local.spring_application_json_key
value = data.template_file.beekeeper_path_cleanup_config.rendered
}
env {
name = "HADOOP_USER_NAME"
value = "beekeeper"
}
}
image_pull_secrets {
name = var.docker_registry_secret_name
}
}
}
}
}
resource "kubernetes_service" "beekeeper_path_cleanup" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.path_cleanup_full_name
labels = local.path_cleanup_labels
namespace = var.k8s_namespace
}
spec {
port {
name = local.path_cleanup_name
target_port = var.k8s_path_cleanup_port
port = var.k8s_path_cleanup_port
}
selector = local.path_cleanup_label_name_instance
type = "ClusterIP"
}
}
resource "kubernetes_service_account_v1" "beekeeper_path_cleanup" {
metadata {
name = local.path_cleanup_full_name
namespace = var.k8s_namespace
annotations = {
"eks.amazonaws.com/role-arn" = aws_iam_role.beekeeper_k8s_role_path_cleanup_iam[0].arn
}
}
}
resource "kubernetes_secret_v1" "beekeeper_path_cleanup" {
metadata {
name = local.path_cleanup_full_name
namespace = var.k8s_namespace
annotations = {
"kubernetes.io/service-account.name" = local.path_cleanup_full_name
"kubernetes.io/service-account.namespace" = var.k8s_namespace
}
}
type = "kubernetes.io/service-account-token"
depends_on = [
kubernetes_service_account_v1.beekeeper_path_cleanup
]
}