Documentation
¶
Index ¶
Constants ¶
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 ¶
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.