How to configure custom attributes for a Rancher-provisioned vSphere cluster?
Article Number: 000021878
Environment
- SUSE Rancher Prime - All Versions.
- Rancher-provisioned vSphere cluster.
Situation
cpp Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Custom attributes in vSphere are user-defined fields that allow users to store metadata for objects like VMs, hosts,etc. - Custom attributes are a legacy feature in vSphere for attaching metadata to objects, while tags are the modern alternative. A tag is a label that can be applied to an object in the vSphere inventory. - Users may need custom attributes for existing workflows or integrations that rely on this metadata for the vSphere clusters provisioned through Rancher.
Cause
- According to the documentation, Custom attributes are a legacy feature that will eventually be removed from vSphere. However, it can be configured through a custom resource definition
vmwarevsphereconfigs.rke-machine-config.cattle.io
on a Rancher-provisioned vsphere cluster. - Since custom attributes will be removed in future vSphere versions, users should consider migrating to tags or other solutions for long-term use.
Resolution
- Make sure the attributes are already created from vSphere client side: vSphere client >> Menu >> Tags & Custom Attributes.
- As custom attribute is stored in key-value format and each key has its own identifier as
ID
. To fetch the ID of the key, first verify that PowerCLI is installed. If not, run the command below from PowerShell to install:
Install-Module -Name VMware.PowerCLI
Connect-VIServer -Server server.example.com -User <username> -Password <password>
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Owner
:
Get-CustomAttribute
Owner
with any custom attribute defined in your vSphere environment:
Get-CustomAttribute -Name "Owner"
Key
column for the attribute.
- Edit the resource vmwarevsphereconfigs.rke-machine-config.cattle.io
in the Rancher management cluster (local cluster) for the specific downstream cluster. Run the first command to get the resource name for the desired downstream cluster. Below is an example shown for a customAttribute Owner
:
kubectl -n fleet-default get vmwarevsphereconfigs.rke-machine-config.cattle.io
kubectl -n fleet-default edit vmwarevsphereconfigs.rke-machine-config.cattle.io <downstream_cluster>
Owner
. Replace the id with the one defined in your vSphere environment for the desired attribute:
customAttribute:
- 1234=user1
Get-VM -Name "<VM_NAME>" | Get-Annotation