Skip to content

Instantly share code, notes, and snippets.

@brianpursley
brianpursley / pg.yaml
Created September 30, 2024 15:10
Run Postgres in Kubernetes with a self-signed certificate (for testing purposes)
apiVersion: v1
kind: Pod
metadata:
name: pg
spec:
initContainers:
- name: generate-cert
image: postgres:16
command: ["sh", "-c", "
openssl req -x509 -nodes -newkey rsa:4096 -keyout /cert/ssl.key -out /cert/ssl.crt -days 365 -subj '/CN=example.com';
@brianpursley
brianpursley / assembly_version.sh
Created April 16, 2024 17:34
Script that prints the version of a .NET assembly
#!/bin/sh
command -v dotnet >/dev/null 2>&1 || { echo >&2 "dotnet is not installed. Please install it and try again."; exit 1; }
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_dll>"
exit 1
fi
temp_dir=$(mktemp -d)
@brianpursley
brianpursley / cgroup-resources.sh
Created April 13, 2023 02:51
Get cgroup resources using crictl
sudo crictl inspect $(sudo crictl ps --name bar -q) | jq '.info.runtimeSpec.linux.resources'
sudo crictl inspect $(sudo crictl ps --name baz -q) | jq '.info.runtimeSpec.linux.resources'
@brianpursley
brianpursley / remove-extended-resources.sh
Last active April 13, 2023 01:11
Remove extended resources from kubernetes nodes
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakecpu"}]'
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakePTSRes"}]'
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/scheduling.k8s.io~1foo"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakecpu"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakePTSRes"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/scheduling.k8s.io~1foo"}]'
@brianpursley
brianpursley / Overview.md
Last active April 5, 2023 14:09
Incorrect limits displayed for multi-container pods

Incorrect limits displayed for multi-container pods

Summary

Pod resource limits are incorrectly calculated in kubectl describe node when all the following conditions are met:

  1. The pod has multiple containers (including init containers).
  2. At least one container specifies a resource limit.
  3. At least one container does not specify a resource limit for a resource type for which another container has specified a resource limit.
@brianpursley
brianpursley / openapi-bad.json
Last active January 19, 2023 01:39
OpenAPI for testing
{
"definitions": {
"org.apache.camel.v1.Integration": {
"description": "Integration is the Schema for the integrations API",
"properties": {
"spec": {
"description": "the desired Integration specification",
"properties": {
"template": {
"description": "Pod template customization",
@brianpursley
brianpursley / sorting-networks-chat-gpt.md
Created December 26, 2022 16:16
Trying to teach Chat GPT to generate sorting networks

Brian Pursley

A sorting network can be represented as a comma-separated list of comparators. A comparator, which compares and swaps two inputs to ensure they are in sorted order, can be represented using the string "a:b", where "a" is the index of the first input, and "b" is the index of the second input. Index numbering starts at 0. Using this notation, create a sorting network that is able to sort three inputs.


Chat GPT

Here is a sorting network that can sort three inputs:

"0:1, 1:2"

This sorting network consists of two comparators. The first comparator compares the first and second inputs, and swaps them if they are out of order. The second comparator compares the second and third inputs, and swaps them if they are out of order. This sorting network is able to sort the three inputs because it will ensure that the first input is the smallest, the second input is the second smallest, and the third input is the largest.

@brianpursley
brianpursley / ServiceCollectionExtensions.cs
Created October 11, 2022 19:04
Use different SignUpSignIn Azure AD B2C policies, depending on the hostname, allowing you to provide SSO for specific companies, without having to provide a button for each SSO integration on the main login page
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
namespace AuthTest.Extensions;
public static class ServiceCollectionExtensions
{
// USAGE:
//
// 1. Add the following line in Program.cs, after your call to AddMicrosoftIdentityWebApp:
// builder.Services.AddAlternateSignUpSignInPolicies(builder.Configuration.GetSection("AzureAdB2C"));
@brianpursley
brianpursley / postgres.sh
Created August 14, 2022 22:38
Script to start a postgres pod, forward port 5432 locally, and cleanup on exit
#!/bin/sh
kubectl run postgres --image=postgres --env=POSTGRES_PASSWORD=hunter2
kubectl wait --for=condition=Ready pod/postgres
cleanup() {
echo
kubectl delete pod postgres --now
}
@brianpursley
brianpursley / nginx.sh
Created June 24, 2022 20:42
Nginx pod with readiness probe using path that is 302 redirected to another path
kubectl create ns nginx-test
kubectl apply --namespace nginx-test -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
default.conf: |
server {