Skip to content

Commit b76283c

Browse files
authored
LIVE-478: feat: update the live eks example (#555)
1 parent 6d6b87b commit b76283c

File tree

10 files changed

+67
-149
lines changed

10 files changed

+67
-149
lines changed

examples/eks/eks_cluster_live_migration/README.MD

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ CAST AI modules are places in one umbrella module that can be reused for differe
99
Example configuration should be analysed in the following order:
1010
1. Create VPC - `vpc.tf`
1111
2. Create EKS cluster - `eks.tf`
12-
3. Create IAM and other CAST AI related resources to connect EKS cluster to CAST AI, configure Autoscaler and Node Configurations - `castai.tf`
12+
3. Create IAM and other CAST AI related resources to connect EKS cluster to CAST AI, configure Autoscaler and Node Configurations - `castai.tf` and `modules/castai`.
13+
14+
CLM is enabled by having:
15+
1. `clm_enabled = true` in `modules/castai/main.tf` in the CAST AI node template.
16+
2. `container_runtime = "containerd"` and `eks_image_family = "al2023"` in the CAST AI node configuration.
17+
3. `install_live = true` (`install_live = var.install_helm_live`, default value is `true`) in the CAST AI module configuration (`module "castai-eks-cluster"`).
18+
All are in the `modules/castai/main.tf` file.
19+
20+
All other EKS/CAST AI resources mostly manage the EKS cluster and its connection to CAST AI, not specifically the CLM feature.
1321

1422
# Usage
1523
1. Rename `tf.vars.example` to `tf.vars`
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
# Configure Data sources and providers required for CAST AI connection.
2+
data "aws_caller_identity" "current" {}
3+
4+
# Configure EKS cluster connection using CAST AI eks-cluster module.
5+
resource "castai_eks_clusterid" "cluster_id" {
6+
account_id = data.aws_caller_identity.current.account_id
7+
region = var.cluster_region
8+
cluster_name = var.cluster_name
9+
}
10+
11+
resource "castai_eks_user_arn" "castai_user_arn" {
12+
cluster_id = castai_eks_clusterid.cluster_id.id
13+
}
14+
15+
# Create AWS IAM policies and a user to connect to CAST AI.
16+
module "castai-eks-role-iam" {
17+
source = "castai/eks-role-iam/castai"
18+
version = "~> 1.0"
19+
count = var.enable_castai ? 1 : 0
20+
21+
aws_account_id = data.aws_caller_identity.current.account_id
22+
aws_cluster_region = var.cluster_region
23+
aws_cluster_name = var.cluster_name
24+
aws_cluster_vpc_id = module.vpc.vpc_id
25+
26+
castai_user_arn = castai_eks_user_arn.castai_user_arn.arn
27+
28+
create_iam_resources_per_cluster = true
29+
}
30+
131
module "cluster" {
232
source = "./module/castai"
333
count = var.enable_castai ? 1 : 0
@@ -8,17 +38,20 @@ module "cluster" {
838
castai_api_url = var.castai_api_url
939
castai_grpc_url = var.castai_grpc_url
1040

11-
vpc_id = module.vpc.vpc_id
41+
castai-eks-role-iam_instance_profile_arn = module.castai-eks-role-iam[0].instance_profile_role_arn
42+
castai-eks-role-iam_role_arn = module.castai-eks-role-iam[0].role_arn
43+
1244
security_groups = [
1345
module.eks.cluster_security_group_id,
1446
module.eks.node_security_group_id,
1547
aws_security_group.additional.id,
1648
]
17-
subnets = module.vpc.private_subnets
18-
live_proxy_version = var.live_proxy_version
19-
live_helm_version = var.live_helm_version
49+
subnets = module.vpc.private_subnets
50+
live_helm_version = var.live_helm_version
2051

2152
install_helm_live = var.install_helm_live
2253

2354
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
55+
56+
depends_on = [module.eks, module.castai-eks-role-iam]
2457
}

examples/eks/eks_cluster_live_migration/eks.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module "eks" {
3030
aws_auth_roles = [
3131
# Add the CAST AI IAM role which required for CAST AI nodes to join the cluster.
3232
{
33-
rolearn = module.cluster[0].instance_profile_role_arn
33+
rolearn = module.castai-eks-role-iam[0].instance_profile_role_arn
3434
username = "system:node:{{EC2PrivateDNSName}}"
3535
groups = [
3636
"system:bootstrappers",
Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
locals {
2-
role_name = "castai-eks-role"
3-
42
default_node_cfg = {
53
default = {
64
subnets = var.subnets
75
tags = var.tags
86
security_groups = var.security_groups
9-
instance_profile_arn = module.castai-eks-role-iam.instance_profile_arn
7+
instance_profile_arn = var.castai-eks-role-iam_instance_profile_arn
108
}
119
}
1210

@@ -37,11 +35,9 @@ locals {
3735
node_configuration = merge(local.default_node_cfg, {
3836
live = {
3937
subnets = var.subnets,
40-
instance_profile_arn = module.castai-eks-role-iam.instance_profile_arn
38+
instance_profile_arn = var.castai-eks-role-iam_instance_profile_arn
4139
security_groups = var.security_groups
42-
init_script = base64encode(templatefile("${path.module}/eks-init-script.sh", {
43-
live_proxy_version = trimspace(var.live_proxy_version)
44-
}))
40+
4541
container_runtime = "containerd"
4642
eks_image_family = "al2023"
4743
}
@@ -52,42 +48,17 @@ locals {
5248
configuration_id = module.castai-eks-cluster.castai_node_configurations["live"]
5349
is_enabled = true
5450
should_taint = true
51+
clm_enabled = true
5552
}
5653
})
5754
}
5855

5956
# Configure Data sources and providers required for CAST AI connection.
6057
data "aws_caller_identity" "current" {}
6158

62-
resource "castai_eks_user_arn" "castai_user_arn" {
63-
cluster_id = castai_eks_clusterid.cluster_id.id
64-
}
65-
66-
# Create AWS IAM policies and a user to connect to CAST AI.
67-
module "castai-eks-role-iam" {
68-
source = "castai/eks-role-iam/castai"
69-
version = "~> 1.0"
70-
71-
aws_account_id = data.aws_caller_identity.current.account_id
72-
aws_cluster_region = var.cluster_region
73-
aws_cluster_name = var.cluster_name
74-
aws_cluster_vpc_id = var.vpc_id
75-
76-
castai_user_arn = castai_eks_user_arn.castai_user_arn.arn
77-
78-
create_iam_resources_per_cluster = true
79-
}
80-
81-
# Configure EKS cluster connection using CAST AI eks-cluster module.
82-
resource "castai_eks_clusterid" "cluster_id" {
83-
account_id = data.aws_caller_identity.current.account_id
84-
region = var.cluster_region
85-
cluster_name = var.cluster_name
86-
}
87-
8859
module "castai-eks-cluster" {
8960
source = "castai/eks-cluster/castai"
90-
version = "~> 13.0"
61+
version = "~> 13.1"
9162

9263
api_url = var.castai_api_url
9364
castai_api_token = var.castai_api_token
@@ -98,7 +69,7 @@ module "castai-eks-cluster" {
9869
aws_cluster_region = var.cluster_region
9970
aws_cluster_name = var.cluster_name
10071

101-
aws_assume_role_arn = module.castai-eks-role-iam.role_arn
72+
aws_assume_role_arn = var.castai-eks-role-iam_role_arn
10273
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
10374

10475
default_node_configuration = module.castai-eks-cluster.castai_node_configurations["default"]
@@ -143,43 +114,6 @@ module "castai-eks-cluster" {
143114
}
144115
}
145116

146-
# depends_on helps Terraform with creating proper dependencies graph in case of resource creation and in this case destroy.
147-
# module "castai-eks-cluster" has to be destroyed before module "castai-eks-role-iam".
148-
depends_on = [module.castai-eks-role-iam]
149-
}
150-
151-
resource "helm_release" "live-helm" {
152-
name = "castai-live"
153-
count = var.install_helm_live ? 1 : 0
154-
155-
repository = "https://castai.github.io/helm-charts"
156-
chart = "castai-live"
157-
version = var.live_helm_version
158-
159-
namespace = "castai-live"
160-
create_namespace = true
161-
dependency_update = true
162-
163-
set = [
164-
{
165-
name = "castai-aws-vpc-cni.enabled"
166-
value = "true"
167-
},
168-
{
169-
name = "castai.clusterID"
170-
value = castai_eks_clusterid.cluster_id.id
171-
},
172-
{
173-
name = "castai.apiKey"
174-
value = var.castai_api_token
175-
},
176-
{
177-
name = "castai.apiURL"
178-
value = var.castai_api_url
179-
},
180-
]
181-
182-
wait = false
183-
184-
depends_on = [module.castai-eks-cluster]
117+
install_live = var.install_helm_live
118+
live_version = var.install_helm_live ? var.live_helm_version : null
185119
}

examples/eks/eks_cluster_live_migration/module/castai/eks-init-script.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
output "instance_profile_role_arn" {
2-
value = module.castai-eks-role-iam.instance_profile_role_arn
3-
}

examples/eks/eks_cluster_live_migration/module/castai/variables.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ variable "cluster_region" {
77
type = string
88
}
99

10-
variable "live_proxy_version" {
11-
type = string
12-
default = "0.36.0"
13-
}
14-
1510
variable "live_helm_version" {
16-
type = string
17-
default = "0.36.0"
11+
type = string
1812
}
1913

2014
variable "tags" {
@@ -27,8 +21,6 @@ variable "subnets" {}
2721

2822
variable "security_groups" {}
2923

30-
variable "vpc_id" {}
31-
3224
variable "castai_api_url" {
3325
type = string
3426
description = "URL of alternative CAST AI API to be used during development or testing"
@@ -57,3 +49,11 @@ variable "install_helm_live" {
5749
description = "Optional parameter, if set to true - the 'castai-live' Helm chart will be installed on the cluster. This is required for live migration feature."
5850
default = true
5951
}
52+
53+
variable "castai-eks-role-iam_role_arn" {
54+
type = string
55+
}
56+
57+
variable "castai-eks-role-iam_instance_profile_arn" {
58+
type = string
59+
}

examples/eks/eks_cluster_live_migration/module/castai/versions.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ terraform {
66
source = "castai/castai"
77
version = ">= 6.0.0"
88
}
9-
helm = {
10-
source = "hashicorp/helm"
11-
version = "~> 3.0"
12-
}
139
aws = {
1410
source = "hashicorp/aws"
1511
version = "~> 5.0"

examples/eks/eks_cluster_live_migration/tf.vars.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ cluster_name = "<place-holder>"
22
cluster_region = "<place-holder>"
33
castai_api_token = "<place-holder>"
44

5-
live_proxy_version = "0.36.0"
6-
live_helm_version = "0.36.0"
5+
live_helm_version = "0.39.0"

examples/eks/eks_cluster_live_migration/variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,11 @@ variable "enable_castai" {
5151

5252
variable "install_helm_live" {
5353
type = bool
54-
description = "Optional parameter, if set to true - the 'castai-live' Helm chart will be installed on the cluster. This is required for live migration feature."
54+
description = "Optional parameter, if set to true - the 'castai-live' Helm chart will be installed on the cluster. Helm chart must be installed to enable live migration functionality, the option exists only for developers."
5555
default = true
5656
}
5757

58-
variable "live_proxy_version" {
59-
type = string
60-
default = "0.36.0"
61-
}
62-
6358
variable "live_helm_version" {
6459
type = string
65-
default = "0.36.0"
60+
default = "0.39.0"
6661
}

0 commit comments

Comments
 (0)