utils

package
v0.1.9 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: 20 Imported by: 0

Documentation

Overview

pkg/utils/gvk.go

pkg/utils/loadfile.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"
)

Variables

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

Functions

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 Exit

func Exit(err error)

Exit exits in error with a code

func FormatYAMLError

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

func GVKFor

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

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 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"
)

Jump to

Keyboard shortcuts

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