Skip to content

Instantly share code, notes, and snippets.

View mayooot's full-sized avatar
:fishsticks:
Focusing

Harry Li mayooot

:fishsticks:
Focusing
  • Beijing
View GitHub Profile
@mayooot
mayooot / simple_saga.go
Created June 13, 2024 07:28
Simple Saga
package main
import (
"errors"
"fmt"
)
type Step func() error
type RollbackStep func() error
@mayooot
mayooot / in-pod-kubeconfig.sh
Created July 6, 2024 10:42 — forked from enriched/in-pod-kubeconfig.sh
Create kubeconfig inside pod
SERVICE_ACCOUNT_DIR="/var/run/secrets/kubernetes.io/serviceaccount"
KUBERNETES_SERVICE_SCHEME=$(case $KUBERNETES_SERVICE_PORT in 80|8080|8081) echo "http";; *) echo "https"; esac)
KUBERNETES_SERVER_URL="$KUBERNETES_SERVICE_SCHEME"://"$KUBERNETES_SERVICE_HOST":"$KUBERNETES_SERVICE_PORT"
KUBERNETES_CLUSTER_CA_FILE="$SERVICE_ACCOUNT_DIR"/ca.crt
KUBERNETES_NAMESPACE=$(cat "$SERVICE_ACCOUNT_DIR"/namespace)
KUBERNETES_USER_TOKEN=$(cat "$SERVICE_ACCOUNT_DIR"/token)
KUBERNETES_CONTEXT="inCluster"
mkdir -p "$HOME"/.kube
cat << EOF > "$HOME"/.kube/config
@mayooot
mayooot / store.go
Last active September 29, 2024 06:17
Annotated the Update function in Kubernetes Store.go to explain how version conflicts are handled.
const (
OptimisticLockErrorMsg = "the object has been modified; please apply your changes to the latest version and try again"
resourceCountPollPeriodJitter = 1.2
)
// Update performs an atomic update and set of the object. Returns the result of the update
// or an error. If the registry allows create-on-update, the create flow will be executed.
// A bool is returned along with the object and any errors, to indicate object creation.
func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
key, err := e.KeyFunc(ctx, name)
@mayooot
mayooot / main.go
Created October 29, 2024 06:44
KubeBuilder Informer Resync Interval
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software