-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add-SupervisorService
does not allow for services that do not need data yaml for registration
#763
Comments
I worked around this issue by adding cci: to the top of the configYAML so it was not empty |
Add-SupervisorService
does not allow for services that do not need data yaml for registration
Based on the way the function is authored, even though both It could be modified as follows: Function Add-SupervisorService {
Param (
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$pass,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$sddcDomain,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$cluster,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$registerYaml,
[Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$configureYaml
)
Try {
if (Test-VCFConnection -server $server) {
if (Test-VCFAuthentication -server $server -user $user -pass $pass) {
if (($vcfVcenterDetails = Get-vCenterServerDetail -server $server -user $user -pass $pass -domain $sddcDomain)) {
if (Test-VsphereConnection -server $($vcfVcenterDetails.fqdn)) {
if (Test-VsphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) {
if (($clusterDetails = Invoke-ListNamespaceManagementClusters | Where-Object { $_.cluster_name -eq $cluster })) {
if ($PsBoundParameters.ContainsKey("registerYaml")) {
if (Test-Path -Path $registerYaml) {
$supervisorService = (($supervisorService = (Select-String -Path $registerYaml -Pattern 'refName: ')) -Split ('refName: '))[-1]
$supervisorServiceVersion = (($supervisorServiceVersion = (Select-String -Path $registerYaml -Pattern 'version: ' -CaseSensitive)) -Split ('version: '))[-1]
$supervisorServiceDisplayName = (($supervisorServiceDisplayName = (Select-String -Path $registerYaml -Pattern 'displayName: ' -CaseSensitive)) -Split ('displayName: '))[-1]
if (-Not (Invoke-ListNamespaceManagementSupervisorServices -Server $DefaultVIServer | Where-Object { $_.display_name -eq $supervisorServiceDisplayName })) {
$supervisorServiceVersionYaml = Get-Content -Path $registerYaml -Raw
$supervisorServiceVersionYamlArray = [System.Text.Encoding]::UTF8.GetBytes($supervisorServiceVersionYaml)
$supervisorServiceVersionYamlbase64 = [System.Convert]::ToBase64String($supervisorServiceVersionYamlArray)
$supervisorServiceCarvelVersionSpec = Initialize-NamespaceManagementSupervisorServicesVersionsCarvelCreateSpec -Content $supervisorServiceVersionYamlbase64
$supervisorServiceCarvelCreateSpec = Initialize-NamespaceManagementSupervisorServicesCarvelCreateSpec -VersionSpec $supervisorServiceCarvelVersionSpec
$supervisorServiceCreateSpec = Initialize-NamespaceManagementSupervisorServicesCreateSpec -CarvelSpec $supervisorServiceCarvelCreateSpec
Invoke-CreateNamespaceManagementSupervisorServices -Server $DefaultVIServer -NamespaceManagementSupervisorServicesCreateSpec $supervisorServiceCreateSpec | Out-Null
if (Invoke-ListNamespaceManagementSupervisorServices -Server $DefaultVIServer | Where-Object { $_.display_name -eq $supervisorServiceDisplayName }) {
Write-Output "Registration of Supervisor Service ($supervisorService): SUCCESSFUL"
} else {
Write-Error "Registration of Supervisor Service ($supervisorService): POST_VALIDATION_FAILED"
}
} else {
Write-Warning "Registration of Supervisor Service ($supervisorService), already exists: SKIPPED"
}
} else {
Write-Error "Supervisor Service Registration YAML (.yml) File ($registerYaml) File Not Found: PRE_VALIDATION_FAILED"
}
}
if ($PsBoundParameters.ContainsKey("configureYaml")) {
if (Test-Path -Path $configureYaml) {
$supervisorServiceConfigurationYaml = Get-Content -Path $configureYaml -Raw
if (-Not $supervisorServiceConfigurationYaml) {
$supervisorServiceConfigurationYaml = "cci:`n configFileContents: {}"
}
$supervisorServiceConfigurationYamlArray = [System.Text.Encoding]::UTF8.GetBytes($supervisorServiceConfigurationYaml)
$supervisorServiceConfigurationYamlBase64 = [System.Convert]::ToBase64String($supervisorServiceConfigurationYamlArray)
$supervisorServicesCreateSpec = Initialize-NamespaceManagementSupervisorServicesClusterSupervisorServicesCreateSpec -SupervisorService $supervisorService -Version $supervisorServiceVersion -YamlServiceConfig $supervisorServiceConfigurationYamlBase64
Invoke-CreateClusterNamespaceManagementSupervisorServices -Server $DefaultVIServer -Cluster $clusterDetails.cluster -NamespaceManagementSupervisorServicesClusterSupervisorServicesCreateSpec $supervisorServicesCreateSpec | Out-Null
Start-Sleep 5
if (Invoke-ListClusterNamespaceManagementSupervisorServices -Server $DefaultVIServer -Cluster $clusterDetails.cluster | Where-Object { $_.supervisor_service -eq $supervisorService }) {
Write-Output "Deployment of Supervisor Service ($supervisorService): SUCCESSFUL"
} else {
Write-Error "Deployment of Supervisor Service ($supervisorService): POST_VALIDATION_FAILED"
}
} else {
Write-Error "Supervisor Service Configuration YAML (.yml) File ($configureYaml) File Not Found: PRE_VALIDATION_FAILED"
}
} else {
Write-Warning "No configuration YAML provided, skipping deployment."
}
} else {
Write-Error "Unable to locate a Kubernetes Cluster on Cluster ($cluster): PRE_VALIDATION_FAILED"
}
}
Disconnect-VIServer -Server $vcfVcenterDetails.fqdn -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
}
}
}
} Catch {
Debug-ExceptionWriter -object $_
}
} |
Alternatively, with guard clauses to reduce the nesting, fail fast, and make it more readable. Function Add-SupervisorService {
Param (
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$pass,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$sddcDomain,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$cluster,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$registerYaml,
[Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$configureYaml
)
Try {
if (-Not (Test-VCFConnection -server $server)) {
Write-Error "Failed to connect to VCF server: $server"
return
}
if (-Not (Test-VCFAuthentication -server $server -user $user -pass $pass)) {
Write-Error "Failed to authenticate to VCF server: $server"
return
}
$vcfVcenterDetails = Get-vCenterServerDetail -server $server -user $user -pass $pass -domain $sddcDomain
if (-Not $vcfVcenterDetails) {
Write-Error "Failed to get vCenter server details for domain: $sddcDomain"
return
}
if (-Not (Test-VsphereConnection -server $vcfVcenterDetails.fqdn)) {
Write-Error "Failed to connect to vSphere server: $($vcfVcenterDetails.fqdn)"
return
}
if (-Not (Test-VsphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass)) {
Write-Error "Failed to authenticate to vSphere server: $($vcfVcenterDetails.fqdn)"
return
}
$clusterDetails = Invoke-ListNamespaceManagementClusters | Where-Object { $_.cluster_name -eq $cluster }
if (-Not $clusterDetails) {
Write-Error "Unable to locate a Kubernetes Cluster on Cluster ($cluster): PRE_VALIDATION_FAILED"
return
}
if (-Not (Test-Path -Path $registerYaml)) {
Write-Error "Supervisor Service Registration YAML (.yml) File ($registerYaml) File Not Found: PRE_VALIDATION_FAILED"
return
}
$supervisorService = (Select-String -Path $registerYaml -Pattern 'refName: ') -Split 'refName: ' | Select-Object -Last 1
$supervisorServiceVersion = (Select-String -Path $registerYaml -Pattern 'version: ' -CaseSensitive) -Split 'version: ' | Select-Object -Last 1
$supervisorServiceDisplayName = (Select-String -Path $registerYaml -Pattern 'displayName: ' -CaseSensitive) -Split 'displayName: ' | Select-Object -Last 1
if (Invoke-ListNamespaceManagementSupervisorServices -Server $DefaultVIServer | Where-Object { $_.display_name -eq $supervisorServiceDisplayName }) {
Write-Warning "Registration of Supervisor Service ($supervisorService), already exists: SKIPPED"
} else {
$supervisorServiceVersionYaml = Get-Content -Path $registerYaml -Raw
$supervisorServiceVersionYamlArray = [System.Text.Encoding]::UTF8.GetBytes($supervisorServiceVersionYaml)
$supervisorServiceVersionYamlbase64 = [System.Convert]::ToBase64String($supervisorServiceVersionYamlArray)
$supervisorServiceCarvelVersionSpec = Initialize-NamespaceManagementSupervisorServicesVersionsCarvelCreateSpec -Content $supervisorServiceVersionYamlbase64
$supervisorServiceCarvelCreateSpec = Initialize-NamespaceManagementSupervisorServicesCarvelCreateSpec -VersionSpec $supervisorServiceCarvelVersionSpec
$supervisorServiceCreateSpec = Initialize-NamespaceManagementSupervisorServicesCreateSpec -CarvelSpec $supervisorServiceCarvelCreateSpec
Invoke-CreateNamespaceManagementSupervisorServices -Server $DefaultVIServer -NamespaceManagementSupervisorServicesCreateSpec $supervisorServiceCreateSpec | Out-Null
if (Invoke-ListNamespaceManagementSupervisorServices -Server $DefaultVIServer | Where-Object { $_.display_name -eq $supervisorServiceDisplayName }) {
Write-Output "Registration of Supervisor Service ($supervisorService): SUCCESSFUL"
} else {
Write-Error "Registration of Supervisor Service ($supervisorService): POST_VALIDATION_FAILED"
return
}
}
if ($PsBoundParameters.ContainsKey("configureYaml")) {
if (-Not (Test-Path -Path $configureYaml)) {
Write-Error "Supervisor Service Configuration YAML (.yml) File ($configureYaml) File Not Found: PRE_VALIDATION_FAILED"
return
}
$supervisorServiceConfigurationYaml = Get-Content -Path $configureYaml -Raw
if (-Not $supervisorServiceConfigurationYaml) {
$supervisorServiceConfigurationYaml = "cci:`n configFileContents: {}"
}
$supervisorServiceConfigurationYamlArray = [System.Text.Encoding]::UTF8.GetBytes($supervisorServiceConfigurationYaml)
$supervisorServiceConfigurationYamlBase64 = [System.Convert]::ToBase64String($supervisorServiceConfigurationYamlArray)
$supervisorServicesCreateSpec = Initialize-NamespaceManagementSupervisorServicesClusterSupervisorServicesCreateSpec -SupervisorService $supervisorService -Version $supervisorServiceVersion -YamlServiceConfig $supervisorServiceConfigurationYamlBase64
Invoke-CreateClusterNamespaceManagementSupervisorServices -Server $DefaultVIServer -Cluster $clusterDetails.cluster -NamespaceManagementSupervisorServicesClusterSupervisorServicesCreateSpec $supervisorServicesCreateSpec | Out-Null
Start-Sleep 5
if (Invoke-ListClusterNamespaceManagementSupervisorServices -Server $DefaultVIServer -Cluster $clusterDetails.cluster | Where-Object { $_.supervisor_service -eq $supervisorService }) {
Write-Output "Deployment of Supervisor Service ($supervisorService): SUCCESSFUL"
} else {
Write-Error "Deployment of Supervisor Service ($supervisorService): POST_VALIDATION_FAILED"
}
} else {
Write-Warning "No configuration YAML provided, skipping deployment."
}
Disconnect-VIServer -Server $vcfVcenterDetails.fqdn -Confirm:$false -WarningAction SilentlyContinue | Out-Null
} Catch {
Debug-ExceptionWriter -object $_
}
} |
Code of Conduct
VMware Cloud Foundation
5.2
Module Version
2.11.1.1010
PowerShell Version
7.4.4
PowerCLI Version
13.2.1
PowerVCF Version
2.4.1.1000
Guest Operating System
Windows 11
Environment Details
No response
Description
Using Add-SupervisorService to register CCI does not seem to work. I have tried without the parameter -configureYaml .as well as pass it an empty yml file. Neither works. The first does not seem to return, does not register the servicee at all, I have to break. And the second returns the error
Registration of Supervisor Service (cci-service.fling.vsphere.vmware.com): SUCCESFUL
Error at Script Line 12877
Relevant Command: $supervisorServiceConfigurationYamlArray = [System.Text.Encoding]::UTF8.GetBytes($supervisorServiceConfigurationYaml)
Error Message: Exception calling "GetBytes" with "1" argument(s): "Value cannot be null. (Parameter 'chars')"
And at least registers or adds the service to WCP, but I then need to manually install it to the supervisor
Error or Debug Output
I have none
Expected Behavior
To register and install the service to he supervisor
Actual Behavior
In description
Steps to Reproduce
Add-SupervisorService -Server $sddcManagerFqdn -User $sddcManagerUser -Pass $sddcManagerPass -sddcDomain $sddcDomainName -Cluster $wmClusterName -registerYaml ..\cci-supervisor-service.yml -configureYaml ..\cci-supervisor-service-empty.yml
Log Fragments and Files
No response
Screenshots
No response
References
No response
The text was updated successfully, but these errors were encountered: