Kubernetes increse memory requests by 10% for all deployments

in case of urgency and need to perform fast change of resources change accross all deployments following script may be used

$deployments = kubectl get deployments -o json | ConvertFrom-Json | Select-Object -ExpandProperty items

foreach($deployment in $deployments) {
    # $deployment = $deployments |? { $_.metadata.name -eq 'users-api' }
    foreach($container in $deployment.spec.template.spec.containers) {
        # $container = $deployment.spec.template.spec.containers[0]
        if (-not $container.resources.requests.memory) {
            Write-Host "$($($deployment.metadata.name)) has no memory requests - skipping" -ForegroundColor Cyan
            continue
        }
        if (-not $container.resources.limits.memory) {
            Write-Host "$($($deployment.metadata.name)) has no memory limits - skipping" -ForegroundColor Cyan
            continue
        }
        if ($container.resources.requests.memory.Contains('Gi') -or $container.resources.limits.memory.Contains('Gi')) {
            Write-Host "$($($deployment.metadata.name)) has big memory requests of $($($container.resources.requests.memory)) - skipping" -ForegroundColor Cyan
            continue
        }

        $requestsCurrent = [int]$container.resources.requests.memory.Replace('Gi', '000').Replace('Mi', '')
        $requestsDesired = [math]::Ceiling( $requestsCurrent * 1.1 / 10 ) * 10

        $limitsCurrent = [int]$container.resources.limits.memory.Replace('Mi', '')
        $limitsDesired = [math]::Ceiling( $limitsCurrent * 1.1 / 10 ) * 10

        # Write-Host "$($deployment.metadata.name) requests $requestsCurrent > $requestsDesired limits $limitsCurrent > $limitsDesired"

        $patch = @{
            spec = @{
                template = @{
                    spec = @{
                        containers = @(
                            @{
                                name = $container.name
                                resources = @{
                                    requests = @{
                                        memory = "$($requestsDesired)Mi"
                                    }
                                    limits = @{
                                        memory = "$($limitsDesired)Mi"
                                        cpu = $null
                                    }
                                }
                            }
                        )
                    }
                }
            }
        } | ConvertTo-Json -Compress -Depth 100
        Write-Host "kubectl patch deployment $($deployment.metadata.name) -p '$patch'"
    }
}