Last active
September 15, 2023 02:44
-
-
Save GustavoAmerico/f362a86581ed078e4e2178b2865cb348 to your computer and use it in GitHub Desktop.
Gets the list of certificates (cert-manager) that are scheduled to renew in the next X days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function k8s-certificates-renew{ | |
param([Parameter()][int]$days = 15) | |
((kubectl get certificates -A -o json | ConvertFrom-Json).items) | | |
?{[Datetime]($_.status.renewalTime) -lt (Get-Date).AddDays($days) }| | |
%{ [pscustomobject]@{Name=$_.metadata.name; RenewAt=[DateTime]$_.status.renewalTime; Namespace=$_.metadata. Namespace } } | |
} | |
function k8s-Select-Resources { | |
###Essa função é responsável por extrair as informações | |
###dos recursos dedicados aos deployments | |
param([Parameter(ValueFromPipeline = $true)]$deployListJson) | |
process { | |
function ExtractCpuNumber{ | |
param($cpu) | |
if (($cpu -match '[0-9]+m') -eq $False) | |
{return ([int]$cpu * 1000);} | |
else | |
{return [int]($cpu -replace '[a-z]');} | |
} | |
return ($deployListJson.items | Foreach-object{ | |
$containers = $_.spec.template.spec.containers ?? $_.spec.containers; | |
$deployName = $_.metadata.name; | |
$deployNamespace = $_.metadata.Namespace; | |
return ($containers|Foreach-object{ | |
$resources = $_.resources; | |
$container = $_; | |
[pscustomobject]@{ | |
Name = $deployName ; | |
ContainerName = ($_.name); | |
Namespace = $deployNamespace; | |
MemoryMin = ($resources.requests.memory); | |
CPUMin = ExtractCpuNumber $resources.requests.cpu; | |
MemoryMax = ($resources.limits.memory); | |
CPUMax = (ExtractCpuNumber $resources.limits.cpu); | |
Image = ($container.image); | |
} | |
}); | |
} ) | Sort-Object -Property CPUMin -Desc | |
} | |
} | |
function k8s-deploy-resources { | |
param([Parameter()][string]$namespace = 'production') | |
(kubectl get deployments -n $namespace --output json | ConvertFrom-Json) | k8s-Select-Resources | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment