3333@task
3434def find_available_version (node_pool_info : node_pool .Info ) -> str :
3535 """Finds the latest available GKE version."""
36- region = node_pool_info .region
37- if not region :
38- raise ValueError ("Region not found in node_pool_info" )
3936
4037 command = (
41- f"gcloud container get-server-config --region={ region } --format='json'"
38+ f"gcloud container get-server-config --region={ node_pool_info .region } "
39+ f"--project={ node_pool_info .project_id } "
40+ "--format='json'"
4241 )
4342 logging .info ("Running command: %s" , command )
4443 stdout = subprocess .run_exec (command )
4544
4645 output_json = json .loads (stdout )
4746 valid_versions = output_json .get ("validMasterVersions" , [])
4847
49- # Filter: ^1\.(3[2-9]|[4-9][0-9])
5048 pattern = re .compile (r"^1\.(3[2-9]|[4-9][0-9])" )
5149 matching_versions = [v for v in valid_versions if pattern .match (v )]
5250
@@ -61,17 +59,8 @@ def find_available_version(node_pool_info: node_pool.Info) -> str:
6159@task
6260def find_current_cluster_version (node_pool_info : node_pool .Info ) -> dict :
6361 """Finds the current version of the cluster."""
64- cluster_name = node_pool_info .cluster_name
65- region = node_pool_info .region
66- if not cluster_name or not region :
67- raise ValueError ("cluster_name or region not found in node_pool_info" )
6862
69- command = (
70- f"gcloud container clusters describe { cluster_name } "
71- f"--region={ region } --format='json'"
72- )
73- logging .info ("Running command: %s" , command )
74- stdout = subprocess .run_exec (command )
63+ stdout = node_pool .describe_cluster (node_pool_info )
7564
7665 output_json = json .loads (stdout )
7766 current_master_version = output_json .get ("currentMasterVersion" )
@@ -92,21 +81,14 @@ def upgrade_master(
9281):
9382 """Upgrades the master to the target version if needed."""
9483 current_master = current_versions .get ("currentMasterVersion" )
95- cluster_name = node_pool_info .cluster_name
96- region = node_pool_info .region
9784
9885 if current_master != latest_version :
9986 logging .info (
10087 "Master version (%s) != Target (%s). Upgrading." ,
10188 current_master ,
10289 latest_version ,
10390 )
104- command = (
105- f"gcloud container clusters upgrade { cluster_name } --master "
106- f"--cluster-version={ latest_version } --region={ region } --quiet"
107- )
108- logging .info ("Running command: %s" , command )
109- subprocess .run_exec (command )
91+ node_pool .upgrade_cluster_master (node_pool_info , latest_version )
11092 else :
11193 logging .info ("Master is already at target version. Skipping." )
11294
@@ -117,37 +99,23 @@ def upgrade_nodes(
11799):
118100 """Upgrades all node pools to the target version if needed."""
119101 current_node = current_versions .get ("currentNodeVersion" )
120- cluster_name = node_pool_info .cluster_name
121- region = node_pool_info .region
122102
123103 if current_node != latest_version :
124104 logging .info (
125105 "Node version (%s) != Target (%s). Upgrading." ,
126106 current_node ,
127107 latest_version ,
128108 )
129- command = (
130- f"gcloud container clusters upgrade { cluster_name } "
131- f"--region={ region } --cluster-version={ latest_version } --quiet"
132- )
133- logging .info ("Running command: %s" , command )
134- subprocess .run_exec (command )
109+ node_pool .upgrade_cluster_node_pool (node_pool_info , latest_version )
135110 else :
136111 logging .info ("Nodes are already at target version. Skipping." )
137112
138113
139114@task
140115def verify_upgrade (target_version : str , node_pool_info : node_pool .Info ):
141116 """Verifies that the upgrade was successful."""
142- cluster_name = node_pool_info .cluster_name
143- region = node_pool_info .region
144117
145- command = (
146- f"gcloud container clusters describe { cluster_name } "
147- f"--region={ region } --format='json'"
148- )
149- logging .info ("Running command: %s" , command )
150- stdout = subprocess .run_exec (command )
118+ stdout = node_pool .describe_cluster (node_pool_info )
151119
152120 output_json = json .loads (stdout )
153121 current_master_version = output_json .get ("currentMasterVersion" )
0 commit comments