utils

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

pkg/utils/gvk.go

pkg/utils/loadfile.go

pkg/utils/printer.go

pkg/utils/rawmap.go

Index

Constants

View Source
const (
	ColorReset     = "\033[0m"
	ColorRed       = "\033[31m"
	ColorGreen     = "\033[32m"
	ColorYellow    = "\033[33m"
	ColorBlue      = "\033[34m"
	ColorMagenta   = "\033[35m"
	ColorCyan      = "\033[36m"
	ColorBold      = "\033[1m"
	ColorDim       = "\033[2m"
	ColorItalic    = "\033[3m"
	ColorUnderline = "\033[4m"
	ColorBlink     = "\033[5m"
	ColorReverse   = "\033[7m"
	ColorHidden    = "\033[8m"
	ColorGray      = "\033[90m"
)

Variables

View Source
View Source
var OrkestraLogoCLI = `` /* 174-byte string literal not displayed */

Functions

func Bold added in v0.2.0

func Bold(s string) string

Bold wraps text in bold ANSI codes.

func BoolPtr

func BoolPtr(b bool) *bool

func BuildAnnotationPatch

func BuildAnnotationPatch(key, value string) map[string]interface{}

BuildAnnotationPatch constructs a JSON merge patch that sets one annotation.

func Center

func Center(text string) string

Center text to 60 columns

func Cyan added in v0.2.0

func Cyan(s string) string

Cyan wraps text in cyan ANSI codes.

func Exit

func Exit(err error)

Exit exits in error with a code

func ExtractStatus added in v0.2.0

func ExtractStatus(obj *unstructured.Unstructured) string

ExtractStatus extracts a status phase or condition from an unstructured object. Returns "Unknown" if no status is found.

func FormatDuration added in v0.2.0

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in human-readable short form. Exported so CLI commands and tests can use it directly.

func FormatYAMLError

func FormatYAMLError(err error, data []byte) string

func GVKFor

func GVKFor(obj runtime.Object, scheme *runtime.Scheme) (schema.GroupVersionKind, error)

func HealthIcon added in v0.2.0

func HealthIcon(status string) string

HealthIcon returns a coloured status icon based on a status string.

func HumanAge added in v0.2.0

func HumanAge(t metav1.Time) string

HumanAge returns a human-readable age string from a Kubernetes timestamp. Format matches kubectl: 5s, 2m, 3h, 4d, 2w

func IsRunningInCluster added in v0.1.9

func IsRunningInCluster() bool

IsRunningInCluster returns true when running inside a Kubernetes pod. The service account token is always present inside a pod.

func Jitter

func Jitter(d time.Duration) time.Duration

func LoadFile

func LoadFile(path string) ([]byte, error)

LoadFile loads a file from local disk or HTTP(S).

For remote files, auth is optional. When nil, an unauthenticated GET is performed. When set, the appropriate Authorization header is added based on auth.Type.

For local files, auth is ignored.

func LoadFileWithAuth

func LoadFileWithAuth(path string, auth *FileAuth) ([]byte, error)

LoadFileWithAuth loads a file with optional authentication. Called by the merger when a source declares an auth block.

func Merge

func Merge(target *string, incoming, sep string)

Used to merge labels

func MetaField added in v0.1.9

func MetaField(objMap map[string]interface{}, field string) string

MetaField extracts a string field from objMap["metadata"]. Returns "" when the field is absent or not a string.

func PrintError added in v0.2.0

func PrintError(msg string)

PrintError prints a red error line.

func PrintField added in v0.2.0

func PrintField(label, value string)

PrintField prints a label: value line used in describe output.

func PrintInfo added in v0.2.0

func PrintInfo(msg string)

PrintInfo prints a dim informational line.

func PrintNestedMap added in v0.2.0

func PrintNestedMap(m map[string]interface{}, indent int)

PrintNestedMap prints a nested map as indented key: value lines. Used by describe to print spec and status sections.

func PrintSection added in v0.2.0

func PrintSection(title string)

