Skip to content

Instantly share code, notes, and snippets.

View yohanb's full-sized avatar

Yohan Belval yohanb

View GitHub Profile
@yohanb
yohanb / get_istio_workloads.sh
Created January 22, 2024 19:49
gets workloads that have istio proxy sidecar
#!/bin/bash
# 1. get all pod containers with istio proxy sidecars
# 2. get pod app labels (some have app, others have app.kubernetes.io/name)
# 3. return only uniques and not nulls
version=1.19.0
kubectl get pods -A -o json | \
jq "[.items[] | select(.spec.containers[].image | contains(\"istio/proxyv2:$version\"))]" | \
jq '[.[].metadata.labels.app, .[].metadata.labels."app.kubernetes.io/name"]' | \
jq 'unique | .[] | select( . != null)'
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
@yohanb
yohanb / InstrumentedStashReceiveActor.cs
Created November 18, 2020 19:01
Instrumented stash receive actor
/// <summary>
/// ReceiveActor with unbounded stash implementation that sends stash depth metrics with AppMetrics.
/// Use when you wish to monitor the stash depth with reporting tools such as DataDog.
/// </summary>
public abstract class InstrumentedStashReceiveActor : ReceiveActor, IWithUnboundedStash
{
private int _stashSize = 0;
private static readonly GaugeOptions GaugeOptions = new GaugeOptions
{
@yohanb
yohanb / snapshot-cli.sh
Created November 5, 2020 16:11
Azure disk snapshot tool cli
dotnet tool install --global dotnet-az-snapshot-tool
az-snapshot-tool create --tenantId xxx --subscriptionId xxx --resourceGroup myRg --diskName myDisk
@yohanb
yohanb / cronjob.yaml
Created November 5, 2020 16:06
Kubernetes CronJob for scheduled disk snapshot
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: snapshot-job
spec:
schedule: "@daily"
jobTemplate:
spec:
template:
spec:
@yohanb
yohanb / compute-family-policy.ts
Created March 4, 2020 21:18
Pulumi policy validation to advise usage of certain compute families.
import { ResourceValidationPolicy, ResourceValidationArgs } from "@pulumi/policy";
const advisedComputeFamilies = [
"Standard_DS?\d{1,2}_v2",
"Standard_DS?\d{1,2}_v3"];
const escapeRegex = (expression: string): string => expression.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const isAzureVirtualMachineResource = (args: ResourceValidationArgs): boolean => args.type.startsWith("azure:compute/virtualMachine");
@yohanb
yohanb / tag-policy.ts
Created March 4, 2020 20:59
Pulumi policy as code for Azure resource tagging.
import { ResourceValidationPolicy, ResourceValidationArgs } from "@pulumi/policy";
const requiredTags = ["owner", "environment"];
const isAzureResource = (args: ResourceValidationArgs): boolean => args.type.startsWith("azure");
// Subject to change since more types will fall through
const isAzureResourceTagFriendly = (args: ResourceValidationArgs): boolean => {
return (
!args.type.startsWith("azure:network/subnet") &&
locals {
org = "acme"
prj = "rockets"
env = "staging"
location = "eastus"
}
resource "random_string" "suffix" {
length = 13
upper = false
@yohanb
yohanb / simple_rg_naming.tf
Last active October 24, 2019 17:28
Simple example of resource group naming.
locals {
org = "acme"
prj = "rockets"
env = "staging"
suffix = "01234"
}
resource "azurerm_resource_group" "example" {
name = # Value on next line for readability
regex("^[-\\w\\._\\(\\)]+$",substr("rg-${local.org}-${local.prj}-${local.env}-main-${local.suffix}", 90))