discovery

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package discovery holds helpers shared by the deployment-discovery verbs (`krci env list`, `krci env get`, `krci project deployments`): DNS-1123 validation, output-format dispatch, JSON envelope rendering, and shared error promotion. Placed under `pkg/cmd/internal/` so Go enforces package visibility: only packages below `pkg/cmd/...` may import it.

Index

Constants

View Source
const MaxIngressHostLen = 50

MaxIngressHostLen caps the visible width of an ingress hostname in table mode (mirrors the pipelinerun-list approach of truncating long names). The OSC 8 hyperlink target carries the full URL regardless.

View Source
const SchemaVersion = "1"

SchemaVersion is the shared JSON envelope version for every deployment- discovery verb. Bump only when the envelope shape changes in a way scripting consumers must detect.

View Source
const ShortDigestLen = 15

ShortDigestLen is the maximum length of an image digest as shown in table mode: `sha256:` (7 chars) + first 8 hex chars = 15 visible characters.

Variables

This section is empty.

Functions

func ColorForArgoStatus

func ColorForArgoStatus(s string) string

ColorForArgoStatus renders an ArgoCD health-status string with a TTY color. healthy → green, degraded/missing → red, progressing → blue (matching the running-pipeline color in `output.PipelineStatusColor`). Anything else (including suspended/unknown) passes through unstyled.

func ExpandIngressRows

func ExpandIngressRows(cells []string, ingressLines []string) [][]string

ExpandIngressRows turns one logical row (cells without INGRESS) plus a list of ingress lines into N visual rows. The first visual row carries the full data; subsequent rows blank out every cell except INGRESS, producing a vertically-stacked layout:

project1   …    ingress1
                ingress2
project2   …    ingress1

When ingressLines is empty, a single row is emitted with "-" in INGRESS.

func HandleError

func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error

HandleError promotes portal.ErrUnauthorized to the shared "run krci auth login" message and — when `-o json` is selected — also writes the `{schemaVersion, error: { message }}` envelope to stdout so scripting consumers get a structured error alongside the exit-1 signal.

func HostnameFromURL

func HostnameFromURL(u string) string

HostnameFromURL strips the scheme + path from a URL, returning just the host. Falls back to the original string if no scheme separator is present.

func IngressLines

func IngressLines(urls []string, isTTY bool) []string

IngressLines renders an ingress-URL slice as one cell per URL. Each line is the hostname (no scheme), truncated to MaxIngressHostLen visible characters and wrapped in an OSC 8 hyperlink (full URL preserved as the link target) when isTTY. Returns nil when urls is empty; callers display a single "-" row in that case.

func OptCell

func OptCell(s *string) string

OptCell renders an optional string field as the dereferenced value, or "-" when the pointer is nil or the value is empty.

func OptStatusCell

func OptStatusCell(s *string, isTTY bool) string

OptStatusCell renders an ArgoCD health-status cell with optional TTY color. "-" when the pointer is nil or the value is empty.

func PrintTable

func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]string) error

PrintTable is the shared TTY/non-TTY dispatcher.

func Render

func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, renderTable TableRenderer) error

Render dispatches on the `-o` flag: emit `{schemaVersion, data}` envelope for `-o json`, invoke the supplied TableRenderer for `-o table` (default), or return a validation error.

func ShortDigestCell

func ShortDigestCell(digest *string) string

ShortDigestCell shortens a sha256 digest for table display: keeps the `sha256:` prefix plus the first 8 hex chars (ShortDigestLen visible chars). Returns "-" when the pointer is nil or the value is empty.

func ValidateCluster

func ValidateCluster(cluster string) error

ValidateCluster rejects values that fail DNS-1123 label validation when the `--cluster` flag is supplied with a non-empty value. Empty is allowed since the flag is optional.

func ValidateDeployment

func ValidateDeployment(deployment string) error

ValidateDeployment rejects values that fail DNS-1123 label validation. Used by both the positional `<deployment>` (env get) and the `--deployment` flag value (env list).

func ValidateEnv

func ValidateEnv(env string) error

ValidateEnv rejects values that fail DNS-1123 label validation. <env> maps to Stage.spec.name (a short user-facing identifier like "dev", "stage", "prod").

func ValidateOutputFormat

func ValidateOutputFormat(format string) error

ValidateOutputFormat rejects `-o` values other than "", "table", or "json".

func ValidateProject

func ValidateProject(project string) error

ValidateProject rejects project names that fail DNS-1123 label validation. Used by `krci project deployments <project>`.

Types

type TableRenderer

type TableRenderer func(w io.Writer, isTTY bool) error

TableRenderer emits the table/text view. The callback receives the writer and the TTY state so it can apply styling or truncation conditionally.

Jump to

Keyboard shortcuts

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