PrintSection prints a bold section header with a separator.

func PrintSuccess added in v0.2.0

func PrintSuccess(msg string)

PrintSuccess prints a green checkmark line.

func PrintTable added in v0.2.0

func PrintTable(w io.Writer, header []string, rows [][]string)

PrintTable prints a header + rows to stdout, flushed and aligned.

func PrintWarning added in v0.2.0

func PrintWarning(msg string)

PrintWarning prints a yellow warning line.

func RawToMap added in v0.1.9

func RawToMap(raw interface{}) (map[string]interface{}, error)

RawToMap converts a raw informer cache object to map[string]interface{}. Works for *unstructured.Unstructured, any typed runtime.Object, and any JSON-serializable value. No type assertion required.

Fast path: *unstructured.Unstructured already has the map — returned directly with zero allocation. General path: JSON round-trip.

func RequireStrParams

func RequireStrParams(required map[string]string) error

func Retry

func Retry(fn func() error, opts RetryOptions) error

func RetryBackoff

func RetryBackoff(fn func() error, opts RetryOptions) error

func Reversed

func Reversed[T any](s []T) []T

Reversed reverses any given slice

func SetGroupVersionKindObj

func SetGroupVersionKindObj(gvk schema.GroupVersionKind) string

func Sleep

func Sleep(n int)

func StrictUnmarshal

func StrictUnmarshal(data []byte, out any) error

func WaitForCRD

func WaitForCRD(cfg *rest.Config, group, kind, version string) error

Wait for CRD creation

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data interface{})

func WriteJSONPruned

func WriteJSONPruned(w http.ResponseWriter, status int, v interface{})

WriteJSONPruned writes a JSON response with null/empty values removed

Types

type FileAuth

type FileAuth struct {
	// Type — authentication scheme.
	// Supported: "bearer", "github", "basic"
	Type string

	// BearerToken — used when Type is "bearer" or "github".
	// Resolved from the environment variable named in the source declaration.
	BearerToken string

	// Username and Password — used when Type is "basic".
	// Each resolved from its own environment variable.
	Username string
	Password string
}

FileAuth holds optional authentication for a remote file source. Constructed from the Katalog source declaration and resolved from environment variables at load time — credentials never appear in YAML.

type GroupVersionKind

type GroupVersionKind string

Consistent Keys

func SetGroupVersionKind

func SetGroupVersionKind(group, version, kind string) GroupVersionKind

Mimicks runtime.Object.GetObjectKind().GroupVersionKind() https://pkg.go.dev/k8s.io/apimachinery@v0.35.2/pkg/runtime/schema#ObjectKind.GroupVersionKind

func (GroupVersionKind) String

func (g GroupVersionKind) String() string

type H

type H map[string]interface{}

type RetryOptions

type RetryOptions struct {
	Attempts int
	Delay    time.Duration
}

type Status

type Status string
const (
	// Status
	StatusReady   Status = "ready"
	StatusRunning Status = "running"
	StatusHealthy Status = "healthy"
	StatusOnline  Status = "online"

	StatusNotReady   Status = "not ready"
	StatusNotRunning Status = "not running"
	StatusNotHealthy Status = "not healthy"
	StatusOffline    Status = "offline"

	// HTTP
	ContentType     = "Content-Type"
	JSONContentType = "application/json"
)

type TableWriter added in v0.2.0

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

TableWriter wraps tabwriter for consistent aligned output.

func NewTableWriter added in v0.2.0

func NewTableWriter() *TableWriter

NewTableWriter returns a TableWriter writing to stdout.

func (*TableWriter) Flush added in v0.2.0

func (t *TableWriter) Flush()

Flush flushes the tabwriter buffer.

func (*TableWriter) Header added in v0.2.0

func (t *TableWriter) Header(cols ...string)

Header prints a bold header row.

func (*TableWriter) Row added in v0.2.0

func (t *TableWriter) Row(cols ...string)

Row prints one data row.

Jump to

Keyboard shortcuts

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