Documentation
¶
Overview ¶
Package cliutil collects boilerplate shared across cobra commands in cmd/. Each helper here is deliberately small and orthogonal so that RunE bodies can focus on command-specific orchestration rather than plumbing.
Index ¶
- func AtomicWriteFile(path string, data []byte, perm os.FileMode) (retErr error)
- func CheckMinimumSupportedVersion(tazuna *v1.Tazuna, current string) error
- func Environment(cmd *cobra.Command) string
- func LoadTazunaYAML(path, environment string) (*v1.Tazuna, error)
- func NewK8sClient() (client.Client, error)
- func NewLogger(cmd *cobra.Command) (*slog.Logger, error)
- func ParseLogLevel(s string) slog.Level
- func ResolveContextMatches(spec v1.TazunaSpec, environment string) ([]string, v1.ContextMatchMode, error)
- func SetCurrentVersion(v string)
- func SetupTracer(ctx context.Context, endpoint string, insecure bool) (trace.TracerProvider, func(context.Context) error, error)
- func SetupTracerFromCmd(ctx context.Context, cmd *cobra.Command) (trace.TracerProvider, func(context.Context) error, error)
- func ShutdownTracerWithWarn(shutdown func(context.Context) error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFile ¶ added in v0.4.1
AtomicWriteFile はtemp file + renameでファイルをアトミックに書き込みます。 書き込み途中でプロセスが落ちても元ファイルが破損しないことを保証します。
func CheckMinimumSupportedVersion ¶ added in v0.2.0
CheckMinimumSupportedVersion は spec.minimumSupportedTazunaVersion と実行中の tazuna バージョン current を比較します。current が制約を満たさない場合はエラーを 返します。
- minimumSupportedTazunaVersion が未指定なら制約なしとして nil を返します。
- minimumSupportedTazunaVersion が semver として不正なら設定エラーを返します。
- current が semver としてパースできない場合("dev" などのローカルビルド)は 比較をスキップして nil を返します。これによりローカル開発がブロックされません。
func Environment ¶ added in v0.4.0
Environment は永続フラグ -e/--environment の値を読み取ります。フラグが未登録の サブコマンドでは空文字列を返します。
func LoadTazunaYAML ¶
LoadTazunaYAML reads path, renders it as a Go template, and decodes it as a v1.Tazuna document.
environment は -e/--environment フラグの値で、テンプレート内の {{ .Environment }} に注入されます。フラグが渡されていない場合は空文字列を渡してください。
func NewK8sClient ¶
NewK8sClient builds a controller-runtime client from the ambient kubeconfig.
func NewLogger ¶
NewLogger reads the persistent --log-level flag and returns a slog.Logger that writes to stderr.
func ParseLogLevel ¶
ParseLogLevel maps the textual log level used by Tazuna's --log-level flag to a slog.Level. Unknown values fall back to slog.LevelInfo.
func ResolveContextMatches ¶ added in v0.4.0
func ResolveContextMatches(spec v1.TazunaSpec, environment string) ([]string, v1.ContextMatchMode, error)
ResolveContextMatches は environment に応じて有効な context_matches パターンと 評価モードを返します。
- environment が空文字列の場合、ルート直下の spec.context_matches / spec.context_match_mode をそのまま返します。
- environment が指定された場合、spec.environments[environment] の値を使います。 該当する環境が宣言されていなければエラーになります。環境の context_match_mode が 空なら、ルート直下の context_match_mode を継承します。
func SetCurrentVersion ¶ added in v0.2.0
func SetCurrentVersion(v string)
SetCurrentVersion は実行中の tazuna のバージョンを記録します。 cmd.SetVersionInfo から呼ばれることを想定しています。
func SetupTracer ¶ added in v0.2.0
func SetupTracer(ctx context.Context, endpoint string, insecure bool) (trace.TracerProvider, func(context.Context) error, error)
SetupTracer initializes an OpenTelemetry TracerProvider for tazuna.
When endpoint is empty, a no-op TracerProvider is returned and shutdown is a no-op. This keeps span-instrumented code paths usable in tests and in normal CLI runs without any external dependency.
When endpoint is non-empty, an OTLP/gRPC exporter is wired into a SDK TracerProvider tagged with the "tazuna" service name. The returned shutdown function must be deferred at the top of each cobra RunE so that pending spans are flushed before the CLI exits.
The returned TracerProvider is also installed as the process-global provider via otel.SetTracerProvider so that callers using otel.Tracer(...) pick it up automatically.
func SetupTracerFromCmd ¶ added in v0.2.0
func SetupTracerFromCmd(ctx context.Context, cmd *cobra.Command) (trace.TracerProvider, func(context.Context) error, error)
SetupTracerFromCmd reads the persistent --otlp-endpoint and --otlp-insecure flags from cmd and calls SetupTracer. It is a thin convenience wrapper to keep RunE bodies free of flag plumbing.
func ShutdownTracerWithWarn ¶ added in v0.4.1
ShutdownTracerWithWarn は shutdown を実行し、失敗した場合は警告ログを出す。 span flush の失敗でコマンド自体を失敗させたくない defer 用途に使う (完全に無音で握り潰すと flush 失敗に気づけないため警告は残す)。
Types ¶
This section is empty.