Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into commands/upgrade/at…
Browse files Browse the repository at this point in the history
…tempt-fix-logic
  • Loading branch information
smokestacklightnin committed Dec 11, 2024
2 parents 40b4660 + 7acea49 commit 473a66a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
exclude: "^src/_nebari/template/"

- repo: https://github.com/crate-ci/typos
rev: v1.27.0
rev: typos-dict-v0.11.37
hooks:
- id: typos

Expand All @@ -61,7 +61,7 @@ repos:
args: ["--line-length=88", "--exclude=/src/_nebari/template/"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix"]
Expand Down
18 changes: 18 additions & 0 deletions src/_nebari/provider/cloud/google_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def regions() -> Set[str]:
return {region.name for region in response}


@functools.lru_cache()
def instances(region: str) -> set[str]:
"""Return a set of available compute instances in a region."""
credentials, project_id = load_credentials()
zones_client = compute_v1.services.region_zones.RegionZonesClient(
credentials=credentials
)
instances_client = compute_v1.MachineTypesClient(credentials=credentials)
zone_list = zones_client.list(project=project_id, region=region)
zones = [zone for zone in zone_list]
instance_set: set[str] = set()
for zone in zones:
instance_list = instances_client.list(project=project_id, zone=zone.name)
for instance in instance_list:
instance_set.add(instance.name)
return instance_set


@functools.lru_cache()
def kubernetes_versions(region: str) -> List[str]:
"""Return list of available kubernetes supported by cloud provider. Sorted from oldest to latest."""
Expand Down
15 changes: 15 additions & 0 deletions src/_nebari/stages/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ def _check_input(cls, data: Any) -> Any:
raise ValueError(
f"\nInvalid `kubernetes-version` provided: {data['kubernetes_version']}.\nPlease select from one of the following supported Kubernetes versions: {available_kubernetes_versions} or omit flag to use latest Kubernetes version available."
)

# check if instances are valid
available_instances = google_cloud.instances(data["region"])
if "node_groups" in data:
for _, node_group in data["node_groups"].items():
instance = (
node_group["instance"]
if hasattr(node_group, "__getitem__")
else node_group.instance
)
if instance not in available_instances:
raise ValueError(
f"Google Cloud Platform instance {instance} not one of available instance types={available_instances}"
)

return data


Expand Down
5 changes: 5 additions & 0 deletions tests/tests_unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def _mock_return_value(return_value):
"us-central1",
"us-east1",
],
"_nebari.provider.cloud.google_cloud.instances": [
"e2-standard-4",
"e2-standard-8",
"e2-highmem-4",
],
}

for attribute_path, return_value in MOCK_VALUES.items():
Expand Down

0 comments on commit 473a66a

Please sign in to comment.