Skip to content

Commit

Permalink
Improve logging and splitting of knownResources
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed May 16, 2024
1 parent 804aeb8 commit b522e2b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Scripts/kubernetesHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function GetResourceVersionsUsed([string]$kubernetesConfigFile, [string]$selecto
Write-Host "Get Accessible Resources"
$resourceVersions = @()
$resources = @()
$knownResourcesArray = $knownResources -Split ","
$knownResourcesArray = $knownResources.Split(",",[System.StringSplitOptions]::RemoveEmptyEntries)

$rawResources = & $KubeCtlExe api-resources --verbs=list --namespaced -o name --kubeconfig=$kubernetesConfigFilePath

Expand All @@ -269,6 +269,11 @@ function GetResourceVersionsUsed([string]$kubernetesConfigFile, [string]$selecto
exit $LASTEXITCODE
}

if($knownResourcesArray.Count -ne 0)
{
Write-Host "Known Resource Types: $knownResourcesArray"
}

foreach($resource in $rawResources)
{
if ($resource.Contains("."))
Expand All @@ -280,15 +285,23 @@ function GetResourceVersionsUsed([string]$kubernetesConfigFile, [string]$selecto
{
if ($resources -notcontains $resource)
{
Write-Host " Checking $resource is accessible"
$cani = & $KubeCtlExe auth can-i list $resource --kubeconfig=$kubernetesConfigFilePath

if ($LASTEXITCODE -eq 0 -and $cani -eq "yes")
{
Write-Host " * $resource (accessible)"
$resources += $resource
}
else
{
Write-Host " * $resource (not accessible)"
}
}
}
else
{
Write-Host " * $resource (not checked)"
}
}

if ($resources.Count -gt 0)
Expand Down

0 comments on commit b522e2b

Please sign in to comment.