runner

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: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasAnyDependsOn added in v0.2.0

func HasAnyDependsOn(manifests []v1.Manifest) bool

HasAnyDependsOn は manifests のうち1つでも dependsOn を持つかを返す。 1つも持たない場合は後方互換のために宣言順の単線実行 (各層1 manifest) を行う。

Types

type ApplyOptions added in v0.2.0

type ApplyOptions struct {
	Sync   bool
	Prune  bool
	Atomic bool
}

ApplyOptions は apply の挙動を切り替えるオプション群。

Sync が true のとき、state を参照した差分適用モードになる。state を読んで Build() 出力との diff を取り、追加/変更のみを CreateOrUpdate する。差分ゼロのリソースは スキップする。

Prune が true のとき、removed (state にあるが manifest に無い) リソースを Delete する。Sync が前提で、単独で指定された場合は呼び出し側でエラーにすること。

Atomic が true のとき、Sync 時の state 保存を全 manifest 処理完了後にまとめて行う。

type DriftEntry added in v0.2.0

type DriftEntry struct {
	Key        string    // ステートキー文字列
	DriftType  DriftType // drift の種類
	StoredHash string    // 保存されていたハッシュ
	LiveHash   string    // ライブ取得時のハッシュ (Missing なら空)
}

DriftEntry は個別リソースの drift 情報を表す

type DriftType added in v0.2.0

type DriftType string

DriftType はライブクラスタとステートの間で検出された差分の種類を表す

const (
	// DriftTypeDrifted は保存ハッシュとライブから再計算したハッシュが一致しない状態を表す
	DriftTypeDrifted DriftType = "live-drifted"
	// DriftTypeMissing は保存ステートに存在するリソースがライブクラスタ上で見つからない状態を表す
	DriftTypeMissing DriftType = "live-missing"
)

type Layer added in v0.2.0

type Layer []v1.Manifest

Layer は同時並列実行可能なマニフェストのグループ (依存深度ごと)。 同一層に属するマニフェストは互いに依存していないため並列適用できる。

func ResolveDependencyOrder added in v0.2.0

func ResolveDependencyOrder(manifests []v1.Manifest) ([]Layer, error)

ResolveDependencyOrder は manifests を dependsOn に基づいてトポロジカルソートし、 層ごとに並列実行可能な配列を返す。各層内のマニフェストは元の宣言順を保持する。

後方互換のため、dependsOn が 1 つも使われていなければ宣言順 1 manifest = 1 層と なるよう各 manifest を独立した層に分割する (= 従来の順次実行と同じ挙動)。

1 つでも dependsOn が使われていれば DAG モードに切り替わり、Kahn's algorithm に よるトポロジカルソートを行う。依存深度ごとに層が形成されるため、同一層に複数 manifest が存在する場合は並列適用が可能になる。

エラー:

  • dependsOn が存在しない manifest 名を参照した場合
  • 自分自身を dependsOn に含めた場合
  • 循環依存が検出された場合

type ResourceStatus added in v0.2.0

type ResourceStatus string

ResourceStatus は status コマンドが扱う managed リソースの判定結果。

const (
	// ResourceStatusReady は対象リソースがクラスタ上に存在し、Ready 判定された状態を表す。
	ResourceStatusReady ResourceStatus = "Ready"
	// ResourceStatusNotReady は対象リソースがクラスタ上に存在するが、Ready 判定されなかった状態を表す。
	ResourceStatusNotReady ResourceStatus = "NotReady"
	// ResourceStatusMissing は state には記録されているが、クラスタ上に存在しない状態を表す。
	ResourceStatusMissing ResourceStatus = "Missing"
	// ResourceStatusError は live 取得時に NotFound 以外のエラーが発生したことを表す。
	ResourceStatusError ResourceStatus = "Error"
)

type RunnerOption

type RunnerOption func(*TazunaRunner)

func WithApplyOptions added in v0.2.0

func WithApplyOptions(opts ApplyOptions) RunnerOption

WithApplyOptions は apply の挙動オプション (--sync / --prune / --atomic) を設定します。 既存呼び出しを壊さないため、未指定時はゼロ値 (= 従来挙動) のままになります。

