Documentation
¶
Index ¶
- Constants
- func CreateNewScheme() (*runtime.Scheme, error)
- func DefaultIfEmpty(value, defaultValue string) string
- func FormatAge(t time.Time) string
- func FormatBoolAsYesNo(b bool) string
- func FormatDuration(d time.Duration) string
- func FormatDurationShort(d time.Duration) string
- func FormatNameWithDisplayName(name, displayName string) string
- func FormatStatusWithMessage(status, reason, message string) string
- func FormatStatusWithReason(status, reason string) string
- func FormatStatusWithType(typeName, reason string) string
- func FormatValueOrPlaceholder(value string) string
- func GenerateResourceName(parts ...string) string
- func GetClient() (client.Client, error)
- func GetK8sObjectYAMLFromCRDWithLabels(group, version, kind, namespace string, labels map[string]string) (string, error)
- func GetPlaceholder() string
- func GetRESTConfig() (*rest.Config, error)
- func GetReadyStatus(conditions []metav1.Condition, ...) string
- func GetResourceStatus(conditions []metav1.Condition, priorityConditions []string, ...) string
- func GetScheme() *runtime.Scheme
- func GetStatus(conditions []metav1.Condition, defaultStatus string) string
- func GetStatusForConditionGetter(resource ConditionGetter, priorityConditions []string, defaultStatus string, ...) string
- func PrintTable(headers []string, rows [][]string) error
- type Applicable
- type BaseResource
- func (b *BaseResource[T, L]) Create(obj T) error
- func (b *BaseResource[T, L]) Delete(name string) error
- func (b *BaseResource[T, L]) Exists(name string) (bool, error)
- func (b *BaseResource[T, L]) GetClient() client.Client
- func (b *BaseResource[T, L]) GetConfig() constants.CRDConfig
- func (b *BaseResource[T, L]) GetLabels() map[string]string
- func (b *BaseResource[T, L]) GetNames() ([]string, error)
- func (b *BaseResource[T, L]) GetNamespace() string
- func (b *BaseResource[T, L]) List() ([]ResourceWrapper[T], error)
- func (b *BaseResource[T, L]) Print(format OutputFormat, filter *ResourceFilter) error
- func (b *BaseResource[T, L]) PrintItems(items []ResourceWrapper[T], format OutputFormat) error
- func (b *BaseResource[T, L]) PrintTableItems(items []ResourceWrapper[T]) error
- func (b *BaseResource[T, L]) Update(obj T) error
- func (b *BaseResource[T, L]) WithNamespace(namespace string)
- type CommonResource
- type ConditionGetter
- type OutputFormat
- type Printable
- type ResourceBase
- type ResourceBaseOption
- type ResourceFilter
- type ResourceKind
- type ResourceOperation
- type ResourceOption
- func WithClient[T client.Object, L client.ObjectList](c client.Client) ResourceOption[T, L]
- func WithConfig[T client.Object, L client.ObjectList](cfg constants.CRDConfig) ResourceOption[T, L]
- func WithLabels[T client.Object, L client.ObjectList](lbls map[string]string) ResourceOption[T, L]
- func WithNamespace[T client.Object, L client.ObjectList](ns string) ResourceOption[T, L]
- func WithScheme[T client.Object, L client.ObjectList](s *runtime.Scheme) ResourceOption[T, L]
- type ResourceWrapper
Constants ¶
const (
ErrFormatUnsupported = "unsupported output format: %s"
)
Common error messages used across resource implementations
Variables ¶
This section is empty.
Functions ¶
func CreateNewScheme ¶
CreateNewScheme creates a new runtime scheme with Choreo CRDs registered
func DefaultIfEmpty ¶
func FormatAge ¶
FormatAge returns a human-readable string representing the time since the given time
func FormatBoolAsYesNo ¶
FormatBoolAsYesNo formats a boolean as "Yes" or "No"
func FormatDuration ¶
FormatDuration formats a time.Duration into a readable string More detailed than FormatDurationShort, suitable for build durations, etc.
func FormatDurationShort ¶
FormatDurationShort formats a duration as a short, human-readable string Suitable for age display in tables
func FormatNameWithDisplayName ¶
FormatNameWithDisplayName returns a formatted name with display name in parentheses if different
func FormatStatusWithMessage ¶
FormatStatusWithMessage formats status with reason and message
func FormatStatusWithReason ¶
FormatStatusWithReason formats status with a reason in parentheses
func FormatStatusWithType ¶
FormatStatusWithType formats status with type and reason
func FormatValueOrPlaceholder ¶
FormatValueOrPlaceholder returns the value or a placeholder if empty
func GenerateResourceName ¶
func GetK8sObjectYAMLFromCRDWithLabels ¶
func GetK8sObjectYAMLFromCRDWithLabels(group, version, kind, namespace string, labels map[string]string) (string, error)
GetK8sObjectYAMLFromCRDWithLabels retrieves a K8s object matching the given parameters and returns it as YAML with runtime fields cleaned.
func GetPlaceholder ¶
func GetPlaceholder() string
GetPlaceholder returns a placeholder string (typically "-") for empty values
func GetRESTConfig ¶
GetRESTConfig returns the REST config based on current context
func GetReadyStatus ¶
func GetReadyStatus(conditions []metav1.Condition, defaultStatus, readyStatus, notReadyStatus string) string
GetReadyStatus is a specialized helper that focuses on the "Ready" condition, common across many Choreo resources
func GetResourceStatus ¶
func GetResourceStatus( conditions []metav1.Condition, priorityConditions []string, defaultStatus string, readyStatus string, notReadyStatus string, ) string
GetResourceStatus returns a human-readable status string based on the resource's conditions priorityConditions are checked in order, other conditions are considered if none of those match defaultStatus is returned if no conditions exist
func GetStatusForConditionGetter ¶
func GetStatusForConditionGetter( resource ConditionGetter, priorityConditions []string, defaultStatus string, readyStatus string, notReadyStatus string, ) string
GetStatusForConditionGetter is a convenience wrapper for resources that implement ConditionGetter
func PrintTable ¶
PrintTable prints slices of rows in tabular format.
Types ¶
type Applicable ¶ added in v0.3.0
Applicable interface for resources that support applying via API
type BaseResource ¶
type BaseResource[T client.Object, L client.ObjectList] struct { // contains filtered or unexported fields }
BaseResource implements the shared logic for resource operations.
func NewBaseResource ¶
func NewBaseResource[T client.Object, L client.ObjectList](opts ...ResourceOption[T, L]) *BaseResource[T, L]
NewBaseResource constructs a BaseResource given ResourceOption callbacks.
func (*BaseResource[T, L]) Create ¶
func (b *BaseResource[T, L]) Create(obj T) error
Create creates a K8s resource.
func (*BaseResource[T, L]) Delete ¶
func (b *BaseResource[T, L]) Delete(name string) error
Delete removes one or more matching resources by name.
func (*BaseResource[T, L]) Exists ¶
func (b *BaseResource[T, L]) Exists(name string) (bool, error)
Exists returns true if a resource with the given name exists.
func (*BaseResource[T, L]) GetClient ¶
func (b *BaseResource[T, L]) GetClient() client.Client
func (*BaseResource[T, L]) GetConfig ¶
func (b *BaseResource[T, L]) GetConfig() constants.CRDConfig
func (*BaseResource[T, L]) GetLabels ¶
func (b *BaseResource[T, L]) GetLabels() map[string]string
func (*BaseResource[T, L]) GetNames ¶
func (b *BaseResource[T, L]) GetNames() ([]string, error)
GetNames returns sorted names of resources.
func (*BaseResource[T, L]) GetNamespace ¶
func (b *BaseResource[T, L]) GetNamespace() string
func (*BaseResource[T, L]) List ¶
func (b *BaseResource[T, L]) List() ([]ResourceWrapper[T], error)
List lists objects matching namespace/labels.
func (*BaseResource[T, L]) Print ¶
func (b *BaseResource[T, L]) Print(format OutputFormat, filter *ResourceFilter) error
Print outputs resources in the specified format with optional filtering
func (*BaseResource[T, L]) PrintItems ¶
func (b *BaseResource[T, L]) PrintItems(items []ResourceWrapper[T], format OutputFormat) error
PrintItems outputs pre-filtered items in the specified format
func (*BaseResource[T, L]) PrintTableItems ¶
func (b *BaseResource[T, L]) PrintTableItems(items []ResourceWrapper[T]) error
func (*BaseResource[T, L]) Update ¶
func (b *BaseResource[T, L]) Update(obj T) error
Update updates a K8s resource.
func (*BaseResource[T, L]) WithNamespace ¶
func (b *BaseResource[T, L]) WithNamespace(namespace string)
WithNamespace sets the namespace on the resource
type CommonResource ¶ added in v0.3.0
type CommonResource interface {
GetNamespace() string
GetConfig() constants.CRDConfig
SetNamespace(namespace string)
}
CommonResource interface defines operations that make sense for all resources
type ConditionGetter ¶
ConditionGetter is an interface for objects that can get conditions
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatTable OutputFormat = "table" OutputFormatYAML OutputFormat = "yaml" OutputFormatJSON OutputFormat = "json" )
type Printable ¶ added in v0.3.0
type Printable interface {
Print(format OutputFormat, filter *ResourceFilter) error
}
Printable interface for resources that support printing/formatting
type ResourceBase ¶ added in v0.3.0
type ResourceBase struct {
// contains filtered or unexported fields
}
ResourceBase provides common fields and functionality for all resources
func NewResourceBase ¶ added in v0.3.0
func NewResourceBase(opts ...ResourceBaseOption) *ResourceBase
NewResourceBase creates a new ResourceBase with options
func (*ResourceBase) ApplyTypedResource ¶ added in v0.3.0
func (base *ResourceBase) ApplyTypedResource(obj interface{}) error
ApplyTypedResource applies a typed resource using the OpenChoreo API
func (*ResourceBase) GetAPIClient ¶ added in v0.3.0
func (base *ResourceBase) GetAPIClient() *choreoctlClient.APIClient
GetAPIClient returns the API client for use by resource implementations
func (*ResourceBase) GetConfig ¶ added in v0.3.0
func (base *ResourceBase) GetConfig() constants.CRDConfig
func (*ResourceBase) GetNamespace ¶ added in v0.3.0
func (base *ResourceBase) GetNamespace() string
func (*ResourceBase) SetNamespace ¶ added in v0.3.0
func (base *ResourceBase) SetNamespace(namespace string)
type ResourceBaseOption ¶ added in v0.3.0
type ResourceBaseOption func(*ResourceBase)
ResourceBaseOption configures a ResourceBase
func WithResourceAPIClient ¶ added in v0.3.0
func WithResourceAPIClient(apiClient *choreoctlClient.APIClient) ResourceBaseOption
WithResourceAPIClient sets the API client for the resource
func WithResourceConfig ¶ added in v0.3.0
func WithResourceConfig(config constants.CRDConfig) ResourceBaseOption
WithResourceConfig sets the CRD config for the resource
func WithResourceLabel ¶ added in v0.3.0
func WithResourceLabel(key, value string) ResourceBaseOption
WithResourceLabel sets a label for the resource
func WithResourceNamespace ¶ added in v0.3.0
func WithResourceNamespace(namespace string) ResourceBaseOption
WithResourceNamespace sets the namespace for the resource
type ResourceFilter ¶
ResourceFilter defines criteria for filtering resources
type ResourceKind ¶
type ResourceKind[T client.Object, L client.ObjectList] struct { // contains filtered or unexported fields }
func NewResourceKind ¶
func NewResourceKind[T client.Object, L client.ObjectList]() *ResourceKind[T, L]
func (*ResourceKind[T, L]) WithClient ¶
func (k *ResourceKind[T, L]) WithClient() ResourceOption[T, L]
func (*ResourceKind[T, L]) WithConfig ¶
func (k *ResourceKind[T, L]) WithConfig() ResourceOption[T, L]
func (*ResourceKind[T, L]) WithLabels ¶
func (k *ResourceKind[T, L]) WithLabels() ResourceOption[T, L]
func (*ResourceKind[T, L]) WithNamespace ¶
func (k *ResourceKind[T, L]) WithNamespace() ResourceOption[T, L]
type ResourceOperation ¶
type ResourceOperation[T client.Object] interface { List() ([]ResourceWrapper[T], error) Create(obj T) error Update(obj T) error Delete(name string) error GetNames() ([]string, error) Exists(name string) (bool, error) GetNamespace() string GetLabels() map[string]string GetConfig() constants.CRDConfig SetNamespace(namespace string) Print(format OutputFormat, filter *ResourceFilter) error PrintItems(items []ResourceWrapper[T], format OutputFormat) error }
ResourceOperation is the interface for any resource operation.
type ResourceOption ¶
type ResourceOption[T client.Object, L client.ObjectList] func(*BaseResource[T, L])
ResourceOption applies configuration to a BaseResource.
func WithClient ¶
func WithClient[T client.Object, L client.ObjectList](c client.Client) ResourceOption[T, L]
WithClient sets the client on BaseResource.
func WithConfig ¶
func WithConfig[T client.Object, L client.ObjectList](cfg constants.CRDConfig) ResourceOption[T, L]
WithConfig sets the CRDConfig on BaseResource.
func WithLabels ¶
func WithLabels[T client.Object, L client.ObjectList](lbls map[string]string) ResourceOption[T, L]
WithLabels sets the labels on BaseResource.
func WithNamespace ¶
func WithNamespace[T client.Object, L client.ObjectList](ns string) ResourceOption[T, L]
WithNamespace sets the namespace on BaseResource.
func WithScheme ¶
func WithScheme[T client.Object, L client.ObjectList](s *runtime.Scheme) ResourceOption[T, L]
WithScheme sets the scheme on BaseResource.
type ResourceWrapper ¶
type ResourceWrapper[T client.Object] struct { // Resource is the actual Kubernetes resource object Resource T // LogicalName is the name of the resource from Choreo's perspective (from labels) LogicalName string // KubernetesName is the actual Kubernetes object name (metadata.name) KubernetesName string }
ResourceWrapper wraps a Kubernetes resource object and provides additional information about the resource, such as the logical name and the Kubernetes name.
func FilterByName ¶
func FilterByName[T client.Object](items []ResourceWrapper[T], name string) ([]ResourceWrapper[T], error)
FilterByName returns only items matching the given logical name (or all if name == "").
func (*ResourceWrapper[T]) GetKubernetesName ¶
func (w *ResourceWrapper[T]) GetKubernetesName() string
GetKubernetesName returns the Kubernetes name of the resource
func (*ResourceWrapper[T]) GetName ¶
func (w *ResourceWrapper[T]) GetName() string
GetName returns the logical name of the resource
func (*ResourceWrapper[T]) GetResource ¶
func (w *ResourceWrapper[T]) GetResource() T
GetResource returns the underlying Kubernetes resource