Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address issue with AWS instance type schema #2787

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/_nebari/stages/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AzureInputVars(schema.Base):
workload_identity_enabled: bool = False


class AWSAmiTypes(enum.Enum):
class AWSAmiTypes(str, enum.Enum):
AL2_x86_64 = "AL2_x86_64"
AL2_x86_64_GPU = "AL2_x86_64_GPU"
CUSTOM = "CUSTOM"
Expand All @@ -151,25 +151,21 @@ class AWSNodeGroupInputVars(schema.Base):
ami_type: Optional[AWSAmiTypes] = None
launch_template: Optional[AWSNodeLaunchTemplate] = None

@field_validator("ami_type", mode="before")
@classmethod
def _infer_and_validate_ami_type(cls, value, values) -> str:
gpu_enabled = values.get("gpu", False)

# Auto-set ami_type if not provided
if not value:
if values.get("launch_template") and values["launch_template"].ami_id:
return "CUSTOM"
if gpu_enabled:
return "AL2_x86_64_GPU"
return "AL2_x86_64"

# Explicit validation
if value == "AL2_x86_64" and gpu_enabled:
raise ValueError(
"ami_type 'AL2_x86_64' cannot be used with GPU enabled (gpu=True)."
)
return value

def construct_aws_ami_type(
gpu_enabled: bool, launch_template: AWSNodeLaunchTemplate, ami_type: str = None
):
"""Construct the AWS AMI type based on the provided parameters."""
if ami_type:
return ami_type

if launch_template and launch_template.ami_id:
return "CUSTOM"

if gpu_enabled:
return "AL2_x86_64_GPU"

return "AL2_x86_64"


class AWSInputVars(schema.Base):
Expand Down Expand Up @@ -858,6 +854,10 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
single_subnet=node_group.single_subnet,
permissions_boundary=node_group.permissions_boundary,
launch_template=node_group.launch_template,
ami_type=construct_aws_ami_type(
gpu_enabled=node_group.gpu,
launch_template=node_group.launch_template,
),
)
for name, node_group in self.config.amazon_web_services.node_groups.items()
],
Expand Down
Loading