func WithEnvironment added in v0.4.0

func WithEnvironment(environment string) RunnerOption

WithEnvironment は -e/--environment フラグの値を設定します。include ファイルを Go template として描画する際の {{ .Environment }} に注入されます。未指定時は 空文字列のままで、従来どおり include ファイルはそのまま解釈されます。

func WithManagersOverride added in v0.2.0

func WithManagersOverride(managers map[string]manager.Manager) RunnerOption

WithManagersOverride はテスト用にマネージャーマップを差し替えるオプションです。 本番コードからは使わない想定で、依存関係や並列実行の挙動を fake manager で 検証するためのフックを提供します。

func WithORASPullOptions

func WithORASPullOptions(opts orasmanager.PullOptions) RunnerOption

WithORASPullOptions は ORAS manager に渡す PullOptions を設定します。 CLI フラグ (--no-cache / --offline) からの値を伝搬するために使います。

func WithTags

func WithTags(tags []string) RunnerOption

type SecretToGenesisSecretOptions added in v0.4.1

type SecretToGenesisSecretOptions struct {
	// LabelSelector は対象 Secret を絞り込むラベルセレクタ (key1=value1,key2=value2)。
	// 空文字なら絞り込まない。
	LabelSelector string
	// NameRegex は対象 Secret 名を絞り込む正規表現。空文字なら絞り込まない。
	NameRegex string
	// Vault は保存先の 1Password vault 名。
	Vault string
	// Namespace は Secret を列挙する Kubernetes namespace。空文字なら全 namespace。
	Namespace string
	// DryRun が true のとき、1Password への保存とファイル書き出しを行わない。
	DryRun bool
	// DumpDir は生成した GenesisSecret YAML の出力先ディレクトリ。
	DumpDir string
	// Note は 1Password item に付与するメモ。
	Note string
	// OpHost は GenesisSecret の uri に使う 1Password ホスト名。
	OpHost string
}

SecretToGenesisSecretOptions は SecretToGenesisSecret の挙動を制御するオプション群。 CLI フラグのパースは cmd 層で行い、この構造体に詰めて渡す。

type TazunaRunner

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

TazunaRunner はTazuna操作を管理するオーバーオールな構造体 これを用意し、各コマンドからはこの構造体を通して操作することで、 Tazunaのロジックをそれぞれ拡張してビルドし、利用できるようにします

func NewTazunaRunner

func NewTazunaRunner(
	logger *slog.Logger,
	k8sClient client.Client,
	opClient op.Client,
	opts ...RunnerOption) *TazunaRunner

func (*TazunaRunner) Apply

func (t *TazunaRunner) Apply(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
) (retErr error)

func (*TazunaRunner) ApplyManifest

func (t *TazunaRunner) ApplyManifest(
	ctx context.Context,
	m v1.Manifest,
	managers map[string]manager.Manager,
	testPlugins map[string]testplugin.Plugin,
	store state.StateStore,
	gitCommit string,
) error

func (*TazunaRunner) ApplyToCluster

func (t *TazunaRunner) ApplyToCluster(
	ctx context.Context,
	tazuna v1.Tazuna,
) (retErr error)

func (*TazunaRunner) Build

func (t *TazunaRunner) Build(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
) (string, error)

func (*TazunaRunner) Check

func (t *TazunaRunner) Check(ctx context.Context, tazuna *v1.Tazuna, tazunaYAMLPath string) error

Check はtazuna.yamlのバリデーションを行う。 include展開後の全manifest間でnameのバリデーションを実行する。

func (*TazunaRunner) CheckAndFix

func (t *TazunaRunner) CheckAndFix(ctx context.Context, tazuna *v1.Tazuna, tazunaYAMLPath string) error

CheckAndFix はname未設定のmanifestに自動的に名前を付与し、バリデーションを実行する。 name付与はinclude展開前のtazuna構造体に対してのみ行われる(呼び出し元が この構造体をファイルへ書き戻すため、展開結果で破壊しない)。 バリデーションはdeep copyに対してinclude展開を行ったうえで実行する。

func (*TazunaRunner) ConvertManifestPathFromCwd

