As a Automation Assembler admin, you can use APIs to create a new tag and add it to a Kubernetes zone.
For information on Tanzu-enabled vSphere integration, see Use Tanzu supervisor clusters and namespaces in Automation Assembler
Prerequisites
- Verify that all general prerequisites and prerequisites for the Automation Assembler Infrastructure as a Service (IaaS) service have been satisfied. See Prerequisites for API Use Case Examples.
- Verify that you have the cloud account ID for a vSphere cloud account. See Add a vSphere Cloud Account.
Procedure
Example: Create a Kubernetes Zone with a Tag
Create a new tag with key example_tag_key and value example_tag_value. Create a Kubernetes zone named K8s-test-zone with the tag. To create a Kubernetes zone, you must associate it with a cloud account configured for Automation Assembler such as a vSphere cloud account with ID 8d4646bd-d629-4526-9009-10e3d4b66e44
.
url='https://appliance.domain.com'
$ api_version='2021-07-15'
Create a new tag with the key/value.
$ curl -X POST \ "$url/iaas/api/tags?apiVersion=$api_version" \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "key": "example_tag_key", "value": "example_tag_value" }' | jq "."
Examine the response for the tag ID.
{ "key": "example_tag_key", "value": "example_tag_value", "id": "a6f324e4-101c-33f6-ac51-d9aaaa020123" }
Assign a value to the tag ID variable.
$ tag_id1= 'a6f324e4-101c-33f6-ac51-d9aaaa020123'
Assign your vSphere cloud account ID to the cloud account ID variable.
$ cloud_account_id='8d4646bd-d629-4526-9009-10e3d4b66e44'
Create the Kubernetes zone with the tag and the cloud account ID.
$ curl -X POST \ "$url/cmx/api/resources/k8s-zones" \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "name": "k8s-test-zone", "providerId": "'$cloud_account_id'", "providerType": "VSPHERE_NAMESPACES", "tagIds": [ "'$tag_id1'" ] }' | jq "."
The response shows the Kubernetes zone.
{ "id": "220a81ba-c8ca-4f01-97bc-6f497576d564", "createdMillis": 1674847375758, "updatedMillis": 1674847375758, "orgId": "20451685-2bf6-4ba4-9ea4-87ee61bd32f8", "name": "k8s-test-zone", "providerId": "8d4646bd-d629-4526-9009-10e3d4b66e44", "providerType": "VSPHERE_NAMESPACES", "tagIds": [ "a6f324e4-101c-33f6-ac51-d9aaaa020123" ] }
If you want to update the Kubernetes zone, assign the Kubernetes zone ID variable.
$ k8s_zone_id='220a81ba-c8ca-4f01-97bc-6f497576d564'
If you want to add another tag, assign another tag ID variable.
$ tag_id2='21ccbdd6-c849-37f3-a784-1f2452cf802d'
Update the Kubernetes zone to add the tag.
$ curl -X PUT \ "$url/cmx/api/resources/k8s-zones/$k8s_zone_id" \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "id": "220a81ba-c8ca-4f01-97bc-6f497576d564", "createdMillis": 1674847375758, "updatedMillis": 1674847375758, "orgId": "20451685-2bf6-4ba4-9ea4-87ee61bd32f8", "name": "k8s-test-zone", "providerId": "'$cloud_account_id'", "providerType": "VSPHERE_NAMESPACES", "tagIds": [ "'$tag_id1'", "'$tag_id2'" ] }' | jq "."