From 50d6fb8927e614fc907291523f1ff26e5ca31c40 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Wed, 27 Nov 2024 09:09:57 +0100 Subject: [PATCH] ENH: Add linkahead --- README.md | 25 ++++- deployment/modules/linkahead/ingress.tf | 29 ++++++ deployment/modules/linkahead/main.tf | 121 ++++++++++++++++++++++ deployment/modules/linkahead/variables.tf | 25 +++++ deployment/modules/mariadb/main.tf | 117 +++++++++++++++++++++ deployment/modules/mariadb/outputs.tf | 32 ++++++ deployment/modules/mariadb/variables.tf | 29 ++++++ deployment/outputs.tf | 10 +- deployment/provider.tf | 17 ++- 9 files changed, 401 insertions(+), 4 deletions(-) create mode 100644 deployment/modules/linkahead/ingress.tf create mode 100644 deployment/modules/linkahead/main.tf create mode 100644 deployment/modules/linkahead/variables.tf create mode 100644 deployment/modules/mariadb/main.tf create mode 100644 deployment/modules/mariadb/outputs.tf create mode 100644 deployment/modules/mariadb/variables.tf diff --git a/README.md b/README.md index d871d59..e575254 100644 --- a/README.md +++ b/README.md @@ -859,4 +859,27 @@ into a filter expression, for example `org.eclipse.edc.vc.type:DataProcessorCred query for `DataProcessorCredentials` in the database. The MVD uses the default `EdcScopeToCriterionTransformer` to achieve this. It is recommended to implement a custom -`ScopeToCriterionTransformer` for an actual production scenario. \ No newline at end of file +`ScopeToCriterionTransformer` for an actual production scenario. + +## Use Minikube as Alternative to KinD + +Build the docker images as described above (section 5.1). Then, instead of +moving on to section 5.2, do the following: + +0. `alias minikube='minikube -p mvd'` +1. `alias kubectl='minikube kubectl --'` +2. `minikube start` +3. `minikube addons enable ingress` +4. Wait for the ingress controller to become available: + ``` + kubectl wait --namespace ingress-nginx \ + --for=condition=ready pod \ + --selector=app.kubernetes.io/component=controller \ + --timeout=90s + ``` +5. Forward the local port 80 to the ingress controller: + `sudo ssh -i $(minikube ssh-key) docker@$(minikube ip) -L 80:localhost:80` +6. Load the images: + `minikube image load controlplane:latest dataplane:latest identity-hub:latest catalog-server:latest sts:latest` + +Now you can go on with starting the pods with `terraform init`, `terraform apply` etc. (see above, section 5.2). diff --git a/deployment/modules/linkahead/ingress.tf b/deployment/modules/linkahead/ingress.tf new file mode 100644 index 0000000..1a90f49 --- /dev/null +++ b/deployment/modules/linkahead/ingress.tf @@ -0,0 +1,29 @@ +resource "kubernetes_ingress_v1" "linkahead-ingress" { + metadata { + name = "${var.instance-name}-ingress" + namespace = var.namespace + annotations = { + #"nginx.ingress.kubernetes.io/rewrite-target" = "/$2" + "nginx.ingress.kubernetes.io/use-regex" = "true" + #"nginx.ingress.kubernetes.io/ssl-passthrough" = "true" + } + } + spec { + ingress_class_name = "nginx" + rule { + http { + path { + path = "/${var.instance-name}/linkahead(/|$)(.*)" + backend { + service { + name = kubernetes_service.linkahead-service.metadata.0.name + port { + number = var.linkahead-port + } + } + } + } + } + } + } +} diff --git a/deployment/modules/linkahead/main.tf b/deployment/modules/linkahead/main.tf new file mode 100644 index 0000000..ec1dd33 --- /dev/null +++ b/deployment/modules/linkahead/main.tf @@ -0,0 +1,121 @@ +resource "kubernetes_deployment" "linkahead" { + metadata { + name = local.app-name + namespace = var.namespace + labels = { + App = local.app-name + } + } + + spec { + replicas = 1 + selector { + match_labels = { + App = local.app-name + } + } + template { + metadata { + labels = { + App = local.app-name + } + } + spec { + container { + image = local.linkahead-image + name = local.app-name + + env_from { + config_map_ref { + name = kubernetes_config_map.linkahead-env.metadata[0].name + } + } + port { + container_port = 10080 + name = "linkahead-port" + } + + # dynamic "volume_mount" { + # for_each = toset(var.init-sql-configs) + # content { + # mount_path = "/docker-entrypoint-initdb.d/${volume_mount.value}.sql" + # name = volume_mount.value + # sub_path = "${volume_mount.value}.sql" + # read_only = true + # } + # } + + # Uncomment this to assign (more) resources + # resources { + # limits = { + # cpu = "2" + # memory = "512Mi" + # } + # requests = { + # cpu = "250m" + # memory = "50Mi" + # } + # } + liveness_probe { + tcp_socket { + port = var.linkahead-port + } + failure_threshold = 10 + period_seconds = 5 + timeout_seconds = 30 + } + } + + # dynamic "volume" { + # for_each = toset(var.init-sql-configs) + # content { + # name = volume.value + # config_map { + # name = volume.value + # } + # } + # } + } + } + } +} + +resource "kubernetes_config_map" "linkahead-env" { + metadata { + name = "${local.app-name}-env" + namespace = var.namespace + } + + data = { + CAOSDB_CONFIG_AUTH_OPTIONAL = "TRUE" + CAOSDB_CONFIG_MYSQL_HOST = local.mariadb-host + CAOSDB_CONFIG_MYSQL_PORT = local.mariadb-port + CAOSDB_CONFIG_CONTEXT_ROOT = "/${var.instance-name}/linkahead" + NO_TLS = "1" + DEBUG = "1" + } +} + +resource "kubernetes_service" "linkahead-service" { + metadata { + name = "${local.app-name}-service" + namespace = var.namespace + } + spec { + selector = { + App = kubernetes_deployment.linkahead.spec.0.template.0.metadata[0].labels.App + } + port { + name = "linkahead-port" + port = var.linkahead-port + target_port = 10080 + } + } +} + +locals { + mariadb-host = "${var.instance-name}-mariadb-service" + mariadb-port = 3306 + app-name = "${var.instance-name}-linkahead" + linkahead-image = "indiscale/linkahead:dev" +} diff --git a/deployment/modules/linkahead/variables.tf b/deployment/modules/linkahead/variables.tf new file mode 100644 index 0000000..b7cae03 --- /dev/null +++ b/deployment/modules/linkahead/variables.tf @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024 Metaform Systems, Inc. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# +# Contributors: +# Metaform Systems, Inc. - initial API and implementation +# + +variable "instance-name" { + description = "Unique name for the LinkAhead instance" +} + +variable "namespace" { + description = "kubernetes namespace where the LinkAhead instance is deployed" +} + +variable "linkahead-port" { + description = "Linkahead http port" + default = 10080 +} diff --git a/deployment/modules/mariadb/main.tf b/deployment/modules/mariadb/main.tf new file mode 100644 index 0000000..a8beb3b --- /dev/null +++ b/deployment/modules/mariadb/main.tf @@ -0,0 +1,117 @@ +resource "kubernetes_deployment" "mariadb" { + metadata { + name = local.app-name + namespace = var.namespace + labels = { + App = local.app-name + } + } + + spec { + replicas = 1 + selector { + match_labels = { + App = local.app-name + } + } + template { + metadata { + labels = { + App = local.app-name + } + } + spec { + container { + image = local.mariadb-image + name = local.app-name + + env_from { + config_map_ref { + name = kubernetes_config_map.mariadb-env.metadata[0].name + } + } + port { + container_port = 3306 + name = "mariadb-port" + } + + # dynamic "volume_mount" { + # for_each = toset(var.init-sql-configs) + # content { + # mount_path = "/docker-entrypoint-initdb.d/${volume_mount.value}.sql" + # name = volume_mount.value + # sub_path = "${volume_mount.value}.sql" + # read_only = true + # } + # } + + # Uncomment this to assign (more) resources + # resources { + # limits = { + # cpu = "2" + # memory = "512Mi" + # } + # requests = { + # cpu = "250m" + # memory = "50Mi" + # } + # } + liveness_probe { + tcp_socket { + port = 3306 + } + failure_threshold = 10 + period_seconds = 5 + timeout_seconds = 30 + } + } + + # dynamic "volume" { + # for_each = toset(var.init-sql-configs) + # content { + # name = volume.value + # config_map { + # name = volume.value + # } + # } + # } + } + } + } +} + +resource "kubernetes_config_map" "mariadb-env" { + metadata { + name = "${local.app-name}-env" + namespace = var.namespace + } + + data = { + MYSQL_ROOT_PASSWORD = "caosdb1234" + } +} + +resource "kubernetes_service" "mariadb-service" { + metadata { + name = "${local.app-name}-service" + namespace = var.namespace + } + spec { + selector = { + App = kubernetes_deployment.mariadb.spec.0.template.0.metadata[0].labels.App + } + port { + name = "mariadb-port" + port = var.database-port + target_port = var.database-port + } + } +} + +locals { + app-name = "${var.instance-name}-mariadb" + mariadb-image = "mariadb:10.11" + db-ip = kubernetes_service.mariadb-service.spec.0.cluster_ip + db-url = "${kubernetes_service.mariadb-service.metadata[0].name}:${var.database-port}" + db-host = kubernetes_service.mariadb-service.metadata[0].name +} diff --git a/deployment/modules/mariadb/outputs.tf b/deployment/modules/mariadb/outputs.tf new file mode 100644 index 0000000..3d5bc5d --- /dev/null +++ b/deployment/modules/mariadb/outputs.tf @@ -0,0 +1,32 @@ +# +# Copyright (c) 2024 Metaform Systems, Inc. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# +# Contributors: +# Metaform Systems, Inc. - initial API and implementation +# + +output "instance-name" { + value = var.instance-name +} + +output "database-port" { + value = var.database-port +} + +output "database-url" { + value = local.db-url +} + +output "database-host" { + value = local.db-host +} + +output "database-ip" { + value = local.db-ip +} diff --git a/deployment/modules/mariadb/variables.tf b/deployment/modules/mariadb/variables.tf new file mode 100644 index 0000000..aae317d --- /dev/null +++ b/deployment/modules/mariadb/variables.tf @@ -0,0 +1,29 @@ +# +# Copyright (c) 2024 Metaform Systems, Inc. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# +# Contributors: +# Metaform Systems, Inc. - initial API and implementation +# + +variable "instance-name" { + description = "Unique name for the Mariadb instance" +} + +variable "database-port" { + default = 3306 +} + +variable "init-sql-configs" { + description = "Name of config maps with init sql scripts" + default = [] +} + +variable "namespace" { + description = "kubernetes namespace where the Mariadb instance is deployed" +} diff --git a/deployment/outputs.tf b/deployment/outputs.tf index 6d848a9..2b7c1ec 100644 --- a/deployment/outputs.tf +++ b/deployment/outputs.tf @@ -28,4 +28,12 @@ output "provider-jdbc-url" { provider-qna = "jdbc:postgresql://${module.provider-postgres.database-url}/provider_qna" provider-manufacturing = "jdbc:postgresql://${module.provider-postgres.database-url}/provider_manufacturing" } -} \ No newline at end of file +} + +output "provider-mariadb" { + value = { + host = module.provider-mariadb.database-host + port = module.provider-mariadb.database-port + ip = module.provider-mariadb.database-ip + } +} diff --git a/deployment/provider.tf b/deployment/provider.tf index f04d6aa..023922f 100644 --- a/deployment/provider.tf +++ b/deployment/provider.tf @@ -99,7 +99,20 @@ module "provider-vault" { namespace = kubernetes_namespace.ns.metadata.0.name } -# Postgres database for the consumer +# Mariadb database for provider linkahead +module "provider-mariadb" { + source = "./modules/mariadb" + instance-name = "provider" + namespace = kubernetes_namespace.ns.metadata.0.name +} + +module "provider-linkahead" { + source = "./modules/linkahead" + instance-name = "provider" + namespace = kubernetes_namespace.ns.metadata.0.name +} + +# Postgres database for the provider module "provider-postgres" { depends_on = [kubernetes_config_map.postgres-initdb-config-cs] source = "./modules/postgres" @@ -170,4 +183,4 @@ resource "kubernetes_config_map" "postgres-initdb-config-ih" { \c identity EOT } -} \ No newline at end of file +} -- GitLab