func (t *TazunaRunner) ConvertManifestPathFromCwd(baseDir string, tazuna *v1.Tazuna)

ConvertManifestPathFromCwd は tazuna.yaml からの相対パスを cwd 起点のパスに 書き換えます。呼び出し元の Manifests スライスを破壊しないよう、専用の バッキング配列にコピーしてから書き換えます。Apply 等が Tazuna を値で受け取って いてもスライスヘッダはバッキング配列を共有するため、コピーしないと同じ Tazuna を二度渡すと baseDir が二重に prefix される問題が起きます。

func (*TazunaRunner) Destroy

func (t *TazunaRunner) Destroy(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
) error

func (*TazunaRunner) DestroyResourcesOnCluster

func (t *TazunaRunner) DestroyResourcesOnCluster(
	ctx context.Context,
	tazuna v1.Tazuna,
) error

func (*TazunaRunner) ListTags

func (t *TazunaRunner) ListTags(ctx context.Context, tazuna *v1.Tazuna, tazunaYAMLPath string) (map[string][]string, error)

func (*TazunaRunner) Plan added in v0.2.0

func (t *TazunaRunner) Plan(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
	w io.Writer,
) (retErr error)

Plan は server-side dry-run のスローガン下で、tazuna.yaml で宣言された manifest を Build() でレンダリングし、ライブクラスタとフィールド単位で比較した結果を出力する。

実装は client-side diff である:

  • fake client が server-side apply (client.Patch + client.Apply + client.DryRunAll) を完全にはサポートしておらず、integration test が成立しないため
  • util/diff.Diff を使った unified diff で「どのフィールドが変わるか」を可視化する

後ろ向きの正確性 (admission webhook や defaulting の結果は反映されない) を犠牲に、 integration test 可能なロジックを優先している。

func (*TazunaRunner) SecretToGenesisSecret

func (t *TazunaRunner) SecretToGenesisSecret(
	ctx context.Context,
	opts SecretToGenesisSecretOptions,
	w io.Writer,
) error

SecretToGenesisSecret は、KubernetesのSecretを1Passwordに保存し、 対応するGenesisSecretのYAMLを生成する。 dry-run 時の出力は w に書き出される。

func (*TazunaRunner) StateDiff

func (t *TazunaRunner) StateDiff(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
	w io.Writer,
) (retErr error)

StateDiff は各managerのBuild()で生成したマニフェストとステートを比較し、差分を出力する

func (*TazunaRunner) StateDrift added in v0.2.0

func (t *TazunaRunner) StateDrift(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
	w io.Writer,
) (retErr error)

StateDrift は保存ステートとライブクラスタを比較し、手動変更や削除を検知して出力する

func (*TazunaRunner) StateList

func (t *TazunaRunner) StateList(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
	w io.Writer,
) error

StateList はクラスタ上のステートConfigMapを読み込み、管理されているリソースを一覧表示する

func (*TazunaRunner) Status added in v0.2.0

func (t *TazunaRunner) Status(
	ctx context.Context,
	tazuna v1.Tazuna,
	tazunaYAMLPath string,
	w io.Writer,
) (retErr error)

Status はステートConfigMapに記録された managed リソースを走査し、 各リソースの Ready / NotReady / Missing を一覧表示する。

func (*TazunaRunner) SyncManifest added in v0.2.0

func (t *TazunaRunner) SyncManifest(
	ctx context.Context,
	m v1.Manifest,
	managers map[string]manager.Manager,
	testPlugins map[string]testplugin.Plugin,
	store state.StateStore,
	gitCommit string,
	pendingSaves map[string]*state.StateData,
	pendingSavesMu *sync.Mutex,
) error

SyncManifest は --sync モードでの manifest 適用処理。 Build() で生成したマニフェストと既存 state を比較し、差分のあるリソースのみを CreateOrUpdate する。Prune が有効ならば removed リソースを Delete する。 テストは差分の有無に関わらず実行する (旧 state sync の挙動を維持)。 Atomic が有効な場合、state 保存は pendingSaves に詰めるだけにし、 呼び出し元の ApplyToCluster で全 manifest 処理後にまとめて保存される。

Jump to

Keyboard shortcuts

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