Skip to content

Instantly share code, notes, and snippets.

View coryodaniel's full-sized avatar
☘️
O'Internets

Cory O'Daniel coryodaniel

☘️
O'Internets
View GitHub Profile
@coryodaniel
coryodaniel / thoughts.md
Created June 19, 2019 18:11
Thoughts about errors & logging

When an error occurs in a function and there is no expectation that the caller can deal with it, returning {:error, error} feels noisy.

Is this better? It makes the assumption that the caller doesnt care. The error is logged for a human operator to see.

def get_some_pods() do
  response = Client.get_pods()
  
 case response do
@coryodaniel
coryodaniel / unique_test_id.ex
Last active June 16, 2019 16:46
ExUnit Unique Test Identifier
# I forget how to get the test "id" constantly.
defmodule FooTest do
@moduledoc false
use ExUnit.Case, async: true
test "show that ID", ctx do
IO.puts ctx[:test]
end
end
@coryodaniel
coryodaniel / state-nabber.rb
Created May 15, 2019 20:23
Nab some values out of a terraform state file
#! /usr/bin/env ruby
require "json"
resources = [
"resource.name",
# "google_service_account.my_service_account",
]
file = File.read("state.json")
@coryodaniel
coryodaniel / debug-containers.md
Last active November 7, 2023 09:09
Connect to a failing kubernetes pod to inspect mounts, etc

Update the command/args:

command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]

Run a command

kubectl exec my-pod -c my-container -- ls /
@coryodaniel
coryodaniel / gke.sh
Created March 13, 2019 17:44
GKE make me cluster admin
kubectl create clusterrolebinding "cluster-admin-$(whoami)" --clusterrole=cluster-admin --user="$(gcloud config get-value core/account)"
@coryodaniel
coryodaniel / jsonpath.sh
Created March 12, 2019 18:09
Escaping dot/period in jsonpath
kubectl get secrets ${secret_name} -o "jsonpath={.data['ca\.crt']}" | base64 -D
@coryodaniel
coryodaniel / job.yaml
Created March 8, 2019 18:33
cluster bootstrap job
apiVersion: batch/v1
kind: Job
metadata:
name: bootstrapper
spec:
template:
metadata:
name: bootstrapper
spec:
containers:

Makefile

help: ## Show this help
help:
	@grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

all: ## Clean and run terraform apply
all: clean
all:
@coryodaniel
coryodaniel / metrics.txt
Created March 6, 2019 19:08
Example Prometheus /metrics HTTP Response
# HELP node_netstat_TcpExt_OfoPruned Protocol TcpExt statistic OfoPruned.
# TYPE node_netstat_TcpExt_OfoPruned untyped
node_netstat_TcpExt_OfoPruned 0
# HELP node_netstat_TcpExt_OutOfWindowIcmps Protocol TcpExt statistic OutOfWindowIcmps.
# TYPE node_netstat_TcpExt_OutOfWindowIcmps untyped
node_netstat_TcpExt_OutOfWindowIcmps 0
# HELP node_netstat_TcpExt_PAWSActive Protocol TcpExt statistic PAWSActive.
# TYPE node_netstat_TcpExt_PAWSActive untyped
node_netstat_TcpExt_PAWSActive 0
# HELP node_netstat_TcpExt_PAWSEstab Protocol TcpExt statistic PAWSEstab.
@coryodaniel
coryodaniel / readme.md
Last active April 30, 2020 03:25
MyApp deployment operater
  • Use bonny to define a MyApp CRD and Controller
    • CRD has a few fields:
      • image
      • deployment_template
  • Define a DBMigration CRD and Controller
    • CRD has a few fields:
      • image
      • migration_template
  • The templates are ConfigMap’s
  • deployment_template is a k8s Deployment YAML manifest w/ no image set (runs ~mix run —no-halt)