diff --git a/infrastructure/modules/k8s/chaos_mesh/README.md b/infrastructure/modules/k8s/chaos_mesh/README.md new file mode 100644 index 000000000..f26b56b2f --- /dev/null +++ b/infrastructure/modules/k8s/chaos_mesh/README.md @@ -0,0 +1,5 @@ +# Module for deploying Chaos Mesh + +https://chaos_mesh.org/docs/production-installation-using-helm/ +https://chaos_mesh.org/docs/offline-installation/ +https://github.com/3191110276/terraform-kubernetes-chaosmesh/blob/main/main.tf diff --git a/infrastructure/modules/k8s/chaos_mesh/main.tf b/infrastructure/modules/k8s/chaos_mesh/main.tf new file mode 100644 index 000000000..101cf491b --- /dev/null +++ b/infrastructure/modules/k8s/chaos_mesh/main.tf @@ -0,0 +1,58 @@ + +resource "kubernetes_namespace" "chaosmesh" { + metadata { + name = var.namespace + } +} + +resource "helm_release" "chaosmesh" { + name = "chaosmesh" + namespace = kubernetes_namespace.chaosmesh.metadata[0].name + chart = "chaos-mesh" + repository = var.helm_chart_repository + version = var.helm_chart_version + + values = var.node_selector != null ? [yamlencode({ + controllerManager = { + nodeSelector = var.node_selector + } + chaosDaemon = { + nodeSelector = var.node_selector + } + dashboard = { + nodeSelector = var.node_selector + } + dnsServer = { + nodeSelector = var.node_selector + } + prometheus = { + nodeSelector = var.node_selector + } + })] : [] + + set { + name = "image.chaosmesh.repository" + value = var.docker_image.chaosmesh.image + } + set { + name = "image.chaosdaemon.tag" + value = var.docker_image.chaosdaemon.tag + } + set { + name = "image.chaosdashboard.tag" + value = var.docker_image.chaosdashboard.tag + } + + set { + name = "dashboard.service.type" + value = var.service_type + } +} + +data "kubernetes_service" "chaos_dashboard" { + metadata { + name = "chaos-dashboard" + namespace = var.namespace + } + depends_on = [resource.helm_release.chaosmesh] +} diff --git a/infrastructure/modules/k8s/chaos_mesh/outputs.tf b/infrastructure/modules/k8s/chaos_mesh/outputs.tf new file mode 100644 index 000000000..5a4ca55d3 --- /dev/null +++ b/infrastructure/modules/k8s/chaos_mesh/outputs.tf @@ -0,0 +1,4 @@ +output "chaos_mesh_url" { + description = "Chaos Mesh endpoint URL" + value = "http://${data.kubernetes_service.chaos_dashboard.status.0.load_balancer.0.ingress.0.ip}:${data.kubernetes_service.chaos_dashboard.spec.0.port.0.node_port}" +} diff --git a/infrastructure/modules/k8s/chaos_mesh/variables.tf b/infrastructure/modules/k8s/chaos_mesh/variables.tf new file mode 100644 index 000000000..b266f3018 --- /dev/null +++ b/infrastructure/modules/k8s/chaos_mesh/variables.tf @@ -0,0 +1,48 @@ + +# Namespace +variable "namespace" { + description = "Namespace for Chaos Mesh" + type = string +} + +variable "service_type" { + description = "service type : ClusterIP,LoadBalancer,NodePort" + type = string +} + +variable "node_selector" { + description = "node selector : {}" + type = any +} + +# Docker image +variable "docker_image" { + description = "Docker image for Chaos Mesh" + type = object({ + chaosmesh = object({ + image = string + tag = string + }) + chaosdaemon = object({ + image = string + tag = string + }) + chaosdashboard = object({ + image = string + tag = string + }) + }) +} + +# Repository of Chaos Mesh helm chart +variable "helm_chart_repository" { + description = "Path to helm chart repository for Chaos Mesh" + type = string +} + +# Version of helm chart +variable "helm_chart_version" { + description = "Version of chart helm for Chaos Mesh" + type = string +} + diff --git a/infrastructure/modules/k8s/chaos_mesh/versions.tf b/infrastructure/modules/k8s/chaos_mesh/versions.tf new file mode 100644 index 000000000..1edb1db8d --- /dev/null +++ b/infrastructure/modules/k8s/chaos_mesh/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.0" + required_providers { + helm = { + source = "hashicorp/helm" + version = ">= 2.10.1" + } + } +} diff --git a/infrastructure/quick-deploy/gcp/all-in-one/chaos-mesh.tf b/infrastructure/quick-deploy/gcp/all-in-one/chaos-mesh.tf new file mode 100644 index 000000000..1bd884aed --- /dev/null +++ b/infrastructure/quick-deploy/gcp/all-in-one/chaos-mesh.tf @@ -0,0 +1,24 @@ +# Chaos Mesh +module "chaos_mesh" { + count = var.chaos_mesh != null ? 1 : 0 + source = "../../../modules/k8s/chaos_mesh/" + namespace = var.chaos_mesh.namespace + docker_image = { + chaosmesh = { + image = var.chaos_mesh.chaosmesh_image_name + tag = try(coalesce(var.chaos_mesh.chaosmesh_image_tag), local.default_tags[var.chaos_mesh.chaosmesh_image_name]) + } + chaosdaemon = { + image = var.chaos_mesh.chaosdaemon_image_name + tag = try(coalesce(var.chaos_mesh.chaosdaemon_image_tag), local.default_tags[var.chaos_mesh.chaosdaemon_image_name]) + } + chaosdashboard = { + image = var.chaos_mesh.chaosdashboard_image_name + tag = try(coalesce(var.chaos_mesh.chaosdashboard_image_tag), local.default_tags[var.chaos_mesh.chaosdashboard_image_name]) + } + } + helm_chart_repository = try(coalesce(var.chaos_mesh.helm_chart_repository), var.helm_charts.chaos_mesh.repository) + helm_chart_version = try(coalesce(var.chaos_mesh.helm_chart_verison), var.helm_charts.chaos_mesh.version) + service_type = var.chaos_mesh.service_type + node_selector = var.chaos_mesh.node_selector +} diff --git a/infrastructure/quick-deploy/gcp/all-in-one/gar.tf b/infrastructure/quick-deploy/gcp/all-in-one/gar.tf index b709f62bf..9c52a7cb3 100644 --- a/infrastructure/quick-deploy/gcp/all-in-one/gar.tf +++ b/infrastructure/quick-deploy/gcp/all-in-one/gar.tf @@ -15,6 +15,9 @@ locals { var.seq != null ? [var.seq.image_name, var.seq.image_tag] : null, var.seq != null ? [var.seq.cli_image_name, var.seq.cli_image_tag] : null, var.grafana != null ? [var.grafana.image_name, var.grafana.image_tag] : null, + var.chaos_mesh != null ? [var.chaos_mesh.chaosmesh_image_name, var.chaos_mesh.chaosmesh_image_tag] : null, + var.chaos_mesh != null ? [var.chaos_mesh.chaosdaemon_image_name, var.chaos_mesh.chaosdaemon_image_tag] : null, + var.chaos_mesh != null ? [var.chaos_mesh.chaosdashboard_image_name, var.chaos_mesh.chaosdashboard_image_tag] : null, var.node_exporter != null ? [var.node_exporter.image_name, var.node_exporter.image_tag] : null, var.partition_metrics_exporter != null ? [ var.partition_metrics_exporter.image_name, var.partition_metrics_exporter.image_tag diff --git a/infrastructure/quick-deploy/gcp/all-in-one/outputs.tf b/infrastructure/quick-deploy/gcp/all-in-one/outputs.tf index a6930c224..81812faf7 100644 --- a/infrastructure/quick-deploy/gcp/all-in-one/outputs.tf +++ b/infrastructure/quick-deploy/gcp/all-in-one/outputs.tf @@ -5,6 +5,7 @@ output "armonik" { grafana_url = module.armonik.endpoint_urls.grafana_url seq_web_url = module.armonik.endpoint_urls.seq_web_url admin_app_url = module.armonik.endpoint_urls.admin_app_url + chaos_mesh_url = one(module.chaos_mesh[*].chaos_mesh_url) } } diff --git a/infrastructure/quick-deploy/gcp/all-in-one/variables.tf b/infrastructure/quick-deploy/gcp/all-in-one/variables.tf index 5b17f67e6..27f19c830 100644 --- a/infrastructure/quick-deploy/gcp/all-in-one/variables.tf +++ b/infrastructure/quick-deploy/gcp/all-in-one/variables.tf @@ -90,6 +90,26 @@ variable "keda" { default = {} } +# Chaos Mesh +variable "chaos_mesh" { + description = "Chaos Mesh configuration" + type = object({ + namespace = optional(string, "chaos-mesh") + chaosmesh_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-mesh"), + chaosmesh_image_tag = optional(string), + chaosdaemon_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-daemon"), + chaosdaemon_image_tag = optional(string), + chaosdashboard_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-dashboard"), + chaosdashboard_image_tag = optional(string), + helm_chart_repository = optional(string) + helm_chart_version = optional(string) + service_type = optional(string, "LoadBalancer") + node_selector = optional(any, {}) + endpoint_url = optional(string) + }) + default = null +} + # Parameters for MongoDB variable "mongodb" { description = "Parameters of MongoDB" diff --git a/infrastructure/quick-deploy/localhost/all-in-one/chaos-mesh.tf b/infrastructure/quick-deploy/localhost/all-in-one/chaos-mesh.tf new file mode 100644 index 000000000..1bd884aed --- /dev/null +++ b/infrastructure/quick-deploy/localhost/all-in-one/chaos-mesh.tf @@ -0,0 +1,24 @@ +# Chaos Mesh +module "chaos_mesh" { + count = var.chaos_mesh != null ? 1 : 0 + source = "../../../modules/k8s/chaos_mesh/" + namespace = var.chaos_mesh.namespace + docker_image = { + chaosmesh = { + image = var.chaos_mesh.chaosmesh_image_name + tag = try(coalesce(var.chaos_mesh.chaosmesh_image_tag), local.default_tags[var.chaos_mesh.chaosmesh_image_name]) + } + chaosdaemon = { + image = var.chaos_mesh.chaosdaemon_image_name + tag = try(coalesce(var.chaos_mesh.chaosdaemon_image_tag), local.default_tags[var.chaos_mesh.chaosdaemon_image_name]) + } + chaosdashboard = { + image = var.chaos_mesh.chaosdashboard_image_name + tag = try(coalesce(var.chaos_mesh.chaosdashboard_image_tag), local.default_tags[var.chaos_mesh.chaosdashboard_image_name]) + } + } + helm_chart_repository = try(coalesce(var.chaos_mesh.helm_chart_repository), var.helm_charts.chaos_mesh.repository) + helm_chart_version = try(coalesce(var.chaos_mesh.helm_chart_verison), var.helm_charts.chaos_mesh.version) + service_type = var.chaos_mesh.service_type + node_selector = var.chaos_mesh.node_selector +} diff --git a/infrastructure/quick-deploy/localhost/all-in-one/outputs.tf b/infrastructure/quick-deploy/localhost/all-in-one/outputs.tf index ee5c5c5a4..0344eb9d6 100644 --- a/infrastructure/quick-deploy/localhost/all-in-one/outputs.tf +++ b/infrastructure/quick-deploy/localhost/all-in-one/outputs.tf @@ -8,5 +8,6 @@ output "armonik" { admin_api_url = module.armonik.endpoint_urls.admin_api_url admin_0_9_url = module.armonik.endpoint_urls.admin_0_9_url admin_0_8_url = module.armonik.endpoint_urls.admin_0_8_url + chaos_mesh_url = one(module.chaos_mesh[*].chaos_mesh_url) } } diff --git a/infrastructure/quick-deploy/localhost/all-in-one/variables.tf b/infrastructure/quick-deploy/localhost/all-in-one/variables.tf index 5a771c0d8..8b5786092 100644 --- a/infrastructure/quick-deploy/localhost/all-in-one/variables.tf +++ b/infrastructure/quick-deploy/localhost/all-in-one/variables.tf @@ -75,6 +75,26 @@ variable "keda" { default = {} } +# Chaos Mesh +variable "chaos_mesh" { + description = "Chaos Mesh configuration" + type = object({ + namespace = optional(string, "chaos-mesh") + chaosmesh_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-mesh"), + chaosmesh_image_tag = optional(string), + chaosdaemon_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-daemon"), + chaosdaemon_image_tag = optional(string), + chaosdashboard_image_name = optional(string, "ghcr.io/chaos-mesh/chaos-dashboard"), + chaosdashboard_image_tag = optional(string), + helm_chart_repository = optional(string) + helm_chart_version = optional(string) + service_type = optional(string, "LoadBalancer") + node_selector = optional(any, {}) + endpoint_url = optional(string) + }) + default = null +} + # Shared storage variable "shared_storage" { description = "Shared storage infos" diff --git a/versions.tfvars.json b/versions.tfvars.json index 320a658ec..ecc393b9d 100644 --- a/versions.tfvars.json +++ b/versions.tfvars.json @@ -63,7 +63,10 @@ "nginxinc/nginx-unprivileged": "1.25.1-alpine-slim", "datalust/seqcli": "2023.2", "k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner": "v4.0.2", - "bitnami/rabbitmq": "3.12.12-debian-11-r21" + "bitnami/rabbitmq": "3.12.12-debian-11-r21", + "ghcr.io/chaos-mesh/chaos-mesh": "v2.6.3", + "ghcr.io/chaos-mesh/chaos-daemon": "v2.6.3", + "ghcr.io/chaos-mesh/chaos-dashboard": "v2.6.3" }, "helm_charts" : { "keda" : { "repository" : "https://kedacore.github.io/charts" , "version" : "2.9.4"}, @@ -71,6 +74,7 @@ "cluster_autoscaler" : {"repository" : "https://kubernetes.github.io/autoscaler" , "version" : "9.24.0"}, "termination_handler" : {"repository" : "https://aws.github.io/eks-charts" , "version" : "0.21.0" }, "efs_csi_driver" : { "repository" :"https://kubernetes-sigs.github.io/aws-efs-csi-driver/" , "version": "2.3.0" }, - "rabbitmq" : { "repository" : "https://charts.bitnami.com/bitnami" , "version" : "12.11.0"} + "rabbitmq" : { "repository" : "https://charts.bitnami.com/bitnami" , "version" : "12.11.0"}, + "chaos_mesh" : { "repository" : "https://charts.chaos-mesh.org" , "version" : "2.6.3"} } }