Skip to content

Commit 0f03faf

Browse files
committed
Disable AWS launch_template from nebari-config schema (#2855)
1 parent 6b32630 commit 0f03faf

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/_nebari/stages/infrastructure/__init__.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import tempfile
99
from typing import Annotated, Any, Dict, List, Literal, Optional, Tuple, Type, Union
1010

11-
from pydantic import Field, PrivateAttr, field_validator, model_validator
11+
from pydantic import Field, field_validator, model_validator
1212

1313
from _nebari import constants
1414
from _nebari.provider import terraform
@@ -136,7 +136,7 @@ class AWSAmiTypes(str, enum.Enum):
136136

137137
class AWSNodeLaunchTemplate(schema.Base):
138138
pre_bootstrap_command: Optional[str] = None
139-
_ami_id: Optional[str] = PrivateAttr(default=None)
139+
ami_id: Optional[str] = None
140140

141141

142142
class AWSNodeGroupInputVars(schema.Base):
@@ -152,10 +152,23 @@ class AWSNodeGroupInputVars(schema.Base):
152152
launch_template: Optional[AWSNodeLaunchTemplate] = None
153153

154154

155-
def construct_aws_ami_type(gpu_enabled: bool, launch_template: AWSNodeLaunchTemplate):
156-
"""Construct the AWS AMI type based on the provided parameters."""
155+
def construct_aws_ami_type(
156+
gpu_enabled: bool, launch_template: AWSNodeLaunchTemplate
157+
) -> str:
158+
"""
159+
This function selects the Amazon Machine Image (AMI) type for AWS nodes by evaluating
160+
the provided parameters. The selection logic prioritizes the launch template over the
161+
GPU flag.
162+
163+
Returns the AMI type (str) determined by the following rules:
164+
- Returns "CUSTOM" if a `launch_template` is provided and it includes a valid `ami_id`.
165+
- Returns "AL2_x86_64_GPU" if `gpu_enabled` is True and no valid
166+
`launch_template` is provided (None).
167+
- Returns "AL2_x86_64" as the default AMI type if `gpu_enabled` is False and no
168+
valid `launch_template` is provided (None).
169+
"""
157170

158-
if launch_template and launch_template._ami_id:
171+
if launch_template and getattr(launch_template, "ami_id", None):
159172
return "CUSTOM"
160173

161174
if gpu_enabled:
@@ -474,7 +487,16 @@ class AWSNodeGroup(schema.Base):
474487
gpu: bool = False
475488
single_subnet: bool = False
476489
permissions_boundary: Optional[str] = None
477-
launch_template: Optional[AWSNodeLaunchTemplate] = None
490+
# Disabled as part of 2024.11.1 until #2832 is resolved
491+
# launch_template: Optional[AWSNodeLaunchTemplate] = None
492+
493+
@model_validator(mode="before")
494+
def check_launch_template(cls, values):
495+
if "launch_template" in values:
496+
raise ValueError(
497+
"The 'launch_template' field is currently unavailable and has been removed from the configuration schema.\nPlease omit this field until it is reintroduced in a future update.",
498+
)
499+
return values
478500

479501

480502
DEFAULT_AWS_NODE_GROUPS = {
@@ -855,10 +877,10 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
855877
max_size=node_group.max_nodes,
856878
single_subnet=node_group.single_subnet,
857879
permissions_boundary=node_group.permissions_boundary,
858-
launch_template=node_group.launch_template,
880+
launch_template=None,
859881
ami_type=construct_aws_ami_type(
860882
gpu_enabled=node_group.gpu,
861-
launch_template=node_group.launch_template,
883+
launch_template=None,
862884
),
863885
)
864886
for name, node_group in self.config.amazon_web_services.node_groups.items()

0 commit comments

Comments
 (0)