Skip to content

Commit

Permalink
feat: Backported support for 'self_managed' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej Kislovskij committed Jun 6, 2024
1 parent e1152f8 commit 865ff58
Show file tree
Hide file tree
Showing 2 changed files with 291 additions and 20 deletions.
275 changes: 261 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,36 @@ resource "helm_release" "castai_agent" {
}
}

resource "helm_release" "castai_evictor" {
name = "castai-evictor"
resource "helm_release" "castai_cluster_controller" {
count = var.self_managed ? 0 : 1

name = "cluster-controller"
repository = "https://castai.github.io/helm-charts"
chart = "castai-evictor"
chart = "castai-cluster-controller"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true
wait = true

version = var.evictor_version
values = var.evictor_values
version = var.cluster_controller_version
values = var.cluster_controller_values

set {
name = "replicaCount"
value = "0"
name = "aks.enabled"
value = "true"
}

set {
name = "castai.clusterID"
value = castai_aks_cluster.castai_cluster.id
}

dynamic "set" {
for_each = var.api_url != "" ? [var.api_url] : []
content {
name = "castai.apiURL"
value = var.api_url
}
}

dynamic "set" {
Expand All @@ -211,14 +226,21 @@ resource "helm_release" "castai_evictor" {
}
}

set_sensitive {
name = "castai.apiKey"
value = castai_aks_cluster.castai_cluster.cluster_token
}

depends_on = [helm_release.castai_agent]

lifecycle {
ignore_changes = [set, version]
}
}

resource "helm_release" "castai_cluster_controller" {
resource "helm_release" "castai_cluster_controller_self_managed" {
count = var.self_managed ? 1 : 0

name = "cluster-controller"
repository = "https://castai.github.io/helm-charts"
chart = "castai-cluster-controller"
Expand Down Expand Up @@ -270,10 +292,6 @@ resource "helm_release" "castai_cluster_controller" {
}

depends_on = [helm_release.castai_agent]

lifecycle {
ignore_changes = [version]
}
}

resource "null_resource" "wait_for_cluster" {
Expand Down Expand Up @@ -301,7 +319,114 @@ resource "null_resource" "wait_for_cluster" {
}
}

resource "helm_release" "castai_evictor" {
count = var.self_managed ? 0 : 1

name = "castai-evictor"
repository = "https://castai.github.io/helm-charts"
chart = "castai-evictor"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true
wait = true

version = var.evictor_version
values = var.evictor_values

set {
name = "replicaCount"
value = "0"
}

set {
name = "castai-evictor-ext.enabled"
value = "false"
}

dynamic "set" {
for_each = var.castai_components_labels
content {
name = "podLabels.${set.key}"
value = set.value
}
}

dynamic "set" {
for_each = var.castai_components_sets
content {
name = set.key
value = set.value
}
}

depends_on = [helm_release.castai_agent]

lifecycle {
ignore_changes = [set, version]
}
}

resource "helm_release" "castai_evictor_self_managed" {
count = var.self_managed ? 1 : 0

name = "castai-evictor"
repository = "https://castai.github.io/helm-charts"
chart = "castai-evictor"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true
wait = true

version = var.evictor_version
values = var.evictor_values

set {
name = "replicaCount"
value = "0"
}

set {
name = "castai-evictor-ext.enabled"
value = "false"
}

dynamic "set" {
for_each = var.castai_components_labels
content {
name = "podLabels.${set.key}"
value = set.value
}
}

dynamic "set" {
for_each = var.castai_components_sets
content {
name = set.key
value = set.value
}
}

depends_on = [helm_release.castai_agent]
}

resource "helm_release" "castai_evictor_ext" {
name = "castai-evictor-ext"
repository = "https://castai.github.io/helm-charts"
chart = "castai-evictor-ext"
namespace = "castai-agent"
create_namespace = false
cleanup_on_fail = true
wait = true

version = var.evictor_ext_version
values = var.evictor_ext_values

depends_on = [helm_release.castai_evictor]
}

resource "helm_release" "castai_pod_pinner" {
count = var.self_managed ? 0 : 1

name = "castai-pod-pinner"
repository = "https://castai.github.io/helm-charts"
chart = "castai-pod-pinner"
Expand All @@ -310,6 +435,8 @@ resource "helm_release" "castai_pod_pinner" {
cleanup_on_fail = true
wait = true

version = var.pod_pinner_version

set {
name = "castai.clusterID"
value = castai_aks_cluster.castai_cluster.id
Expand Down Expand Up @@ -360,10 +487,73 @@ resource "helm_release" "castai_pod_pinner" {
depends_on = [helm_release.castai_agent]

lifecycle {
ignore_changes = [set, version]
ignore_changes = [version]
}
}

resource "helm_release" "castai_pod_pinner_self_managed" {
count = var.self_managed ? 1 : 0

name = "castai-pod-pinner"
repository = "https://castai.github.io/helm-charts"
chart = "castai-pod-pinner"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true
wait = true

version = var.pod_pinner_version

set {
name = "castai.clusterID"
value = castai_aks_cluster.castai_cluster.id
}

dynamic "set" {
for_each = var.api_url != "" ? [var.api_url] : []
content {
name = "castai.apiURL"
value = var.api_url
}
}

set_sensitive {
name = "castai.apiKey"
value = castai_aks_cluster.castai_cluster.cluster_token
}

dynamic "set" {
for_each = var.grpc_url != "" ? [var.grpc_url] : []
content {
name = "castai.grpcURL"
value = var.grpc_url
}
}

dynamic "set" {
for_each = var.castai_components_labels
content {
name = "podLabels.${set.key}"
value = set.value
}
}

dynamic "set" {
for_each = var.castai_components_sets
content {
name = set.key
value = set.value
}
}

set {
name = "replicaCount"
value = "0"
}

depends_on = [helm_release.castai_agent]
}

resource "helm_release" "castai_spot_handler" {
name = "castai-spot-handler"
repository = "https://castai.github.io/helm-charts"
Expand Down Expand Up @@ -419,7 +609,7 @@ resource "helm_release" "castai_spot_handler" {
}

resource "helm_release" "castai_kvisor" {
count = var.install_security_agent ? 1 : 0
count = var.install_security_agent && !var.self_managed ? 1 : 0

name = "castai-kvisor"
repository = "https://castai.github.io/helm-charts"
Expand Down Expand Up @@ -479,6 +669,63 @@ resource "helm_release" "castai_kvisor" {
}
}

resource "helm_release" "castai_kvisor_self_managed" {
count = var.install_security_agent && var.self_managed ? 1 : 0

name = "castai-kvisor"
repository = "https://castai.github.io/helm-charts"
chart = "castai-kvisor"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true

version = var.kvisor_version
values = var.kvisor_values

set {
name = "castai.clusterID"
value = castai_aks_cluster.castai_cluster.id
}

set_sensitive {
name = "castai.apiKey"
value = castai_aks_cluster.castai_cluster.cluster_token
}

set {
name = "castai.grpcAddr"
value = var.api_grpc_addr
}

set {
name = "controller.extraArgs.kube-linter-enabled"
value = "true"
}

set {
name = "controller.extraArgs.image-scan-enabled"
value = "true"
}

set {
name = "controller.extraArgs.kube-bench-enabled"
value = "true"
}

set {
name = "controller.extraArgs.kube-bench-cloud-provider"
value = "aks"
}

dynamic "set" {
for_each = var.castai_components_sets
content {
name = set.key
value = set.value
}
}
}

resource "castai_autoscaler" "castai_autoscaler_policies" {
autoscaler_policies_json = var.autoscaler_policies_json
cluster_id = castai_aks_cluster.castai_cluster.id
Expand Down
Loading

0 comments on commit 865ff58

Please sign in to comment.