hook

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the maximum time a hook is allowed to run.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	ExitCode int
	Stderr   string
	Stdout   string
	Duration time.Duration
}

Result holds the outcome of a hook execution.

func RunPostApply

func RunPostApply(ctx context.Context, command string, resourceType string, sourceFile string, resultJSON []byte) (*Result, error)

RunPostApply executes the post-apply hook command.

Invoked the same way as RunPreApply — POSIX-style tokenize, append resource type and source file as the two final args, run directly (no "sh -c"). Stdin is the apply result as JSON, so the hook can read the created/updated resource's id, name, url, etc. Stdout and stderr are both captured and returned; the caller is responsible for printing them to the user (a post-apply hook's output is always relevant, including on success).

The caller is responsible for deciding how a non-zero ExitCode maps to dtctl apply's overall result — post-apply runs after the resource is already persisted, so a hook-level failure is typically a warning.

func RunPreApply

func RunPreApply(ctx context.Context, command string, resourceType string, sourceFile string, jsonData []byte) (*Result, error)

RunPreApply executes the pre-apply hook command.

The command string is tokenized with POSIX-style shell quoting (see tokenizeCommand) and executed directly (NOT via "sh -c"). The resource type and source file are appended as the two final arguments of the process. Processed JSON is piped to stdin.

Example: command `bash /path/to/validate.sh` becomes exec.Command("bash", "/path/to/validate.sh", "<rtype>", "<sourceFile>"). Quoting is honoured, so `bash "/path with spaces/validate.sh"` works.

sourceFile is the original filename that was passed to "dtctl apply -f". It is informational only — the hook MUST read the resource content from stdin (which contains the processed JSON after YAML→JSON conversion and template rendering), not from this file path.

Returns a Result with ExitCode 0 on success. A non-zero ExitCode means the hook rejected the resource (this is not an error). An error return indicates the hook could not be executed at all (not found, timed out, etc.).

If command is empty, the hook is a no-op and returns ExitCode 0.

Jump to

Keyboard shortcuts

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