ksblob

package module
v0.0.0-...-c899cac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 17 Imported by: 1

README

ksblob

Build Status Go Reference

Blob storage based on Kubernetes Secrets, support automatic slicing and atomic update

基于 Kubernetes Secret 的 Blob 存储,支持自动分片,和原子更新

Usage / 使用方法

package main

import (
	"context"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
	"go.guoyk.net/ksblob"
)

func main() {
	var client *kubernetes.Clientset
	//... init kubernetes client
	blob := ksblob.New(ksblob.Options{
		Client:    client,
		Name:      "ksblob-test",
		Namespace: "default",
		ChunkSize: 128,
	})
	_ = blob.Save(context.Background(), []byte("hello,world"))

	buf, _ := blob.Load(context.Background())
}

Credits / 许可证

Guo Y.K., MIT License

Donation / 赞助

e-CNY (数字人民币钱包)

0051266031786184

Documentation

Index

Constants

View Source
const (
	LabelKeyManagedBy = "app.kubernetes.io/managed-by"
	LabelValManagedBy = "ksblob"
	LabelKeyComponent = "app.kubernetes.io/component"
	LabelValComponent = "chunk"
	LabelKeyName      = "ksblob.guoyk.net/name"
	LabelKeyRevision  = "ksblob.guoyk.net/revision"

	KeyName     = "name"
	KeyRevision = "revision"
	KeyChunks   = "chunks"
	KeyChecksum = "checksum"

	KeyData = "data"
)
View Source
const (
	DefaultChunkSize = 4096
)

Variables

View Source
var (
	ErrNotFound         = errors.New("not found")
	ErrChecksumMismatch = errors.New("checksum mismatch")

	ErrInvalidHeaderFieldName     = errors.New("missing or invalid field in header secret: 'name'")
	ErrInvalidHeaderFieldChecksum = errors.New("missing or invalid field in header secret: 'checksum'")
	ErrInvalidHeaderFieldRevision = errors.New("missing or invalid field in header secret: 'revision'")
	ErrInvalidHeaderFieldChunks   = errors.New("missing or invalid field in header secret: 'chunks'")
)

Functions

This section is empty.

Types

type Blob

type Blob struct {
	// contains filtered or unexported fields
}

func New

func New(opts Options) *Blob

New create a Blob / 创建一个 Blob

func (*Blob) Delete

func (bl *Blob) Delete(ctx context.Context) (err error)

func (*Blob) Load

func (bl *Blob) Load(ctx context.Context) (buf []byte, err error)

Load load all data from kubernetes secrets / 从 Kubernetes Secret 载入全部数据

func (*Blob) Save

func (bl *Blob) Save(ctx context.Context, buf []byte) (err error)

Save save data to kubernetes secrets / 把数据保存到 Kubernetes Secret

type Options

type Options struct {
	// Client kubernetes client / kubernetes 客户端
	Client *kubernetes.Clientset
	// Name Blob name, use as Secret name / Blob 名称,同时会用作 Secret 名
	Name string
	// Namespace kubernetes namespace / kubernetes 命名空间
	Namespace string
	// ChunkSize maximum size of each chunk / 最大分片大小
	ChunkSize int
}

Options options to create Blob / 创建 Blob 所需要的参数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL