Skip to content

Instantly share code, notes, and snippets.

@toredash
toredash / workbook
Created April 29, 2026 10:02
Azure Workbooks to identify Subscriptions with broken diagnostic settings
// 1. Fetch the master list of all Subscriptions from Azure Resource Manager
arg("").resourcecontainers
| where type =~ "microsoft.resources/subscriptions"
| project SubscriptionId = toupper(subscriptionId), SubscriptionName = name
// 2. Do a left-outer join with our Log Analytics workspace data
| join kind=fullouter (
AzureActivity
| where TimeGenerated > ago(30d)
| summarize LastLogReceived = max(TimeGenerated), TotalLogs30Days = count() by SubscriptionId = toupper(SubscriptionId)
) on SubscriptionId
@toredash
toredash / re-apply-diagnostic-settings-azure-subscriptions.sh
Created April 28, 2026 12:09
re-apply-diagnostic-settings-azure-subscriptions.sh
#!/bin/bash
# Ensure required CLI tools are installed
command -v jq >/dev/null || { echo "Error: 'jq' required. Install it using 'brew install jq' or similar."; exit 1; }
command -v az >/dev/null || { echo "Error: Azure CLI ('az') required."; exit 1; }
# Configuration
BACKUP_DIR="diag_settings_backups"
API_VER="2021-05-01-preview"
mkdir -p "$BACKUP_DIR"
@toredash
toredash / gist:d4879e2d5dbd44e102d10a9865844740
Created January 30, 2025 14:05
ingress-nginx - how to add custom log keys/values from Ingress object
diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl
index a1e02aae3..886dc33c1 100644
--- a/rootfs/etc/nginx/template/nginx.tmpl
+++ b/rootfs/etc/nginx/template/nginx.tmpl
@@ -1229,6 +1229,7 @@ stream {
{{ $ing := (getIngressInformation $location.Ingress $server.Hostname $location.IngressPath) }}
set $namespace {{ $ing.Namespace | quote}};
set $ingress_name {{ $ing.Rule | quote }};
+ set $service_annotations {{ if $value := $ing.Annotations.log_group }}"{{ $value }}"{{ else }}"-"{{ end }};
@toredash
toredash / remove-cpu-limits-requests.yaml
Created October 3, 2024 11:14
Kyverno policy to remove cpu requests and limits
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remove-cpu-limits-requests
spec:
rules:
- name: remove-cpu-limits-per-container
match:
any:
- resources:
@toredash
toredash / add-aks-spot-taint.yaml
Created October 3, 2024 11:13
Kyverno mutating policy to tolerate AKS Spot nodes
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-aks-spot-taint
annotations:
policies.kyverno.io/title: Add AKS spot taint
policies.kyverno.io/category: AKS
policies.kyverno.io/subject: Pod
kyverno.io/kubernetes-version: "1.12"
spec:
@toredash
toredash / aks-spot-preferrence.yaml
Last active October 3, 2024 11:11
Kyverno mutating policy to add AKS Spot preference to Pod Create calls
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-aks-spot-perference
annotations:
policies.kyverno.io/title: Add AKS spot preference
policies.kyverno.io/category: AKS
policies.kyverno.io/subject: Pod
kyverno.io/kubernetes-version: "1.12"
spec:
@toredash
toredash / gist:2fba2cab676e1e43e5a0ff18af7cb3ef
Created November 10, 2023 13:48
add-upstream-addr-nginx
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-add-headers
data:
x-upstream-addr: $upstream_addr
---
values.yaml:
@toredash
toredash / update-eks-node-groups.py
Created August 15, 2023 10:31
python script to update eks node groups based on internal naming conventions
import boto3
import os
import re
import holidays
from dateutil.easter import *
from datetime import datetime, timedelta
def should_run_code(date):
norway_holidays = holidays.Norway()
controller:
config:
keep-alive: "620" # https://cloud.google.com/load-balancing/docs/https#timeouts_and_retries
use-forwarded-headers: "true" # passes the incoming X-Forwarded-* headers to upstreams.
proxy-real-ip-cidr: "35.191.0.0/16,130.211.0.0/22,<HTTPS_LB_IP>/32" # Trusted IPs that provides correct X-Forwarded-For headers
service:
clusterIP: "-"
enableHttps: false # We don't terminate SSL between the LB and nginx-controller
type: "ClusterIP"
@toredash
toredash / gist:5661622624bcdbf625d0d2942f1eece0
Created June 3, 2021 06:05
Example on how to print all headers in nginx/openresty with nginx-ingress
-- file should be in /etc/nginx/lua/plugins/headers/main.lua
-- enable via ConfigMap => 'plugins: "headers"'
local ngx = ngx
local split = require("util.split")
local _M = {}
function _M.rewrite()
local h = ngx.req.get_headers()
for k, v in pairs(h) do