diff --git a/deploy/kubernetes/charts/orders/templates/_helpers.tpl b/deploy/kubernetes/charts/orders/templates/_helpers.tpl index 3a9ad8fdc..a2287bdb8 100644 --- a/deploy/kubernetes/charts/orders/templates/_helpers.tpl +++ b/deploy/kubernetes/charts/orders/templates/_helpers.tpl @@ -86,16 +86,16 @@ Create the name of the config map to use {{- end }} {{- end -}} -{{- define "orders.mysql.fullname" -}} +{{- define "orders.postgresql.fullname" -}} {{- include "orders.fullname" . }}-mysql {{- end -}} {{/* Common labels for mysql */}} -{{- define "orders.mysql.labels" -}} +{{- define "orders.postgresql.labels" -}} helm.sh/chart: {{ include "orders.chart" . }} -{{ include "orders.mysql.selectorLabels" . }} +{{ include "orders.postgresql.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -105,7 +105,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels for mysql */}} -{{- define "orders.mysql.selectorLabels" -}} +{{- define "orders.postgresql.selectorLabels" -}} app.kubernetes.io/name: {{ include "orders.fullname" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: mysql @@ -123,35 +123,19 @@ app.kubernetes.io/component: mysql {{- end -}} {{- end }} -{{- define "orders.mysql.password" -}} -{{- if not (empty .Values.mysql.secret.password) -}} - {{- .Values.mysql.secret.password | b64enc -}} +{{- define "orders.postgresql.password" -}} +{{- if not (empty .Values.postgresql.secret.password) -}} + {{- .Values.postgresql.secret.password | b64enc -}} {{- else -}} - {{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.secret.name "Key" "password") -}} + {{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.postgresql.secret.name "Key" "password") -}} {{- end -}} {{- end -}} -{{- define "orders.mysql.reader.password" -}} -{{- if not (empty .Values.mysql.reader.secret.password) -}} - {{- .Values.mysql.reader.secret.password | b64enc -}} +{{- define "orders.postgresql.endpoint" -}} +{{- if not (empty .Values.postgresql.endpoint) -}} + {{- .Values.postgresql.endpoint -}} {{- else -}} - {{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.reader.secret.name "Key" "password") -}} -{{- end -}} -{{- end -}} - -{{- define "orders.mysql.endpoint" -}} -{{- if not (empty .Values.mysql.endpoint) -}} - {{- .Values.mysql.endpoint -}} -{{- else -}} -jdbc:mariadb://{{ include "orders.mysql.fullname" . }}:{{ .Values.mysql.service.port }}/{{ .Values.mysql.database }} -{{- end -}} -{{- end -}} - -{{- define "orders.mysql.reader.endpoint" -}} -{{- if not (empty .Values.mysql.reader.endpoint) -}} - {{- .Values.mysql.reader.endpoint -}} -{{- else -}} -{{- include "orders.mysql.endpoint" . -}} +jdbc:mariadb://{{ include "orders.postgresql.fullname" . }}:{{ .Values.postgresql.service.port }}/{{ .Values.postgresql.database }} {{- end -}} {{- end -}} diff --git a/deploy/kubernetes/charts/orders/templates/configmap.yml b/deploy/kubernetes/charts/orders/templates/configmap.yml index 8d9bfef23..391badf22 100644 --- a/deploy/kubernetes/charts/orders/templates/configmap.yml +++ b/deploy/kubernetes/charts/orders/templates/configmap.yml @@ -4,7 +4,7 @@ kind: ConfigMap metadata: name: {{ include "orders.configMapName" . }} data: - SPRING_PROFILES_ACTIVE: mysql,rabbitmq - SPRING_DATASOURCE_URL: {{ include "orders.mysql.endpoint" . }} + SPRING_PROFILES_ACTIVE: rabbitmq + SPRING_DATASOURCE_URL: jdbc:postgresql://{{ .Values.postgresql.endpoint.host }}:{{ .Values.postgresql.endpoint.port }}/{{ .Values.postgresql.database }} SPRING_RABBITMQ_ADDRESSES: {{ include "orders.rabbitmq.addresses" . }} {{- end }} diff --git a/deploy/kubernetes/charts/orders/templates/deployment.yaml b/deploy/kubernetes/charts/orders/templates/deployment.yaml index 1f5cc601c..f28f23ff9 100644 --- a/deploy/kubernetes/charts/orders/templates/deployment.yaml +++ b/deploy/kubernetes/charts/orders/templates/deployment.yaml @@ -42,12 +42,12 @@ spec: - name: SPRING_DATASOURCE_USERNAME valueFrom: secretKeyRef: - name: {{ .Values.mysql.secret.name }} + name: {{ .Values.postgresql.secret.name }} key: username - name: SPRING_DATASOURCE_PASSWORD valueFrom: secretKeyRef: - name: {{ .Values.mysql.secret.name }} + name: {{ .Values.postgresql.secret.name }} key: password envFrom: - secretRef: diff --git a/deploy/kubernetes/charts/orders/templates/mysql-reader-secret.yaml b/deploy/kubernetes/charts/orders/templates/mysql-reader-secret.yaml deleted file mode 100644 index 17f2a1ff0..000000000 --- a/deploy/kubernetes/charts/orders/templates/mysql-reader-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -{{- if .Values.mysql.reader.secret.create }} -apiVersion: v1 -kind: Secret -metadata: - name: {{ .Values.mysql.reader.secret.name }} -data: - username: {{ .Values.mysql.reader.secret.username | b64enc | quote }} - password: "{{ include "orders.mysql.reader.password" . }}" -{{- end }} \ No newline at end of file diff --git a/deploy/kubernetes/charts/orders/templates/mysql-secret.yaml b/deploy/kubernetes/charts/orders/templates/mysql-secret.yaml deleted file mode 100644 index 44faebc4d..000000000 --- a/deploy/kubernetes/charts/orders/templates/mysql-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -{{- if .Values.mysql.secret.create }} -apiVersion: v1 -kind: Secret -metadata: - name: {{ .Values.mysql.secret.name }} -data: - username: {{ .Values.mysql.secret.username | b64enc | quote }} - password: "{{ include "orders.mysql.password" . }}" -{{- end }} \ No newline at end of file diff --git a/deploy/kubernetes/charts/orders/templates/mysql-service.yaml b/deploy/kubernetes/charts/orders/templates/mysql-service.yaml deleted file mode 100644 index 3bd08918f..000000000 --- a/deploy/kubernetes/charts/orders/templates/mysql-service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -{{- if .Values.mysql.create }} -apiVersion: v1 -kind: Service -metadata: - name: {{ include "orders.mysql.fullname" . }} - labels: - {{- include "orders.mysql.labels" . | nindent 4 }} -spec: - type: {{ .Values.mysql.service.type }} - ports: - - port: {{ .Values.mysql.service.port }} - targetPort: mysql - protocol: TCP - name: mysql - selector: - {{- include "orders.mysql.selectorLabels" . | nindent 4 }} -{{- end }} \ No newline at end of file diff --git a/deploy/kubernetes/charts/orders/templates/postgresql-secret.yaml b/deploy/kubernetes/charts/orders/templates/postgresql-secret.yaml new file mode 100644 index 000000000..e088e59c5 --- /dev/null +++ b/deploy/kubernetes/charts/orders/templates/postgresql-secret.yaml @@ -0,0 +1,9 @@ +{{- if .Values.postgresql.secret.create }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.postgresql.secret.name }} +data: + username: {{ .Values.postgresql.secret.username | b64enc | quote }} + password: "{{ include "orders.postgresql.password" . }}" +{{- end }} \ No newline at end of file diff --git a/deploy/kubernetes/charts/orders/templates/postgresql-service.yaml b/deploy/kubernetes/charts/orders/templates/postgresql-service.yaml new file mode 100644 index 000000000..699339fb2 --- /dev/null +++ b/deploy/kubernetes/charts/orders/templates/postgresql-service.yaml @@ -0,0 +1,17 @@ +{{- if .Values.postgresql.create }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "orders.postgresql.fullname" . }} + labels: + {{- include "orders.postgresql.labels" . | nindent 4 }} +spec: + type: {{ .Values.postgresql.service.type }} + ports: + - port: {{ .Values.postgresql.service.port }} + targetPort: mysql + protocol: TCP + name: mysql + selector: + {{- include "orders.postgresql.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/deploy/kubernetes/charts/orders/templates/mysql-statefulset.yaml b/deploy/kubernetes/charts/orders/templates/postgresql-statefulset.yaml similarity index 50% rename from deploy/kubernetes/charts/orders/templates/mysql-statefulset.yaml rename to deploy/kubernetes/charts/orders/templates/postgresql-statefulset.yaml index eaf85423b..479a15949 100644 --- a/deploy/kubernetes/charts/orders/templates/mysql-statefulset.yaml +++ b/deploy/kubernetes/charts/orders/templates/postgresql-statefulset.yaml @@ -1,24 +1,24 @@ -{{- if .Values.mysql.create }} +{{- if .Values.postgresql.create }} apiVersion: apps/v1 kind: StatefulSet metadata: - name: {{ include "orders.mysql.fullname" . }} + name: {{ include "orders.postgresql.fullname" . }} labels: - {{- include "orders.mysql.labels" . | nindent 4 }} + {{- include "orders.postgresql.labels" . | nindent 4 }} spec: replicas: 1 - serviceName: {{ include "orders.mysql.fullname" . }} + serviceName: {{ include "orders.postgresql.fullname" . }} selector: matchLabels: - {{- include "orders.mysql.selectorLabels" . | nindent 6 }} + {{- include "orders.postgresql.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.mysql.podAnnotations }} + {{- with .Values.postgresql.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "orders.mysql.selectorLabels" . | nindent 8 }} + {{- include "orders.postgresql.selectorLabels" . | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -26,22 +26,22 @@ spec: {{- end }} containers: - name: mysql - image: "{{ .Values.mysql.image.repository }}:{{ .Values.mysql.image.tag }}" - imagePullPolicy: {{ .Values.mysql.image.pullPolicy }} + image: "{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}" + imagePullPolicy: {{ .Values.postgresql.image.pullPolicy }} env: - name: MYSQL_ROOT_PASSWORD value: my-secret-pw - name: MYSQL_DATABASE - value: {{ .Values.mysql.database }} + value: {{ .Values.postgresql.database }} - name: MYSQL_USER valueFrom: secretKeyRef: - name: {{ .Values.mysql.secret.name }} + name: {{ .Values.postgresql.secret.name }} key: username - name: MYSQL_PASSWORD valueFrom: secretKeyRef: - name: {{ .Values.mysql.secret.name }} + name: {{ .Values.postgresql.secret.name }} key: password args: - "--ignore-db-dir=lost+found" @@ -52,41 +52,41 @@ spec: - name: mysql containerPort: 3306 protocol: TCP - {{- with .Values.mysql.nodeSelector }} + {{- with .Values.postgresql.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.mysql.affinity }} + {{- with .Values.postgresql.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.mysql.tolerations }} + {{- with .Values.postgresql.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} -{{- if .Values.mysql.persistentVolume.enabled }} +{{- if .Values.postgresql.persistentVolume.enabled }} volumeClaimTemplates: - metadata: name: data - {{- if .Values.mysql.persistentVolume.annotations }} + {{- if .Values.postgresql.persistentVolume.annotations }} annotations: -{{ toYaml .Values.mysql.persistentVolume.annotations | indent 10 }} +{{ toYaml .Values.postgresql.persistentVolume.annotations | indent 10 }} {{- end }} - {{- if .Values.mysql.persistentVolume.labels }} + {{- if .Values.postgresql.persistentVolume.labels }} labels: -{{ toYaml .Values.mysql.persistentVolume.labels | indent 10 }} +{{ toYaml .Values.postgresql.persistentVolume.labels | indent 10 }} {{- end }} spec: accessModes: -{{ toYaml .Values.mysql.persistentVolume.accessModes | indent 8 }} +{{ toYaml .Values.postgresql.persistentVolume.accessModes | indent 8 }} resources: requests: - storage: "{{ .Values.mysql.persistentVolume.size }}" - {{- if .Values.mysql.persistentVolume.storageClass }} - {{- if (eq "-" .Values.mysql.persistentVolume.storageClass) }} + storage: "{{ .Values.postgresql.persistentVolume.size }}" + {{- if .Values.postgresql.persistentVolume.storageClass }} + {{- if (eq "-" .Values.postgresql.persistentVolume.storageClass) }} storageClassName: "" {{- else }} - storageClassName: "{{ .Values.mysql.persistentVolume.storageClass }}" + storageClassName: "{{ .Values.postgresql.persistentVolume.storageClass }}" {{- end }} {{- end }} {{- else }} diff --git a/deploy/kubernetes/charts/orders/values.yaml b/deploy/kubernetes/charts/orders/values.yaml index ea30cb748..5df511981 100644 --- a/deploy/kubernetes/charts/orders/values.yaml +++ b/deploy/kubernetes/charts/orders/values.yaml @@ -70,12 +70,14 @@ configMap: create: true name: -mysql: +postgresql: create: true database: orders - endpoint: "" + endpoint: + host: "" + port: "" secret: create: true @@ -92,13 +94,13 @@ mysql: password: "" image: - repository: mysql + repository: postgres pullPolicy: IfNotPresent - tag: "5.7" + tag: "16.1" service: type: ClusterIP - port: 3306 + port: 5432 podAnnotations: {} diff --git a/deploy/kubernetes/charts/templates/orders.yaml.gotmpl b/deploy/kubernetes/charts/templates/orders.yaml.gotmpl index 163df87a2..6b36ab44a 100644 --- a/deploy/kubernetes/charts/templates/orders.yaml.gotmpl +++ b/deploy/kubernetes/charts/templates/orders.yaml.gotmpl @@ -5,7 +5,7 @@ image: {{end}} {{if env "RANDOM_PASSWORD" }} -mysql: +postgresql: secret: password: {{ env "RANDOM_PASSWORD" | default "" }} {{end}} \ No newline at end of file diff --git a/deploy/terraform/eks/default/kubernetes.tf b/deploy/terraform/eks/default/kubernetes.tf index 8818b1713..f733786c5 100644 --- a/deploy/terraform/eks/default/kubernetes.tf +++ b/deploy/terraform/eks/default/kubernetes.tf @@ -46,7 +46,7 @@ resource "time_sleep" "workloads" { create_duration = "30s" destroy_duration = "60s" - depends_on = [ + depends_on = [ null_resource.addons_blocker ] } @@ -64,12 +64,12 @@ resource "kubernetes_namespace_v1" "assets" { } resource "helm_release" "assets" { - name = "assets" - chart = "../../../kubernetes/charts/assets" + name = "assets" + chart = "../../../kubernetes/charts/assets" - namespace = kubernetes_namespace_v1.assets.metadata[0].name + namespace = kubernetes_namespace_v1.assets.metadata[0].name values = [ - templatefile("${path.module}/values/assets.yaml", { + templatefile("${path.module}/values/assets.yaml", { opentelemetry_enabled = var.opentelemetry_enabled }) ] @@ -88,13 +88,13 @@ resource "kubernetes_namespace_v1" "catalog" { } resource "helm_release" "catalog" { - name = "catalog" - chart = "../../../kubernetes/charts/catalog" + name = "catalog" + chart = "../../../kubernetes/charts/catalog" - namespace = kubernetes_namespace_v1.catalog.metadata[0].name + namespace = kubernetes_namespace_v1.catalog.metadata[0].name values = [ - templatefile("${path.module}/values/catalog.yaml", { + templatefile("${path.module}/values/catalog.yaml", { opentelemetry_enabled = var.opentelemetry_enabled database_endpoint = "${module.dependencies.catalog_db_endpoint}:${module.dependencies.catalog_db_port}" database_username = module.dependencies.catalog_db_master_username @@ -117,16 +117,16 @@ resource "kubernetes_namespace_v1" "carts" { } resource "helm_release" "carts" { - name = "carts" - chart = "../../../kubernetes/charts/carts" + name = "carts" + chart = "../../../kubernetes/charts/carts" - namespace = kubernetes_namespace_v1.carts.metadata[0].name + namespace = kubernetes_namespace_v1.carts.metadata[0].name values = [ - templatefile("${path.module}/values/carts.yaml", { + templatefile("${path.module}/values/carts.yaml", { opentelemetry_enabled = var.opentelemetry_enabled role_arn = module.iam_assumable_role_carts.iam_role_arn - table_name = module.dependencies.carts_dynamodb_table_name + table_name = module.dependencies.carts_dynamodb_table_name }) ] } @@ -144,13 +144,13 @@ resource "kubernetes_namespace_v1" "checkout" { } resource "helm_release" "checkout" { - name = "checkout" - chart = "../../../kubernetes/charts/checkout" + name = "checkout" + chart = "../../../kubernetes/charts/checkout" - namespace = kubernetes_namespace_v1.checkout.metadata[0].name + namespace = kubernetes_namespace_v1.checkout.metadata[0].name values = [ - templatefile("${path.module}/values/checkout.yaml", { + templatefile("${path.module}/values/checkout.yaml", { opentelemetry_enabled = var.opentelemetry_enabled redis_address = module.dependencies.checkout_elasticache_primary_endpoint redis_port = module.dependencies.checkout_elasticache_port @@ -172,21 +172,23 @@ resource "kubernetes_namespace_v1" "orders" { } resource "helm_release" "orders" { - name = "orders" - chart = "../../../kubernetes/charts/orders" + name = "orders" + chart = "../../../kubernetes/charts/orders" - namespace = kubernetes_namespace_v1.orders.metadata[0].name + namespace = kubernetes_namespace_v1.orders.metadata[0].name values = [ - templatefile("${path.module}/values/orders.yaml", { - opentelemetry_enabled = var.opentelemetry_enabled - database_endpoint = "jdbc:mariadb://${module.dependencies.orders_db_endpoint}:${module.dependencies.orders_db_port}/${module.dependencies.orders_db_database_name}" - database_username = module.dependencies.orders_db_master_username - database_password = module.dependencies.orders_db_master_password - rabbitmq_endpoint = module.dependencies.mq_broker_endpoint - rabbitmq_username = module.dependencies.mq_user - rabbitmq_password = module.dependencies.mq_password - security_group_id = aws_security_group.orders.id + templatefile("${path.module}/values/orders.yaml", { + opentelemetry_enabled = var.opentelemetry_enabled + database_endpoint_host = module.dependencies.orders_db_endpoint + database_endpoint_port = module.dependencies.orders_db_port + database_name = module.dependencies.orders_db_database_name + database_username = module.dependencies.orders_db_master_username + database_password = module.dependencies.orders_db_master_password + rabbitmq_endpoint = module.dependencies.mq_broker_endpoint + rabbitmq_username = module.dependencies.mq_user + rabbitmq_password = module.dependencies.mq_password + security_group_id = aws_security_group.orders.id }) ] } @@ -204,10 +206,10 @@ resource "kubernetes_namespace_v1" "ui" { } resource "helm_release" "ui" { - name = "ui" - chart = "../../../kubernetes/charts/ui" + name = "ui" + chart = "../../../kubernetes/charts/ui" - namespace = kubernetes_namespace_v1.ui.metadata[0].name + namespace = kubernetes_namespace_v1.ui.metadata[0].name values = [ templatefile("${path.module}/values/ui.yaml", { @@ -220,23 +222,23 @@ resource "helm_release" "ui" { resource "time_sleep" "restart_pods" { create_duration = "30s" - depends_on = [ + depends_on = [ helm_release.ui, helm_release.opentelemetry ] } resource "null_resource" "restart_pods" { - depends_on = [ time_sleep.restart_pods ] + depends_on = [time_sleep.restart_pods] provisioner "local-exec" { interpreter = ["/bin/bash", "-c"] environment = { KUBECONFIG = base64encode(local.kubeconfig) } - + command = <<-EOT kubectl delete pod -A -l app.kuberneres.io/owner=retail-store-sample --kubeconfig <(echo $KUBECONFIG | base64 -d) EOT } -} \ No newline at end of file +} diff --git a/deploy/terraform/eks/default/values/orders.yaml b/deploy/terraform/eks/default/values/orders.yaml index 103fc9fbc..7882ac714 100644 --- a/deploy/terraform/eks/default/values/orders.yaml +++ b/deploy/terraform/eks/default/values/orders.yaml @@ -1,7 +1,11 @@ mysql: create: false - endpoint: ${database_endpoint} + database: ${database_name} + + endpoint: + host: ${database_endpoint_host} + port: "${database_endpoint_port}" secret: username: ${database_username} diff --git a/deploy/terraform/lib/dependencies/orders_rds.tf b/deploy/terraform/lib/dependencies/orders_rds.tf index 219cbcfb6..7f3a4d993 100644 --- a/deploy/terraform/lib/dependencies/orders_rds.tf +++ b/deploy/terraform/lib/dependencies/orders_rds.tf @@ -2,16 +2,16 @@ module "orders_rds" { source = "terraform-aws-modules/rds-aurora/aws" version = "7.7.1" - name = "${var.environment_name}-orders" - engine = "aurora-mysql" - engine_version = "5.7" + name = "${var.environment_name}-orders" + engine = "aurora-postgresql" + engine_version = "15.5" instance_class = "db.t3.small" instances = { one = {} } - vpc_id = var.vpc_id + vpc_id = var.vpc_id subnets = var.subnet_ids allowed_security_groups = concat(var.allowed_security_group_ids, [var.orders_security_group_id]) @@ -25,16 +25,16 @@ module "orders_rds" { create_db_parameter_group = true db_parameter_group_name = "${var.environment_name}-orders" - db_parameter_group_family = "aurora-mysql5.7" + db_parameter_group_family = "aurora-postgresql15" create_db_cluster_parameter_group = true db_cluster_parameter_group_name = "${var.environment_name}-orders" - db_cluster_parameter_group_family = "aurora-mysql5.7" + db_cluster_parameter_group_family = "aurora-postgresql15" - tags = var.tags + tags = var.tags } resource "random_string" "orders_db_master" { length = 10 special = false -} \ No newline at end of file +}