Skip to content

Instantly share code, notes, and snippets.

View x893675's full-sized avatar
:octocat:
🐳 ☸️

Hanamichi x893675

:octocat:
🐳 ☸️
View GitHub Profile
@x893675
x893675 / main.go
Last active April 23, 2023 09:37
use client-go emulate kubectl apply
package main
import (
"bufio"
"bytes"
"context"
"encoding/json"
"github.com/pkg/errors"
"io"
"k8s.io/apimachinery/pkg/api/meta"
@x893675
x893675 / main.go
Last active December 26, 2022 03:11
create random string
package main
import (
"fmt"
"math/rand"
"strings"
"time"
"unsafe"
)
@x893675
x893675 / clientset.go
Created March 24, 2022 09:07
use client-go to proxy request to in cluster svc
package main
import (
"context"
"fmt"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"github.com/kubeclipper/kubeclipper/pkg/utils/cmdutil"
@x893675
x893675 / color_print.go
Created December 6, 2021 01:22
color print in console
package main
import "fmt"
/*
// 前景 背景 颜色
// ---------------------------------------
// 30 40 黑色
// 31 41 红色
// 32 42 绿色
@x893675
x893675 / main.go
Created February 21, 2021 05:52
timer and ticker
package main
import (
"fmt"
"sync"
"time"
)
/**
*ticker只要定义完成,从此刻开始计时,不需要任何其他的操作,每隔固定时间都会触发。
package main
import (
"fmt"
"math"
"sync"
)
func echo(nums []int) <-chan int {
out := make(chan int)
@x893675
x893675 / main.go
Created January 17, 2021 06:43
map / reduce / filter
package main
import (
"fmt"
"reflect"
)
func Transform(slice, function interface{}) interface{} {
return transform(slice, function, false)
}
@x893675
x893675 / etcd-deploy.sh
Last active January 10, 2021 09:36
etcd cluster deploy scripts
#!/bin/bash
CERTS=$PWD/cert
ETCD_IMAGE=k8s.gcr.io/etcd:3.4.3-0
NODE1=(node1 192.168.234.130:2379 192.168.234.130:2380 127.0.0.1:2381)
NODE2=(node2 192.168.234.130:3379 192.168.234.130:3380 127.0.0.1:3381 node2=https://192.168.234.130:3380,node1=https://192.168.234.130:2380)
NODE3=(node3 192.168.234.130:4379 192.168.234.130:4380 127.0.0.1:4381 node3=https://192.168.234.130:4380,node2=https://192.168.234.130:3380,node1=https://192.168.234.130:2380)
@x893675
x893675 / main.go
Created November 26, 2020 02:10
casbin,watcher,adapter
package main
import (
"bufio"
"fmt"
"github.com/billcobbler/casbin-redis-watcher/v2"
"github.com/casbin/casbin/v2"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/x893675/kubecaas/pkg/client/database"
"os"
@x893675
x893675 / main.go
Created October 26, 2020 07:29
generate access token
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
const (