Private/Checks/VCenter/Test-VcfVcenterVsphereSupervisorClusterVersions.ps1

# Copyright (c) 2026 Broadcom. All Rights Reserved.
# Broadcom Confidential. The term "Broadcom" refers to Broadcom Inc.
# and/or its subsidiaries.
#
# =============================================================================
#
# SOFTWARE LICENSE AGREEMENT
#
# Copyright (c) CA, Inc. All rights reserved.
#
# You are hereby granted a non-exclusive, worldwide, royalty-free license
# under CA, Inc.'s copyrights to use, copy, modify, and distribute this
# software in source code or binary form for use in connection with CA, Inc.
# products.
#
# This copyright notice shall be included in all copies or substantial
# portions of the software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# =============================================================================
function Test-VcfVcenterVsphereSupervisorClusterVersions {

    <#
        .SYNOPSIS
        Reports the Kubernetes version of every vSphere Supervisor cluster across all vCenter domains.

        .DESCRIPTION
        Queries software and Kubernetes version details for vSphere Supervisor clusters across all vCenter
        appliances connected to SDDC Manager using Get-VcfCheckSupervisorClusterSoftware.

        Evaluates Supervisor cluster presence:
        - Pass: vSphere Supervisor clusters are present, and software version details are reported.
        - Skipped: No vSphere Supervisor clusters are deployed on the target vCenter.

        Populates a structured Rows table detailing ClusterName, Cluster, and CurrentVersion.
        Delegates per-vCenter execution and per-domain outcome packaging to Invoke-VcfCheckPerVCenterCheck.

        .PARAMETER Context
        The VcfCheck.Context object. Must already be connected to SDDC Manager.

        .PARAMETER DisplayName
        Optional friendly display name for the check result.

        .OUTPUTS
        [PSObject[]] Per-vCenter check results generated by Invoke-VcfCheckPerVCenterCheck.
    #>


    [CmdletBinding()]
    [OutputType([PSObject])]
    Param (
        [Parameter(Mandatory = $true)] [PSObject]$Context,
        [Parameter(Mandatory = $false)] [String]$DisplayName = ''
    )

    return Invoke-VcfCheckPerVCenterCheck -Context $Context -CheckId 'vcenter_vsphere_supervisor_cluster_versions' -Area vCenter -DisplayName $DisplayName -Body {
        param($Context, $VCenterFqdn)
        $clusters = @(Get-VcfCheckSupervisorClusterSoftware -Server $VCenterFqdn)

        if ($clusters.Count -eq 0) {
            return [PSCustomObject]@{ Status = 'Skipped'; Detail = 'vSphere Supervisor is not deployed (no Supervisor clusters found).'; SkipReasonTag = 'Supervisor Service not installed'; Rows = @() }
        }

        $rows = @($clusters | ForEach-Object {
            [PSCustomObject]@{
                ClusterName = $_.ClusterName
                Cluster = $_.Cluster
                CurrentVersion = $_.CurrentVersion
            }
        })
        $lines = $clusters | ForEach-Object { "$($_.ClusterName) ($($_.Cluster)): $($_.CurrentVersion)" }
        return [PSCustomObject]@{ Status = 'Pass'; Detail = ($lines -join "`n"); Rows = $rows }
    }
}