Skip to content

Instantly share code, notes, and snippets.

View Yapcheekian's full-sized avatar

Yap Yapcheekian

View GitHub Profile
@Yapcheekian
Yapcheekian / generic.md
Last active August 9, 2023 04:05
generic.md
type Model interface {
	comparable
	TableName() (schema, table string)
}

type Change[T Model] struct {
	New T
	Old T
}
@Yapcheekian
Yapcheekian / mutating.go
Created March 4, 2022 00:33
mutating webhook in k8s
package mutator
import (
"encoding/json"
"log"
"net/http"
admission "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@Yapcheekian
Yapcheekian / authenticate.go
Created March 4, 2022 00:16
authentication webhook is k8s
package authenticate
import (
"encoding/json"
"errors"
"log"
"net/http"
"strings"
authentication "k8s.io/api/authentication/v1beta1"
)
@Yapcheekian
Yapcheekian / authorization.go
Created March 4, 2022 00:13
k8s authorization webhook
package authorize
import (
"encoding/json"
"fmt"
"log"
"net/http"
authorization "k8s.io/api/authorization/v1beta1"
)
@Yapcheekian
Yapcheekian / validating.go
Created March 4, 2022 00:11
validating webhook
package validate
import (
"encoding/json"
"log"
"net/http"
"regexp"
admission "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@Yapcheekian
Yapcheekian / k8s.md
Last active March 4, 2022 05:53
K8s deep dive
docker run -it --rm k8s.gcr.io/kube-apiserver:v1.19.0 kube-apiserver --help

docker run -it --rm k8s.gcr.io/kube-scheduler:v1.19.0 kube-scheduler --help

Custom Scheduler

apiVersion: v1
kind: Pod
@Yapcheekian
Yapcheekian / concurrent.txt
Last active December 31, 2021 10:42
Process vs coroutines vs thread
https://stackoverflow.com/questions/3324643/processes-threads-green-threads-protothreads-fibers-coroutines-whats-the
https://stackoverflow.com/questions/46864623/which-of-coroutines-goroutines-and-kotlin-coroutines-are-faster
@Yapcheekian
Yapcheekian / slices.go
Created August 9, 2021 13:56
Notes on go slices
var arrNum [5]int // this is an array
var sliceNum []int // this is a slice
fmt.Println(arrNum) // [5]int{0,0,0,0,0} array have initial value of zero value
fmt.Println(sliceNum) // []int(nil) slice have initial value of nil value
sliceNum == nil // true
arrNum[0] = 1 // ok
sliceNum[0] = 1 // compile time error because you cannot assign values to nil
@Yapcheekian
Yapcheekian / e_net.sh
Last active August 5, 2021 00:46
capture pod packet
#!/usr/bin/env bash
# https://mp.weixin.qq.com/s?__biz=MzA4MzIwNTc4NQ==&mid=2247484821&idx=1&sn=aaa173a8b913cc759c56efe05d2c15ad&chksm=9ffb4e63a88cc7755ca720b3886946245246d8e57687cf209ad47f61a186cc290c04ef57fc91&scene=21#wechat_redirect
function e_net() {
set -eu
pod=`kubectl get pod ${pod_name} -n ${namespace} -o template --template='{{range .status.containerStatuses}}{{.containerID}}{{end}}' | sed 's/docker:\/\/\(.*\)$/\1/'`
pid=`docker inspect -f {{.State.Pid}} $pod`
echo -e "\033[32m Entering pod netns for ${namespace}/${pod_name} \033[0m\n"
cmd="nsenter -n -t ${pid}"
echo -e "\033[32m Execute the command: ${cmd} \033[0m"