Skip to content

Commit 1f55e56

Browse files
committed
refactor: Update CI/QA environments to use serverless cache by default
1 parent d8aa2c0 commit 1f55e56

13 files changed

Lines changed: 435 additions & 180 deletions

File tree

src/ol_infrastructure/applications/edxapp/__main__.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# ruff: noqa: E501
2-
32
"""Provision and deploy the resources needed for an edxapp installation.
43
54
- Create S3 buckets required by edxapp
@@ -51,12 +50,12 @@
5150
from bridge.secrets.sops import read_yaml_secrets
5251
from bridge.settings.openedx.version_matrix import OpenLearningOpenEdxDeployment
5352
from ol_infrastructure.applications.edxapp.k8s_resources import create_k8s_resources
54-
from ol_infrastructure.components.aws.cache import OLAmazonCache, OLAmazonRedisConfig
5553
from ol_infrastructure.components.aws.database import OLAmazonDB, OLMariaDBConfig
5654
from ol_infrastructure.components.services.vault import (
5755
OLVaultDatabaseBackend,
5856
OLVaultMysqlDatabaseConfig,
5957
)
58+
from ol_infrastructure.lib.aws.cache_helper import create_redis_cache
6059
from ol_infrastructure.lib.aws.ec2_helper import (
6160
DiskTypes,
6261
InstanceTypes,
@@ -984,33 +983,26 @@ def cloud_init_user_data_func(
984983
vpc_id=edxapp_vpc_id,
985984
)
986985

987-
redis_instance_type = (
988-
redis_config.get("instance_type") or defaults(stack_info)["redis"]["instance_type"]
989-
)
990-
redis_cache_config = OLAmazonRedisConfig(
991-
encrypt_transit=True,
992-
auth_token=read_yaml_secrets(
993-
Path(f"edxapp/{stack_info.env_prefix}.{stack_info.env_suffix}.yaml")
994-
)["redis_auth_token"],
995-
cluster_mode_enabled=False,
996-
encrypted=True,
986+
# Create Redis cache (auto-selects serverless for CI/QA, dedicated for Prod)
987+
redis_defaults_config = defaults(stack_info)["redis"]
988+
redis_auth_token = read_yaml_secrets(
989+
Path(f"edxapp/{stack_info.env_prefix}.{stack_info.env_suffix}.yaml")
990+
)["redis_auth_token"]
991+
992+
edxapp_redis_cache = create_redis_cache(
993+
stack_info=stack_info,
994+
cache_name=f"edxapp-redis-{env_name}",
995+
description="Redis cluster for edX platform tasks and caching",
996+
security_group_ids=[redis_cluster_security_group.id],
997+
subnet_group=edxapp_vpc["elasticache_subnet"],
998+
subnet_ids=edxapp_vpc["subnet_ids"][:3],
999+
auth_token=redis_auth_token,
9971000
engine="valkey",
9981001
engine_version="7.2",
999-
instance_type=redis_instance_type,
1002+
instance_type=redis_config.get("instance_type")
1003+
or redis_defaults_config["instance_type"],
10001004
num_instances=3,
1001-
shard_count=1,
1002-
auto_upgrade=True,
1003-
cluster_description="Redis cluster for edX platform tasks and caching",
1004-
cluster_name=f"edxapp-redis-{env_name}",
1005-
parameter_overrides={"maxmemory-policy": "allkeys-lru"},
1006-
security_groups=[redis_cluster_security_group.id],
1007-
subnet_group=edxapp_vpc[
1008-
"elasticache_subnet"
1009-
], # the name of the subnet group created in the OLVPC component resource
10101005
tags=aws_config.tags,
1011-
)
1012-
edxapp_redis_cache = OLAmazonCache(
1013-
redis_cache_config,
10141006
opts=ResourceOptions(
10151007
aliases=[Alias(name=f"edxapp-redis-{env_name}-redis-elasticache-cluster")]
10161008
),
@@ -1026,7 +1018,7 @@ def cloud_init_user_data_func(
10261018
"edxapp-redis-consul-service",
10271019
node=edxapp_redis_consul_node.name,
10281020
name="edxapp-redis",
1029-
port=redis_cache_config.port,
1021+
port=DEFAULT_REDIS_PORT,
10301022
meta={
10311023
"external-node": True,
10321024
"external-probe": True,
@@ -1622,7 +1614,6 @@ def cloud_init_user_data_func(
16221614
"fastly_access_logging_iam_role"
16231615
)
16241616

1625-
16261617
mfe_regex = "^/({})/".format("|".join(edxapp_mfe_paths))
16271618
edxapp_fastly_service = fastly.ServiceVcl(
16281619
f"fastly-{stack_info.env_prefix}-{stack_info.env_suffix}",

src/ol_infrastructure/applications/learn_ai/__main__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
ONE_MEGABYTE_BYTE,
3232
)
3333
from bridge.secrets.sops import read_yaml_secrets
34-
from ol_infrastructure.components.aws.cache import OLAmazonCache, OLAmazonRedisConfig
3534
from ol_infrastructure.components.aws.eks import OLEKSTrustRole, OLEKSTrustRoleConfig
3635
from ol_infrastructure.components.services import appdb
3736
from ol_infrastructure.components.services.k8s import (
@@ -53,6 +52,7 @@
5352
OLVaultK8SSecret,
5453
OLVaultK8SStaticSecretConfig,
5554
)
55+
from ol_infrastructure.lib.aws.cache_helper import create_redis_cache
5656
from ol_infrastructure.lib.aws.eks_helper import (
5757
check_cluster_namespace,
5858
default_psg_egress_args,
@@ -569,25 +569,22 @@
569569
tags=aws_config.tags,
570570
)
571571

572-
redis_cache_config = OLAmazonRedisConfig(
573-
encrypt_transit=True,
572+
# Create Redis cache (automatically selects serverless for CI, dedicated for Production)
573+
redis_defaults = defaults(stack_info)["redis"]
574+
redis_cache = create_redis_cache(
575+
stack_info=stack_info,
576+
cache_name=f"learn-ai-redis-{stack_info.env_suffix}",
577+
description="Redis cluster for learn UI tasks and caching",
578+
security_group_ids=[redis_cluster_security_group.id],
579+
subnet_group=apps_vpc["elasticache_subnet"],
580+
subnet_ids=apps_vpc["subnet_ids"][:3],
574581
auth_token=redis_config.require("password"),
575-
cluster_mode_enabled=False,
576-
encrypted=True,
577-
engine_version="7.2",
578582
engine="valkey",
583+
engine_version="7.2",
584+
instance_type=redis_config.get("instance_type")
585+
or redis_defaults.get("instance_type"),
579586
num_instances=3,
580-
shard_count=1,
581-
auto_upgrade=True,
582-
cluster_description="Redis cluster for learn UI tasks and caching.",
583-
cluster_name=f"learn-ai-redis-{stack_info.env_suffix}",
584-
subnet_group=apps_vpc["elasticache_subnet"],
585-
security_groups=[redis_cluster_security_group.id],
586587
tags=aws_config.tags,
587-
**redis_defaults,
588-
)
589-
redis_cache = OLAmazonCache(
590-
redis_cache_config,
591588
opts=ResourceOptions(
592589
aliases=[
593590
Alias(

src/ol_infrastructure/applications/mit_learn/__main__.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
from ol_infrastructure.applications.mit_learn.k8s_secrets import (
3030
create_mitlearn_k8s_secrets,
3131
)
32-
from ol_infrastructure.components.aws.cache import (
33-
OLAmazonCache,
34-
OLAmazonRedisConfig,
35-
)
3632
from ol_infrastructure.components.aws.database import OLAmazonDB, OLPostgresDBConfig
3733
from ol_infrastructure.components.services.cert_manager import (
3834
OLCertManagerCert,
@@ -56,6 +52,7 @@
5652
OLVaultK8SResourcesConfig,
5753
OLVaultPostgresDatabaseConfig,
5854
)
55+
from ol_infrastructure.lib.aws.cache_helper import create_redis_cache
5956
from ol_infrastructure.lib.aws.eks_helper import (
6057
check_cluster_namespace,
6158
default_psg_egress_args,
@@ -1338,25 +1335,22 @@
13381335
vpc_id=apps_vpc["id"],
13391336
tags=aws_config.tags,
13401337
)
1341-
redis_cache_config = OLAmazonRedisConfig(
1342-
encrypt_transit=True,
1338+
1339+
# Create Redis cache (auto-selects serverless for CI/QA, dedicated for Prod)
1340+
redis_cache = create_redis_cache(
1341+
stack_info=stack_info,
1342+
cache_name=f"mitlearn-redis-{stack_info.env_suffix}",
1343+
description="Redis cluster for MIT Learn",
1344+
security_group_ids=[redis_cluster_security_group.id],
1345+
subnet_group=apps_vpc["elasticache_subnet"],
1346+
subnet_ids=apps_vpc["subnet_ids"][:3],
13431347
auth_token=redis_config.require("password"),
1344-
cluster_mode_enabled=False,
1345-
encrypted=True,
1346-
engine_version="7.2",
13471348
engine="valkey",
1349+
engine_version="7.2",
1350+
instance_type=redis_config.get("instance_type")
1351+
or redis_defaults.get("instance_type"),
13481352
num_instances=3,
1349-
shard_count=1,
1350-
auto_upgrade=True,
1351-
cluster_description="Redis cluster for MIT Learn",
1352-
cluster_name=f"mitlearn-redis-{stack_info.env_suffix}",
1353-
subnet_group=apps_vpc["elasticache_subnet"],
1354-
security_groups=[redis_cluster_security_group.id],
13551353
tags=aws_config.tags,
1356-
**redis_defaults,
1357-
)
1358-
redis_cache = OLAmazonCache(
1359-
redis_cache_config,
13601354
opts=ResourceOptions(
13611355
aliases=[
13621356
Alias(

src/ol_infrastructure/applications/mit_learn/k8s_secrets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from bridge.lib.magic_numbers import DEFAULT_REDIS_PORT
1616
from ol_infrastructure.components.aws.cache import OLAmazonCache
17+
from ol_infrastructure.components.aws.serverless_cache import OLAmazonServerlessCache
1718
from ol_infrastructure.components.services.vault import (
1819
OLVaultDatabaseBackend,
1920
OLVaultK8SDynamicSecretConfig,
@@ -133,7 +134,7 @@ def create_mitlearn_k8s_secrets(
133134
mitlearn_vault_mount: Mount,
134135
db_config: OLVaultDatabaseBackend,
135136
redis_password: str,
136-
redis_cache: OLAmazonCache,
137+
redis_cache: OLAmazonCache | OLAmazonServerlessCache,
137138
) -> tuple[list[str], list[OLVaultK8SSecret | kubernetes.core.v1.Secret]]:
138139
"""
139140
Create all Kubernetes secrets required by the mitlearn application.

