Skip to content

Commit

Permalink
feat: add chaos mesh infra (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo committed Mar 6, 2024
2 parents 4d7bfd1 + 4d99af9 commit ee7fb02
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 2 deletions.
5 changes: 5 additions & 0 deletions infrastructure/modules/k8s/chaos_mesh/README.md
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions infrastructure/modules/k8s/chaos_mesh/main.tf
Original file line number Diff line number Diff line change
@@ -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]
}
4 changes: 4 additions & 0 deletions infrastructure/modules/k8s/chaos_mesh/outputs.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
48 changes: 48 additions & 0 deletions infrastructure/modules/k8s/chaos_mesh/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

9 changes: 9 additions & 0 deletions infrastructure/modules/k8s/chaos_mesh/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.0"
required_providers {
helm = {
source = "hashicorp/helm"
version = ">= 2.10.1"
}
}
}
24 changes: 24 additions & 0 deletions infrastructure/quick-deploy/gcp/all-in-one/chaos-mesh.tf
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions infrastructure/quick-deploy/gcp/all-in-one/gar.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions infrastructure/quick-deploy/gcp/all-in-one/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
20 changes: 20 additions & 0 deletions infrastructure/quick-deploy/gcp/all-in-one/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions infrastructure/quick-deploy/localhost/all-in-one/chaos-mesh.tf
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
20 changes: 20 additions & 0 deletions infrastructure/quick-deploy/localhost/all-in-one/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions versions.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@
"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"},
"metrics_server" : { "repository" : "https://kubernetes-sigs.github.io/metrics-server/" , "version" :"3.8.3"},
"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"}
}
}

0 comments on commit ee7fb02

Please sign in to comment.