i want to write tests for an adapter over google compute engine and google container engine.
for example:
node = gce.managedInstanceGroup("myGroup").createNode()
//do something with node
node.delete()
when i try to use the resize operation on a managed cluster to add a node, i get back an operation:
{
"kind": "compute#operation",
"id": --
"name": "operation---",
"zone": "https://www.googleapis.com/compute/v1/projects/--/zones/us-east1-d",
"operationType": "compute.instanceGroupManagers.resize",
"targetLink": "https://www.googleapis.com/compute/v1/projects/--/zones/us-east1-d/instanceGroupManagers/---grp",
"targetId": "--",
"status": "DONE",
"user": "--@--.iam.gserviceaccount.com",
"progress": 100,
"insertTime": "2016-05-10T04:40:28.281-07:00",
"startTime": "2016-05-10T04:40:28.283-07:00",
"endTime": "2016-05-10T04:40:28.283-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/--/zones/us-east1-d/operations/operation---"
}
i don't see a way to extract which nodes are being created by it. i can get a list of all nodes and see which ones are with status CREATING, but that doesn't mean they were created by MY operation. i can't just delete them, i don't know where they're from.
is there a way to determine exactly which nodes my resize operation created in the managed instance group?
additionally, how can i tell when my operation specifically is completed, if there isn't? how can i clean up my nodes?
as an alternative, is there a way to add nodes to a managed instance group other than the resize operation?
Managed Instance Groups operate using the 'intent based' semantics, i.e. you tell the instance group what your desired state of the group is and the group will optimally get to that state. The only thing the operations do is to set the target state. In the example operation you pasted you can see it has "status": "DONE"
. Managed instance groups do not track which instances where created as a result of which operation, because it gets really messy conceptually when you have multiple (some times contradictory) operations running in parallel. Please remember that many people have autohealers and autoscalers connected, which independently change the target state.
The typical way to get the newly created instances registered/configured/etc. is to define a start-up script in the instance template that will handle everything automatically. If you really need the list of names of the instances then, as Alex Robinson wrote, the only way is to list all instances before the operation and after the operation and calculate the diff.
If you are running only one operation at a time you can poll on list managed instances and wait until all of them are running. There is also a handy gcloud command wait-until-stable command that does exactly that.
If you need a better manual control over instances in your instance group you can always create a normal (non-managed) instance group: https://cloud.google.com/compute/docs/instance-groups/unmanaged-groups
To tell which nodes were added, you can list the instances in the instance group before and after the resize and see which nodes exist afterwards that didn't exist before.
To tell when the operation is done, poll the operation returned by the resize request. You can just directly due a GET on the contents of the "selfLink" field. In the example you show, it already is done, judging by its "status" field.
I'm not aware of a way to add nodes to a managed instance group other than the resize operation, and I'm honestly not sure why you'd want to?