Skip to content

Instantly share code, notes, and snippets.

☘️
O'Internets

Cory O'Daniel coryodaniel

☘️
O'Internets
Block or report user

Report or block coryodaniel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@coryodaniel
coryodaniel / weird.mock.ex
Created Jun 27, 2019
Per process / test mock
View weird.mock.ex
defmodule K8s.Mock do
@moduledoc """
A single interface to use for an environment, but allow each process to define its own module that implements behaviors to respond.
Good for tests, two tests can independently register the HTTP responses they should receive w/o having the confusing shared http_provider mock currently in k8s
"""
use GenServer
# TODO methods that the http behavior has go here, when executing should look up
# the registered module for the calling pid
View nginx.pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
@coryodaniel
coryodaniel / k8s.ex
Last active Jun 21, 2019
K8s.Controller to k8s client?
View k8s.ex
# Thinking about moving controller functionality from Bonny to K8s.
# Currently k8s is very focused around HTTP, but controllers are a common concept, so YMMV.
# This may be a piece of yarn, and end up pulling too much operator functionality.
# In that case, I'm using this for spit balling the API for Bonny v1.
# Start a new controller w/ default
K8s.Controller.start("foo.example.com/v1", :bars, mod: BarController)
K8s.Controller.start("foo.example.com/v1", :bars,
mod: BarController,
@coryodaniel
coryodaniel / thoughts.md
Created Jun 19, 2019
Thoughts about errors & logging
View thoughts.md

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 Jun 16, 2019
ExUnit Unique Test Identifier
View unique_test_id.ex
# 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
Nab some values out of a terraform state file
View state-nabber.rb
#! /usr/bin/env ruby
require "json"
resources = [
"resource.name",
# "google_service_account.my_service_account",
]
file = File.read("state.json")
@coryodaniel
coryodaniel / fail.md
Last active Mar 27, 2019
Connect to a failing kubernetes pod to inspect mounts, etc
View fail.md

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 Mar 13, 2019
GKE make me cluster admin
View gke.sh
kubectl create clusterrolebinding "cluster-admin-$(whoami)" --clusterrole=cluster-admin --user="$(gcloud config get-value core/account)"
@coryodaniel
coryodaniel / jsonpath.sh
Created Mar 12, 2019
Escaping dot/period in jsonpath
View jsonpath.sh
kubectl get secrets ${secret_name} -o "jsonpath={.data['ca\.crt']}" | base64 -D
@coryodaniel
coryodaniel / job.yaml
Created Mar 8, 2019
cluster bootstrap job
View job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: bootstrapper
spec:
template:
metadata:
name: bootstrapper
spec:
containers:
You can’t perform that action at this time.