Skip to content

Instantly share code, notes, and snippets.

View pwittrock's full-sized avatar

Phillip Wittrock pwittrock

View GitHub Profile
@pwittrock
pwittrock / node_e2e_host_setup.sh
Last active February 23, 2016 23:46
Setup e2e node host
#!/bin/bash
# Fixup sudoers require tty
sudo grep -q "# Defaults requiretty" /etc/sudoers
if [ $? -ne 0 ] ; then
sudo sed -i 's/Defaults requiretty/# Defaults requiretty/' /etc/sudoers
fi
# Install etcd
hash etcd 2>/dev/null
@pwittrock
pwittrock / gist:bee735f6ba24ba032036
Created February 17, 2016 19:32
./hack/verify-all.sh debug
./hack/verify-all.sh
Running in the silent mode, run with -v if you want to see script logs.
Skipping ./hack/../hack/verify-all.sh
Verifying ./hack/../hack/verify-api-reference-docs.sh
SUCCESS
Verifying ./hack/../hack/verify-boilerplate.sh
SUCCESS
Verifying ./hack/../hack/verify-codecgen.sh
SUCCESS
Verifying ./hack/../hack/verify-codegen.sh
@pwittrock
pwittrock / pitfalls.md
Last active October 31, 2023 04:27
GOLANG Common Bugs
  1. for _, value := range values { go func() {somefn(value)}() } // Every go func sees that same value because the address is updated
  • Must copy variable in a for loop to new value if using in a gofn, address of variable get reused
  1. m := map[string]SomeStruct &m["k"] // Fails to compile
  • Cannot take the address of map keys/values: use a pointer when possible
  1. err := somefn() if err != nil { newvar, err := somefn() } // Does not update err in outer scope!
  • must declare var newvar string and then use newvar, err = somefn()
  1. go f1(blockingFn()) // blockingFn() not run in a go routine - equivalent to r := blockingFn() go f1(r)
  • blockingFn() is run synchronously outside a go routine, and f1 is run in a go routine with the realized argument
@pwittrock
pwittrock / pod1.yaml
Last active March 15, 2016 19:52
Pods
curl http://127.0.0.1:10255/stats/summary
curl -X "POST" -d '{"containerName":"/","num_stats":1,"subcontainers":true}' localhost:10255/stats/container
curl -X "POST" -d '{"containerName":"/","num_stats":1,"subcontainers":true}' localhost:10255/stats/container | xclip -sel clip
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Pod YAMLs:
apiVersion: v1
kind: Pod
metadata:
name: test-emptydir
spec:
containers:
- image: gcr.io/google_containers/busybox
command:
rootfs 103079200 3461828 95302104 4% /
udev 10240 0 10240 0% /dev
tmpfs 767984 312 767672 1% /run
/dev/disk/by-uuid/0f4155c3-2c08-43f0-9949-b25bb21e3561 103079200 3461828 95302104 4% /
tmpfs 5120 0 5120 0% /run/lock
tmpfs 1535960 368 1535592 1% /run/shm
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: nginx
#!/bin/bash
set -o errexit
set -o nounset
for i in ${BASH_ARGV[*]} ; do
gcloud compute disks --project kubernetes-jenkins snapshot $i --snapshot-names tmp-copy-$i
gcloud compute disks --project kubernetes-jenkins create tmp-copy-$i --source-snapshot tmp-copy-$i
gcloud compute images --project kubernetes-jenkins create $i-image --source-disk tmp-copy-$i
// Go Struct
// +x-kubernetes-get-columns="NAME:metadata.name,STATUS:status.phase"
// +x-kubernetes-describe-columns="NAME:metadata.name,STATUS:status.phase,DNS:spec.dnsPolicy"
type Pod struct {
...
}
"v1.Pod": {
"x-kubernetes-get-columns": "NAME:metadata.name,STATUS:status.phase",
"x-kubernetes-describe-columns": "NAME:metadata.name,STATUS:status.phase,DNS:spec.dnsPolicy",
wittroc-macbookpro2:sample-apiserver pwittroc$ glide install
[INFO] Lock file (glide.lock) does not exist. Performing update.
[INFO] Downloading dependencies. Please wait...
[INFO] --> Fetching updates for k8s.io/apimachinery.
[INFO] --> Fetching updates for k8s.io/apiserver.
[INFO] --> Fetching updates for github.com/spf13/cobra.
[INFO] Resolving imports
[INFO] --> Fetching updates for github.com/go-openapi/spec.
[INFO] --> Fetching updates for github.com/gogo/protobuf.
[INFO] --> Fetching updates for github.com/google/gofuzz.