src/ol_infrastructure/applications/mitxonline/__main__.py

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@
2828
from ol_infrastructure.applications.mitxonline.k8s_secrets import (
2929
create_mitxonline_k8s_secrets,
3030
)
31-
from ol_infrastructure.components.aws.cache import (
32-
OLAmazonCache,
33-
OLAmazonRedisConfig,
34-
)
3531
from ol_infrastructure.components.aws.database import OLAmazonDB, OLPostgresDBConfig
36-
from ol_infrastructure.components.aws.serverless_cache import (
37-
OLAmazonServerlessCache,
38-
OLAmazonServerlessCacheConfig,
39-
)
4032
from ol_infrastructure.components.services.cert_manager import (
4133
OLCertManagerCert,
4234
OLCertManagerCertConfig,
@@ -59,6 +51,7 @@
5951
OLVaultK8SResourcesConfig,
6052
OLVaultPostgresDatabaseConfig,
6153
)
54+
from ol_infrastructure.lib.aws.cache_helper import create_redis_cache
6255
from ol_infrastructure.lib.aws.eks_helper import (
6356
check_cluster_namespace,
6457
default_psg_egress_args,
@@ -424,29 +417,22 @@
424417
vpc_id=apps_vpc["id"],
425418
tags=aws_config.tags,
426419
)
420+
# Create Redis cache (automatically selects serverless for CI/QA, dedicated for Production)
421+
# Configuration can override via redis:use_serverless_cache boolean
427422
redis_defaults = defaults(stack_info)["redis"]
428-
redis_defaults["instance_type"] = (
429-
redis_config.get("instance_type") or redis_defaults["instance_type"]
430-
)
431-
redis_cache_config = OLAmazonRedisConfig(
432-
encrypt_transit=True,
423+
redis_cache = create_redis_cache(
424+
stack_info=stack_info,
425+
cache_name=f"mitxonline-app-redis-{stack_info.env_suffix}",
426+
description="Redis cluster for MITxonline",
427+
security_group_ids=[redis_cluster_security_group.id],
428+
subnet_group=apps_vpc["elasticache_subnet"],
429+
subnet_ids=apps_vpc["subnet_ids"][:3],
433430
auth_token=redis_config.require("password"),
434-
cluster_mode_enabled=False,
435-
encrypted=True,
436-
engine_version="7.2",
437431
engine="valkey",
432+
engine_version="7.2",
433+
instance_type=redis_config.get("instance_type") or redis_defaults["instance_type"],
438434
num_instances=3,
439-
shard_count=1,
440-
auto_upgrade=True,
441-
cluster_description="Redis cluster for MITxonline",
442-
cluster_name=f"mitxonline-app-redis-{stack_info.env_suffix}",
443-
subnet_group=apps_vpc["elasticache_subnet"],
444-
security_groups=[redis_cluster_security_group.id],
445435
tags=aws_config.tags,
446-
**redis_defaults,
447-
)
448-
redis_cache = OLAmazonCache(
449-
redis_cache_config,
450436
opts=ResourceOptions(
451437
aliases=[
452438
Alias(
@@ -456,24 +442,6 @@
456442
),
457443
)
458444

459-
serverless_cache_config = OLAmazonServerlessCacheConfig(
460-
description="Redis cluster for MITxonline",
461-
cache_name=f"mitxonline-app-serverless-{stack_info.env_suffix}",
462-
security_group_ids=[redis_cluster_security_group.id],
463-
subnet_ids=apps_vpc["subnet_ids"][:3], # We can only specify three
464-
tags=aws_config.tags,
465-
)
466-
serverless_cache = OLAmazonServerlessCache(
467-
serverless_cache_config,
468-
opts=ResourceOptions(
469-
aliases=[
470-
Alias(
471-
name=f"mitxonline-app-serverless-{stack_info.env_suffix}-serverless-elasticache-cluster"
472-
)
473-
]
474-
),
475-
)
476-
477445
# Create Kubernetes secrets using the dedicated function
478446
# The function returns the names of the secrets and the Pulumi resource objects
479447
secret_names, secret_resources = create_mitxonline_k8s_secrets(

src/ol_infrastructure/applications/mitxonline/k8s_secrets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from bridge.lib.magic_numbers import DEFAULT_REDIS_PORT
1515
from ol_infrastructure.components.aws.cache import OLAmazonCache
16+
from ol_infrastructure.components.aws.serverless_cache import OLAmazonServerlessCache
1617
from ol_infrastructure.components.services.vault import (
1718
OLVaultDatabaseBackend,
1819
OLVaultK8SDynamicSecretConfig,
@@ -133,7 +134,7 @@ def create_mitxonline_k8s_secrets(
133134
rds_endpoint: str,
134135
openedx_environment: str,
135136
redis_password: str,
136-
redis_cache: OLAmazonCache,
137+
redis_cache: OLAmazonCache | OLAmazonServerlessCache,
137138
) -> tuple[list[str], list[OLVaultK8SSecret | kubernetes.core.v1.Secret]]:
138139
"""
139140
Create all Kubernetes secrets required by the MITx Online application.

src/ol_infrastructure/applications/odl_video_service/__main__.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
OLTargetGroupConfig,
3131
TagSpecification,
3232
)
33-
from ol_infrastructure.components.aws.cache import OLAmazonCache, OLAmazonRedisConfig
3433
from ol_infrastructure.components.aws.database import OLAmazonDB, OLPostgresDBConfig
3534
from ol_infrastructure.components.aws.mediaconvert import (
3635
MediaConvertConfig,
@@ -40,6 +39,7 @@
4039
OLVaultDatabaseBackend,
4140
OLVaultPostgresDatabaseConfig,
4241
)
42+
from ol_infrastructure.lib.aws.cache_helper import create_redis_cache
4343
from ol_infrastructure.lib.aws.ec2_helper import InstanceTypes, default_egress_args
4444
from ol_infrastructure.lib.aws.iam_helper import IAM_POLICY_VERSION, lint_iam_policy
4545
from ol_infrastructure.lib.consul import consul_key_helper, get_consul_provider
@@ -454,24 +454,22 @@
454454
redis_auth_token = secrets["redis"]["auth_token"]
455455
redis_config = Config("redis")
456456

457-
ovs_server_redis_config = OLAmazonRedisConfig(
458-
encrypt_transit=True,
457+
# Create Redis cache (automatically selects serverless for CI, dedicated for Production)
458+
redis_defaults = defaults(stack_info)["redis"]
459+
ovs_server_redis_cluster = create_redis_cache(
460+
stack_info=stack_info,
461+
cache_name=f"odl-video-service-redis-{stack_info.env_suffix}",
462+
description="Redis cluster for ODL Video Service",
463+
security_group_ids=[ovs_redis_security_group.id],
464+
subnet_group=target_vpc["elasticache_subnet"],
465+
subnet_ids=target_vpc["subnet_ids"][:3],
459466
auth_token=redis_auth_token,
460-
engine_version="7.2",
461467
engine="valkey",
468+
engine_version="7.2",
469+
instance_type=redis_config.get("instance_type")
470+
or redis_defaults.get("instance_type"),
462471
num_instances=3,
463-
shard_count=1,
464-
auto_upgrade=True,
465-
cluster_mode_enabled=False,
466-
cluster_description="Redis cluster for ODL Video Service.",
467-
cluster_name=f"odl-video-service-redis-{stack_info.env_suffix}",
468-
security_groups=[ovs_redis_security_group.id],
469-
subnet_group=target_vpc["elasticache_subnet"],
470472
tags=aws_config.tags,
471-
**defaults(stack_info)["redis"],
472-
)
473-
ovs_server_redis_cluster = OLAmazonCache(
474-
ovs_server_redis_config,
475473
opts=ResourceOptions(
476474
aliases=[
477475
Alias(

0 commit comments

Comments
 (0)