Get google cloud container cluster provisioning status using api python client

I am creating a container cluster using the python API for the google cloud platform. I did successfully creating the container. Now I need to apply some settings of the barley, but before applying any kubernetes yaml configurations, the cluster must be provided otherwise the kubernetes API is not available. I need to do one thing (creating a container, and applying yaml configs) in one request. How can I get cluster provisioning status using api?

Here is what I tried:

After creating the cluster: From views.py:

print('Fetching Cluster configs ....') cc = subprocess.call( 'gcloud container clusters get-credentials ' + deployment.deploymentName.lower() + ' --zone ' + deployment.region + ' --project ' + deployment.project, shell=True) print(cc) while cc == 1: cc = subprocess.call( 'gcloud container clusters get-credentials ' + deployment.deploymentName.lower() + ' --zone ' + deployment.region + ' --project ' + deployment.project, shell=True) print(cc) 

Help me please!

Thank Advance

0
source share
2 answers

Here is how I do it in my code:

 """ If you have a credentials issue, run: gcloud beta auth application-default login """ import time import googleapiclient.discovery service = googleapiclient.discovery.build('container', 'v1') clusters_resource = service.projects().zones().clusters() operations_resource = service.projects().zones().operations() def create_cluster(project_id, zone, config, async=False): req = clusters_resource.create(projectId=project_id, zone=zone, body=config) operation = req.execute() if async: return while operation['status'] == 'RUNNING': time.sleep(1) req = operations_resource.get(projectId=project_id, zone=zone, operationId=operation['name']) operation = req.execute() return operation['status'] == 'DONE' 
+1
source

What you are looking for is the status of the operation whose identifier is returned from the create cluster call . Then you need to perform the operation (via the container API, not the calculation API) and check the status of the operation to see if it is DONE. Once this is done, you can determine if there was an error by viewing the status message in the operation. If it is empty, then the cluster API call is created successfully. If it is not empty, the call failed, and a status message tells you why. Once the cluster creation operation is complete, the get-credentials call will succeed.

+2
source

Source: https://habr.com/ru/post/1268821/


All Articles