state

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TazunaNamespace はステートConfigMapを格納するnamespace
	TazunaNamespace = "tazuna"
)

Variables

This section is empty.

Functions

func ComputeContentHash

func ComputeContentHash(obj *unstructured.Unstructured) (string, error)

ComputeContentHash はunstructured.UnstructuredオブジェクトからSHA-256コンテンツハッシュを算出する。 server-side付与のフィールド(resourceVersion, uid等)とstatusは除外してハッシュを計算する。

func ConfigMapName

func ConfigMapName(manifestName string) string

ConfigMapName はmanifest名からConfigMap名を生成する

func EnsureNamespace

func EnsureNamespace(ctx context.Context, c client.Client) error

EnsureNamespace はtazuna namespaceが存在することを保証する。 存在しない場合は新規作成し、既に存在する場合は何もしない。 並列applyでは複数goroutineが同時にここへ到達するため、Createの AlreadyExistsはレースの敗者として成功扱いにする。

Types

type ConfigMapStateStore

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

ConfigMapStateStore はConfigMapベースのStateStore実装

func NewConfigMapStateStore

func NewConfigMapStateStore(c client.Client) *ConfigMapStateStore

NewConfigMapStateStore はConfigMapStateStoreを生成する

func (*ConfigMapStateStore) Get

func (s *ConfigMapStateStore) Get(ctx context.Context, manifestName string) (*StateData, error)

Get はmanifest名に対応するステートをConfigMapから読み込む。 ConfigMapが存在しない場合は空のStateDataを返す。

func (*ConfigMapStateStore) Save

func (s *ConfigMapStateStore) Save(ctx context.Context, manifestName string, data *StateData) error

Save はmanifest名に対応するステートをConfigMapに保存する。 ConfigMapが存在しない場合は新規作成、存在する場合は更新する。 state ConfigMap は tazuna namespace 配下に作成されるため、書き込み前に namespace の存在を保証する (呼び出し側での ensure 忘れを防ぐ)。

type DiffEntry

type DiffEntry struct {
	Key      string   // ステートキー文字列
	DiffType DiffType // 差分の種類
	OldHash  string   // removed/modified時の旧ハッシュ
	NewHash  string   // added/modified/always-sync時の新ハッシュ
}

DiffEntry は個別リソースの差分情報を表す

func ComputeDiff

func ComputeDiff(stateData *StateData, currentEntries map[string]StateEntry, alwaysSyncKeys map[string]bool) []DiffEntry

ComputeDiff は既存ステートと現在のエントリを比較して差分を算出する。 alwaysSyncKeys に含まれるキーは always-sync として扱う。

type DiffType

type DiffType string

DiffType は差分の種類を表す

const (
	DiffTypeAdded      DiffType = "added"
	DiffTypeModified   DiffType = "modified"
	DiffTypeRemoved    DiffType = "removed"
	DiffTypeAlwaysSync DiffType = "always-sync"
)

type StateData

type StateData struct {
	Metadata StateMetadata
	Entries  map[string]StateEntry // キー: ステートキー文字列
}

StateData はmanifest単位のステート全体を表す

type StateEntry

type StateEntry struct {
	ContentHash string `json:"contentHash"`
}

StateEntry はステートに保存される個別リソースのエントリ

type StateKey

type StateKey struct {
	ManifestName string
	Group        string
	Version      string
	Kind         string
	Namespace    string // クラスタスコープリソースの場合は空文字
	Name         string
}

StateKey はステートエントリのキーを表す構造体

func NewStateKey

func NewStateKey(manifestName string, obj client.Object) StateKey

NewStateKey はK8sオブジェクトからステートキーを生成する

func ParseStateKey

func ParseStateKey(s string) (StateKey, error)

ParseStateKey は文字列からStateKeyをパースする。 namespaced (6パート): {manifest}/{group}/{version}/{kind}/{namespace}/{name} cluster-scoped (5パート): {manifest}/{group}/{version}/{kind}/{name}

func (StateKey) String

func (k StateKey) String() string

String はステートキーを文字列に変換する。 namespaced: {manifest}/{group}/{version}/{kind}/{namespace}/{name} cluster-scoped: {manifest}/{group}/{version}/{kind}/{name}

type StateMetadata

type StateMetadata struct {
	GitCommitHash string `json:"gitCommitHash"`
	LastSyncedAt  string `json:"lastSyncedAt"`
}

StateMetadata はステートConfigMapのメタデータ (_metadata キー)

type StateStore

type StateStore interface {
	// Get はmanifest名に対応するステートを取得する。
	// ConfigMapが存在しない場合は空のStateDataを返す。
	Get(ctx context.Context, manifestName string) (*StateData, error)
	// Save はmanifest名に対応するステートを保存する。
	Save(ctx context.Context, manifestName string, data *StateData) error
}

StateStore はステートの読み書きインターフェース

Jump to

Keyboard shortcuts

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