Skip to content

Instantly share code, notes, and snippets.

@Seekatar
Created February 6, 2021 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seekatar/5c14ad85d9d649ca0da9bf8377367ac4 to your computer and use it in GitHub Desktop.
Save Seekatar/5c14ad85d9d649ca0da9bf8377367ac4 to your computer and use it in GitHub Desktop.
Split up Helm dry-run output into separate files to match the template folder
<#
.SYNOPSIS
Split out the manifest files from a helm dryrun for comparing against one another or the Helm /template folder
.PARAMETER line
Lines from --dry-run output
.PARAMETER OutputPath
Existing folder where to put the files
.EXAMPLE
helm install . --dry-run --generate-name --values ..\config-values-api.yml | Split-HelmDryRun -OutputPath \temp\helm
bcomp.exe .\templates C:\temp\helm\cas-service\templates
Do a dry run of a cas-service template then launch BeyondCompare
#>
function Split-HelmDryRun
{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[string] $Line,
[Parameter(ValueFromPipeline, Mandatory)]
[string] $OutputPath
)
begin
{
$infile = $false
$fileName = $null
$ErrorActionPreference = 'Stop'
}
process
{
if ($Line -match '^# Source: (.*)')
{
$fileName = Join-Path $OutputPath $matches[1]
Write-Information "Writing chart output to $fileName" -InformationAction Continue
if (Test-Path $fileName)
{
Remove-Item $fileName
}
if (!(Test-Path (Split-Path $fileName -Parent)))
{
$null = mkdir (Split-Path $fileName -Parent)
}
$infile = $true
}
elseif ($Line -eq '---' -or $Line -eq 'NOTES:')
{
$infile = $false
$fileName = $null
}
elseif ($infile)
{
$Line | Out-File $fileName -Encoding ascii -Append
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment