Skip to content

Instantly share code, notes, and snippets.

Avatar

Yap Yapcheekian

View GitHub Profile
@Yapcheekian
Yapcheekian / mutating.go
Created Mar 4, 2022
mutating webhook in k8s
View mutating.go
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 Mar 4, 2022
authentication webhook is k8s
View authenticate.go
package authenticate
import (
"encoding/json"
"errors"
"log"
"net/http"
"strings"
authentication "k8s.io/api/authentication/v1beta1"
)
@Yapcheekian
Yapcheekian / authorization.go
Created Mar 4, 2022
k8s authorization webhook
View authorization.go
package authorize
import (
"encoding/json"
"fmt"
"log"
"net/http"
authorization "k8s.io/api/authorization/v1beta1"
)
View validating.go
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 Mar 4, 2022
K8s deep dive
View k8s.md
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 Dec 31, 2021
Process vs coroutines vs thread
View concurrent.txt
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 / gem.md
Created Aug 31, 2021
Fix when gem install mysql2 in rails failed
View gem.md
gem install mysql2 -v 0.5.3 -- \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.26/bin/mysql_config \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include \
--platform=ruby
@Yapcheekian
Yapcheekian / slices.go
Created Aug 9, 2021
Notes on go slices
View slices.go
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 Aug 5, 2021
capture pod packet
View e_net.sh
#!/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"