Skip to content

Commit

Permalink
feat: Introduced castai-evictor-ext chart (#63)
Browse files Browse the repository at this point in the history
- Introduced castai-evictor-ext chart
- Introduced functionality to manage chart versions by customers (`self_managed` mode)
  • Loading branch information
andrejatcastai authored May 21, 2024
1 parent 133088b commit bc7b386
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 @@ -181,21 +181,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 @@ -214,14 +229,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]
ignore_changes = [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 @@ -273,10 +295,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 @@ -304,7 +322,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 @@ -313,6 +438,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 @@ -367,6 +494,69 @@ resource "helm_release" "castai_pod_pinner" {
}
}

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 @@ -422,7 +612,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 @@ -482,6 +672,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 bc7b386

Please sign in to comment.