From a72fa36e949f1008c13506302d819420b5b21e68 Mon Sep 17 00:00:00 2001 From: Joey Davenport Date: Thu, 26 Aug 2021 12:22:31 -0600 Subject: [PATCH] Made changes for better module composition --- README.md | 49 +++++++++++-------- main.tf | 45 +++++++---------- modules/istio-operator/main.tf | 6 +-- modules/istio-operator/variables.tf | 2 +- .../chart/templates/catalogsource.yaml | 2 +- modules/olm-subscriptions/chart/values.yaml | 2 +- modules/olm-subscriptions/main.tf | 4 +- modules/olm-subscriptions/variables.tf | 4 +- modules/vault-operator/README.md | 2 +- modules/vault-operator/variables.tf | 2 +- variables.tf | 38 ++++---------- 11 files changed, 67 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 67d332b..8ce0a52 100644 --- a/README.md +++ b/README.md @@ -8,28 +8,40 @@ The `main.tf` file in the root of this repository contains an example of how to A simple example of how to use one of the modules is shown below: ```hcl +data "aws_eks_cluster" "cluster" { + name = "my_eks_cluster_id" +} + +data "aws_eks_cluster_auth" "cluster" { + name = "my_eks_cluster_id" +} + +provider "kubernetes" { + host = data.aws_eks_cluster.cluster.endpoint + cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data) + token = data.aws_eks_cluster_auth.cluster.token + insecure = false + config_path = "./my-eks-kube-config" +} + provider "helm" { kubernetes { - config_path = pathexpand("~/.kube/my-eks-cluster-config") + config_path = "./my-eks-kube-config" } } -module "pulsar_operator" { - source = "streamnative/charts/helm//pulsar-operator" +module "sn_bootstrap" { + source = "streamnative/charts/helm" - chart_name = "pulsar-operator" - chart_repository = "https://charts.streamnative.io" - chart_version = "0.7.2" - cleanup_on_fail = true - namespace = "pulsar-system" - release_name = "pulsar-operator" - - settings = { - "namespace" = "pulsar-system" - "namespaceCreate" = "true" - } + enable_vault_operator = true + enable_function_mesh_operator = true + enable_istio_operator = true + enable_prometheus_operator = true + enable_pulsar_operator = true - timeout = 300 + depends_on = [ + module.sn_cluster, + ] } ``` @@ -96,9 +108,6 @@ No resources. | [function\_mesh\_operator\_release\_name](#input\_function\_mesh\_operator\_release\_name) | The name of the helm release | `string` | `"function-mesh-operator"` | no | | [function\_mesh\_operator\_settings](#input\_function\_mesh\_operator\_settings) | Additional settings which will be passed to the Helm chart values | `map(any)` | `null` | no | | [function\_mesh\_operator\_timeout](#input\_function\_mesh\_operator\_timeout) | Time in seconds to wait for any individual kubernetes operation | `number` | `600` | no | -| [istio\_operator\_chart\_name](#input\_istio\_operator\_chart\_name) | The name of the Helm chart to install | `string` | `"istio-operator"` | no | -| [istio\_operator\_chart\_repository](#input\_istio\_operator\_chart\_repository) | The repository containing the Helm chart to install | `string` | `"https://kubernetes-charts.banzaicloud.com"` | no | -| [istio\_operator\_chart\_version](#input\_istio\_operator\_chart\_version) | The version of the Helm chart to install | `string` | `"0.0.88"` | no | | [istio\_operator\_cleanup\_on\_fail](#input\_istio\_operator\_cleanup\_on\_fail) | Allow deletion of new resources created in this upgrade when upgrade fails | `bool` | `true` | no | | [istio\_operator\_namespace](#input\_istio\_operator\_namespace) | The namespace used for the operator deployment | `string` | `"istio-system"` | no | | [istio\_operator\_release\_name](#input\_istio\_operator\_release\_name) | The name of the helm release | `string` | `"istio-operator"` | no | @@ -108,7 +117,7 @@ No resources. | [olm\_namespace](#input\_olm\_namespace) | The namespace used by OLM and its resources | `string` | `"olm"` | no | | [olm\_operators\_namespace](#input\_olm\_operators\_namespace) | The namespace where OLM will install the operators | `string` | `"operators"` | no | | [olm\_settings](#input\_olm\_settings) | Additional settings which will be passed to the Helm chart values | `map(any)` | `null` | no | -| [olm\_sn\_image](#input\_olm\_sn\_image) | The registry containing StreamNative's operator catalog image | `string` | n/a | yes | +| [olm\_sn\_image](#input\_olm\_sn\_image) | The registry containing StreamNative's operator catalog image | `string` | `""` | no | | [olm\_subscription\_settings](#input\_olm\_subscription\_settings) | Additional settings which will be passed to the Helm chart values | `map(any)` | `null` | no | | [prometheus\_operator\_chart\_name](#input\_prometheus\_operator\_chart\_name) | The name of the Helm chart to install | `string` | `"kube-prometheus-stack"` | no | | [prometheus\_operator\_chart\_repository](#input\_prometheus\_operator\_chart\_repository) | The repository containing the Helm chart to install | `string` | `"https://prometheus-community.github.io/helm-charts"` | no | @@ -128,7 +137,7 @@ No resources. | [pulsar\_operator\_timeout](#input\_pulsar\_operator\_timeout) | Time in seconds to wait for any individual kubernetes operation | `number` | `600` | no | | [vault\_operator\_chart\_name](#input\_vault\_operator\_chart\_name) | The name of the Helm chart to install | `string` | `"vault-operator"` | no | | [vault\_operator\_chart\_repository](#input\_vault\_operator\_chart\_repository) | The repository containing the Helm chart to install | `string` | `"https://kubernetes-charts.banzaicloud.com"` | no | -| [vault\_operator\_chart\_version](#input\_vault\_operator\_chart\_version) | The version of the Helm chart to install | `string` | `"1.13.0"` | no | +| [vault\_operator\_chart\_version](#input\_vault\_operator\_chart\_version) | The version of the Helm chart to install | `string` | `"1.13.2"` | no | | [vault\_operator\_cleanup\_on\_fail](#input\_vault\_operator\_cleanup\_on\_fail) | Allow deletion of new resources created in this upgrade when upgrade fails | `bool` | `true` | no | | [vault\_operator\_namespace](#input\_vault\_operator\_namespace) | The namespace used for the operator deployment | `string` | `"sn-system"` | no | | [vault\_operator\_release\_name](#input\_vault\_operator\_release\_name) | The name of the helm release | `string` | `"vault-operator"` | no | diff --git a/main.tf b/main.tf index badad6a..8312508 100644 --- a/main.tf +++ b/main.tf @@ -17,59 +17,48 @@ # under the License. # -#### -# This top module is an example of how one might use the sub-modules for individual helm charts used by StreamNative -#### - module "function_mesh_operator" { - count = var.enable_function_mesh_operator && var.disable_olm ? 1 : 0 + count = var.enable_function_mesh_operator == true && var.enable_olm == false ? 1 : 0 source = "./modules/function-mesh-operator" chart_name = var.function_mesh_operator_chart_name chart_repository = var.function_mesh_operator_chart_repository chart_version = var.function_mesh_operator_chart_version cleanup_on_fail = var.function_mesh_operator_cleanup_on_fail - namespace = var.function_mesh_operator_namespace + namespace = var.function_mesh_operator_namespace release_name = var.function_mesh_operator_release_name settings = coalesce(var.function_mesh_operator_settings, {}) # The empty map is a placeholder value, reserved for future defaults timeout = var.function_mesh_operator_timeout } module "istio_operator" { - count = var.enable_istio_operator ? 1 : 0 + count = var.enable_istio_operator ? 1 : 0 source = "./modules/istio-operator" - chart_name = var.istio_operator_chart_name - chart_repository = var.istio_operator_chart_repository - chart_version = var.istio_operator_chart_version - cleanup_on_fail = var.istio_operator_cleanup_on_fail - namespace = var.istio_operator_namespace - release_name = var.istio_operator_release_name - settings = coalesce(var.istio_operator_settings, {}) # The empty map is a placeholder value, reserved for future defaults - timeout = var.istio_operator_timeout + cleanup_on_fail = var.istio_operator_cleanup_on_fail + namespace = var.istio_operator_namespace + release_name = var.istio_operator_release_name + settings = coalesce(var.istio_operator_settings, {}) # The empty map is a placeholder value, reserved for future defaults + timeout = var.istio_operator_timeout } module "olm" { - count = var.disable_olm ? 0 : 1 + count = var.enable_olm ? 1 : 0 source = "./modules/operator-lifecycle-manager" olm_namespace = var.olm_namespace olm_operators_namespace = var.olm_operators_namespace settings = coalesce(var.olm_settings, {}) # The empty map is a placeholder value, reserved for future defaults - - depends_on = [ - kubernetes_namespace.sn_system - ] } module "olm_subscriptions" { - count = var.disable_olm ? 0 : 1 + count = var.enable_olm ? 1 : 0 source = "./modules/olm-subscriptions" catalog_namespace = var.olm_catalog_namespace namespace = var.olm_namespace settings = coalesce(var.olm_subscription_settings, {}) # The empty map is a placeholder value, reserved for future defaults - sn_image = var.olm_sn_image + registry = var.olm_registry depends_on = [ module.olm @@ -77,14 +66,14 @@ module "olm_subscriptions" { } module "prometheus_operator" { - count = var.enable_prometheus_operator && var.disable_olm ? 1 : 0 + count = var.enable_prometheus_operator == true && var.enable_olm == false ? 1 : 0 source = "./modules/prometheus-operator" chart_name = var.prometheus_operator_chart_name chart_repository = var.prometheus_operator_chart_repository chart_version = var.prometheus_operator_chart_version cleanup_on_fail = var.prometheus_operator_cleanup_on_fail - namespace = var.prometheus_operator_namespace + namespace = var.prometheus_operator_namespace release_name = var.prometheus_operator_release_name settings = coalesce(var.prometheus_operator_settings, { # Defaults are set to the right. Passing input via var.prometheus_operator_settings will override @@ -99,14 +88,14 @@ module "prometheus_operator" { } module "pulsar_operator" { - count = var.enable_pulsar_operator && var.disable_olm ? 1 : 0 + count = var.enable_pulsar_operator == true && var.enable_olm == false ? 1 : 0 source = "./modules/pulsar-operator" chart_name = var.pulsar_operator_chart_name chart_repository = var.pulsar_operator_chart_repository chart_version = var.pulsar_operator_chart_version cleanup_on_fail = var.pulsar_operator_cleanup_on_fail - namespace = var.pulsar_operator_namespace + namespace = var.pulsar_operator_namespace release_name = var.pulsar_operator_release_name settings = coalesce(var.pulsar_operator_settings, {}) # The empty map is a placeholder value, reserved for future defaults timeout = var.pulsar_operator_timeout @@ -120,8 +109,8 @@ module "vault_operator" { chart_repository = var.vault_operator_chart_repository chart_version = var.vault_operator_chart_version cleanup_on_fail = var.vault_operator_cleanup_on_fail - namespace = var.vault_operator_namespace + namespace = var.vault_operator_namespace release_name = var.vault_operator_release_name settings = coalesce(var.vault_operator_settings, {}) # The empty map is a placeholder value, reserved for future defaults timeout = var.vault_operator_timeout -} +} \ No newline at end of file diff --git a/modules/istio-operator/main.tf b/modules/istio-operator/main.tf index b89441e..d44e6da 100644 --- a/modules/istio-operator/main.tf +++ b/modules/istio-operator/main.tf @@ -30,13 +30,11 @@ terraform { resource "helm_release" "istio_operator" { atomic = var.atomic - chart = "${path.module}/chart" + chart = "${path.module}/chart" cleanup_on_fail = var.cleanup_on_fail name = var.release_name namespace = var.namespace - # repository = var.chart_repository - timeout = var.timeout - # version = var.chart_version + timeout = var.timeout dynamic "set" { for_each = var.settings diff --git a/modules/istio-operator/variables.tf b/modules/istio-operator/variables.tf index 630fb23..2f6b030 100644 --- a/modules/istio-operator/variables.tf +++ b/modules/istio-operator/variables.tf @@ -48,7 +48,7 @@ variable "cleanup_on_fail" { } variable "namespace" { - description = "The namespace used for the operator deployment" + description = "The namespace used for the helm release. The istio operator itself will be installed" type = string } diff --git a/modules/olm-subscriptions/chart/templates/catalogsource.yaml b/modules/olm-subscriptions/chart/templates/catalogsource.yaml index 0e7f2d6..81a5bde 100644 --- a/modules/olm-subscriptions/chart/templates/catalogsource.yaml +++ b/modules/olm-subscriptions/chart/templates/catalogsource.yaml @@ -24,7 +24,7 @@ metadata: namespace: {{ .Values.catalog_namespace }} spec: displayName: StreamNative Operators - image: {{ .Values.sn_image }} + image: {{ .Values.sn_registry }} publisher: StreamNative.io sourceType: grpc updateStrategy: diff --git a/modules/olm-subscriptions/chart/values.yaml b/modules/olm-subscriptions/chart/values.yaml index 5a8839f..b2b4cc1 100644 --- a/modules/olm-subscriptions/chart/values.yaml +++ b/modules/olm-subscriptions/chart/values.yaml @@ -21,7 +21,7 @@ catalog_namespace: olm install_namespace: sn-system operator_group: sn-operators -sn_image: "" +sn_registry: "" components: bookkeeper: true diff --git a/modules/olm-subscriptions/main.tf b/modules/olm-subscriptions/main.tf index 9ab7216..0dae79c 100644 --- a/modules/olm-subscriptions/main.tf +++ b/modules/olm-subscriptions/main.tf @@ -49,8 +49,8 @@ resource "helm_release" "olm_subscriptions" { } set { - name = "sn_image" - value = var.sn_image + name = "sn_registry" + value = var.registry type = "string" } diff --git a/modules/olm-subscriptions/variables.tf b/modules/olm-subscriptions/variables.tf index fa54cb8..c6514f8 100644 --- a/modules/olm-subscriptions/variables.tf +++ b/modules/olm-subscriptions/variables.tf @@ -53,8 +53,8 @@ variable "settings" { type = map(any) } -variable "sn_image" { - description = "The registry containing StreamNative's operator catalog image" +variable "registry" { + description = "The registry containing StreamNative's operator catalog images" type = string } diff --git a/modules/vault-operator/README.md b/modules/vault-operator/README.md index 4f0083a..14dbd4d 100644 --- a/modules/vault-operator/README.md +++ b/modules/vault-operator/README.md @@ -31,7 +31,7 @@ No modules. | [atomic](#input\_atomic) | Purge the chart on a failed installation. Default's to "true". | `bool` | `true` | no | | [chart\_name](#input\_chart\_name) | The name of the Helm chart to install | `string` | `"vault-operator"` | no | | [chart\_repository](#input\_chart\_repository) | The repository containing the Helm chart to install | `string` | `"https://kubernetes-charts.banzaicloud.com"` | no | -| [chart\_version](#input\_chart\_version) | The version of the Helm chart to install | `string` | `"1.13.0"` | no | +| [chart\_version](#input\_chart\_version) | The version of the Helm chart to install | `string` | `"1.13.2"` | no | | [cleanup\_on\_fail](#input\_cleanup\_on\_fail) | Allow deletion of new resources created in this upgrade when upgrade fails | `bool` | `true` | no | | [create\_namespace](#input\_create\_namespace) | Create a namespace for the operator. Defaults to "false". As a best practice it is not recommended to not have Helm manage namespaces. | `bool` | `"false"` | no | | [namespace](#input\_namespace) | The namespace used for the operator deployment | `string` | n/a | yes | diff --git a/modules/vault-operator/variables.tf b/modules/vault-operator/variables.tf index 66e6209..c2b38ac 100644 --- a/modules/vault-operator/variables.tf +++ b/modules/vault-operator/variables.tf @@ -42,7 +42,7 @@ variable "create_namespace" { type = bool } variable "chart_version" { - default = "1.13.0" + default = "1.13.2" description = "The version of the Helm chart to install" type = string } diff --git a/variables.tf b/variables.tf index a0656d7..73c97e9 100644 --- a/variables.tf +++ b/variables.tf @@ -1,8 +1,7 @@ -### Enable/Disable sub-module flags - -variable "disable_olm" { - default = true - description = "Enables Operator Lifecycle Manager (OLM), and disables installing operators via Helm. OLM is disabled by default. Set to \"false\" to have OLM manage the operators." +### Enable/Disable sub-modules +variable "enable_olm" { + default = false + description = "Enables Operator Lifecycle Manager (OLM), and disables installing operators via Helm. OLM is disabled by default. Set to \"true\" to have OLM manage the operators." type = bool } @@ -86,24 +85,6 @@ variable "function_mesh_operator_timeout" { type = number } -variable "istio_operator_chart_name" { - default = "istio-operator" - description = "The name of the Helm chart to install" - type = string -} - -variable "istio_operator_chart_repository" { - default = "https://kubernetes-charts.banzaicloud.com" - description = "The repository containing the Helm chart to install" - type = string -} - -variable "istio_operator_chart_version" { - default = "0.0.88" - description = "The version of the Helm chart to install" - type = string -} - variable "istio_operator_cleanup_on_fail" { default = true description = "Allow deletion of new resources created in this upgrade when upgrade fails" @@ -111,7 +92,7 @@ variable "istio_operator_cleanup_on_fail" { } variable "istio_operator_namespace" { - default = "istio-system" + default = "kube-system" description = "The namespace used for the operator deployment" type = string } @@ -158,8 +139,9 @@ variable "olm_settings" { type = map(any) } -variable "olm_sn_image" { - description = "The registry containing StreamNative's operator catalog image" +variable "olm_registry" { + default = "" + description = "The registry containing StreamNative's operator catalog images" type = string } @@ -244,7 +226,7 @@ variable "pulsar_operator_cleanup_on_fail" { variable "pulsar_operator_namespace" { default = "sn-system" description = "The namespace used for the operator deployment" - type = string + type = string } variable "pulsar_operator_release_name" { @@ -278,7 +260,7 @@ variable "vault_operator_chart_repository" { } variable "vault_operator_chart_version" { - default = "1.13.0" + default = "1.13.2" description = "The version of the Helm chart to install" type = string }