-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathKubeTidy.psm1
More file actions
59 lines (54 loc) · 2.3 KB
/
Copy pathKubeTidy.psm1
File metadata and controls
59 lines (54 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env pwsh
$privatePath = Join-Path -Path $PSScriptRoot -ChildPath 'Private'
foreach ($scriptName in 'Get-KubeTidyBinaryPath.ps1', 'Invoke-KubeTidyBinary.ps1') {
. (Join-Path -Path $privatePath -ChildPath $scriptName)
}
function Invoke-KubeTidy {
[CmdletBinding()]
param (
[string]$KubeConfigPath,
[array]$ExclusionList,
[bool]$Backup = $true,
[switch]$Force,
[switch]$ListClusters,
[switch]$ListContexts,
[switch]$Report,
[switch]$Doctor,
[string]$ExportContexts = "",
[array]$MergeConfigs,
[string]$DestinationConfig,
[switch]$DryRun,
[int]$ProbeTimeoutSeconds = 5,
[ValidateSet("text", "json", "yaml")] [string]$Output = "text",
[ValidateSet("keep-first", "keep-last", "fail-on-conflict")] [string]$MergeStrategy = "keep-first",
[switch]$UI,
[Alias("h")] [switch]$Help
)
$args = @()
if ($KubeConfigPath) { $args += @('--kubeconfig', $KubeConfigPath) }
if ($ExclusionList) {
$exclusions = @($ExclusionList | ForEach-Object { $_.ToString() } | Where-Object { $_.Trim() -ne '' })
if ($exclusions.Count -gt 0) {
$args += @('--exclusionlist', ($exclusions -join ','))
}
}
if (-not $Backup) { $args += @('--backup=false') }
if ($Force) { $args += '--force' }
if ($ListClusters) { $args += '--listclusters' }
if ($ListContexts) { $args += '--listcontexts' }
if ($Report) { $args += '--report' }
if ($Doctor) { $args += '--doctor' }
if ($ExportContexts) { $args += @('--exportcontexts', $ExportContexts) }
foreach ($configPath in @($MergeConfigs | Where-Object { $_ })) {
$args += @('--mergeconfigs', $configPath)
}
if ($DestinationConfig) { $args += @('--destinationconfig', $DestinationConfig) }
if ($DryRun) { $args += '--dryrun' }
if ($PSBoundParameters.ContainsKey('ProbeTimeoutSeconds')) { $args += @('--probe-timeout-seconds', $ProbeTimeoutSeconds.ToString()) }
if ($Output) { $args += @('--output', $Output) }
if ($MergeStrategy) { $args += @('--merge-strategy', $MergeStrategy) }
if ($UI) { $args += '--ui' }
if ($Help) { $args += '--help' }
if ($PSBoundParameters.ContainsKey('Verbose')) { $args += '--verbose' }
Invoke-KubeTidyBinary -Arguments $args
}