mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
- make cluster-storage milestone opt-in and remove installer cluster-storage step from UI navigation\n- add cluster storage browser and GKE cluster ops helpers with CLI coverage\n- update k8s/CNPG config and install flow files for corrected cluster setup\n- add/refresh tests for storage browser, GKE ops, prod config, and service-layer navigation Co-authored-by: Junie <junie@jetbrains.com>
84 lines
2.4 KiB
Python
84 lines
2.4 KiB
Python
from pathlib import Path
|
|
import sys
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from subprocess import CompletedProcess
|
|
|
|
from knoe.core.ops import gke_clusters
|
|
|
|
|
|
def test_build_kubectl_env_for_cluster_sets_explicit_role_and_context():
|
|
env = gke_clusters.build_kubectl_env_for_cluster(
|
|
base_env={"EXISTING": "1"},
|
|
kubecontext="ctx-app",
|
|
cluster_name="knoe-dev-0",
|
|
cluster_role="app",
|
|
)
|
|
|
|
assert env["EXISTING"] == "1"
|
|
assert env["KUBECTL_CONTEXT"] == "ctx-app"
|
|
assert env["CLUSTER_NAME"] == "knoe-dev-0"
|
|
assert env["KNOE_CLUSTER_ROLE"] == "app"
|
|
assert env["KNOE_APP_CLUSTER_NAME"] == "knoe-dev-0"
|
|
|
|
|
|
def test_get_cluster_credentials_builds_expected_gcloud_command(monkeypatch):
|
|
called = {}
|
|
|
|
def fake_run(cmd, capture_output, text):
|
|
called["cmd"] = cmd
|
|
return CompletedProcess(cmd, 0, stdout="", stderr="")
|
|
|
|
monkeypatch.setattr(gke_clusters.subprocess, "run", fake_run)
|
|
|
|
context = gke_clusters.get_cluster_credentials(
|
|
project_id="proj-1",
|
|
cluster_name="knoe-cnpg-0",
|
|
location="us-central1",
|
|
)
|
|
|
|
assert context == "gke_proj-1_us-central1_knoe-cnpg-0"
|
|
assert called["cmd"] == [
|
|
"gcloud",
|
|
"container",
|
|
"clusters",
|
|
"get-credentials",
|
|
"knoe-cnpg-0",
|
|
"--project",
|
|
"proj-1",
|
|
"--region",
|
|
"us-central1",
|
|
"--quiet",
|
|
]
|
|
|
|
|
|
def test_ensure_db_cluster_creates_standard_cluster_with_minimum_nodes(monkeypatch):
|
|
commands = []
|
|
|
|
def fake_run(cmd, log=None):
|
|
commands.append(cmd)
|
|
if "describe" in cmd:
|
|
return CompletedProcess(cmd, 1, stdout="", stderr="not found")
|
|
return CompletedProcess(cmd, 0, stdout="created", stderr="")
|
|
|
|
monkeypatch.setattr(gke_clusters, "_run", fake_run)
|
|
|
|
spec = gke_clusters.GkeClusterSpec(
|
|
name="knoe-cnpg-0",
|
|
mode="standard",
|
|
location="us-central1",
|
|
machine_type="e2-small",
|
|
node_count=1,
|
|
node_pool_name="cnpg-db-pool",
|
|
)
|
|
|
|
gke_clusters.ensure_db_cluster(project_id="proj-1", spec=spec)
|
|
|
|
create_cmd = commands[-1]
|
|
assert create_cmd[:5] == ["gcloud", "container", "clusters", "create", "knoe-cnpg-0"]
|
|
assert "--num-nodes" in create_cmd
|
|
assert create_cmd[create_cmd.index("--num-nodes") + 1] == "3"
|