How to configure custom attributes for a Rancher-provisioned vSphere cluster?
This document (000021878) is provided subject to the disclaimer at the end of this document.
Environment
- SUSE Rancher Prime - All Versions.
- Rancher-provisioned vSphere cluster.
Situation
- ```
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Install-Module -Name VMware.PowerCLI
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. ### 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:
Connect-VIServer -Server server.example.com -User- Now, connect to the desired vSphere cluster using the below command in Power CLI:
-Password Set-PowerCLIConfiguration -InvalidCertificateAction Ignore- If it fails with SSL error, then you can try the workaround below & re-run the above command:
Get-CustomAttribute- Now fetch the customAttributes from the environment, below is an example shown for custom attribute `Owner`:
Get-CustomAttribute -Name "Owner"- Run the command below to get a specific attribute. Replace `Owner ` with any custom attribute defined in your vSphere environment:
kubectl -n fleet-default get vmwarevsphereconfigs.rke-machine-config.cattle.io kubectl -n fleet-default edit vmwarevsphereconfigs.rke-machine-config.cattle.io- Note the ID mentioned in `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`:
customAttribute:- In the example YAML output given below 1234 is the id for the attribute `Owner`. Replace the id with the one defined in your vSphere environment for the desired attribute:
-
1234=user1 ```
-
Verify the custom attribute in the vSphere client under 'Tags & Custom Attributes' or run the below command from PowerCLI:
Get-VM -Name "<VM_NAME>" | Get-Annotation
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.
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.