Documentation
¶
Index ¶
- func AddLabelsColumnToTable(table *metav1.Table)
- func Apply(ctx context.Context, dynClient dynamic.Interface, ...) (name, kind string, err error)
- func DecodeUnstructured(data []byte) (*unstructured.Unstructured, error)
- func LabelsToString(labels map[string]string) string
- func LookupDefaultName(gvk schema.GroupVersionKind) (func(data []byte) (string, error), bool)
- func PrintStructured(obj runtime.Object, format string) error
- func PrintTable(table *metav1.Table, showLabels bool) error
- func ReadInputData(filename string) ([]byte, error)
- func ReadInputs(paths []string, recursive bool) ([][]byte, error)
- func RegisterDefaultName(gvk schema.GroupVersionKind, fn func(data []byte) (string, error))
- func SplitYAMLDocuments(data []byte) [][]byte
- type ApplyOptions
- type CustomPrinterConfig
- type Object
- type ResourceClient
- type ResourceCommand
- type TableConverter
- type TablePrinterConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLabelsColumnToTable ¶
AddLabelsColumnToTable appends a Labels column to a table and populates it from the embedded objects.
func Apply ¶
func Apply( ctx context.Context, dynClient dynamic.Interface, mapper *restmapper.DeferredDiscoveryRESTMapper, data []byte, opts ApplyOptions, ) (name, kind string, err error)
Apply server-side-applies a single resource document (YAML or JSON) using the supplied dynamic client and REST mapper. Returns the applied object's name and kind for status reporting. data must be a single document — call SplitYAMLDocuments first if you have a multi-doc stream.
func DecodeUnstructured ¶
func DecodeUnstructured(data []byte) (*unstructured.Unstructured, error)
DecodeUnstructured parses a single YAML/JSON document without requiring a registered scheme. See decodeUnstructured.
func LabelsToString ¶
LabelsToString formats a label map as a comma-separated key=value string.
func LookupDefaultName ¶
LookupDefaultName returns the DefaultName function for the given GVK, if registered.
func PrintStructured ¶
PrintStructured serializes a runtime.Object as JSON or YAML to stdout.
func PrintTable ¶
PrintTable prints a metav1.Table to stdout using display-width-aware column alignment (handles emoji and other wide Unicode correctly).
func ReadInputData ¶
ReadInputData reads configuration data from stdin or the given file path. If filename is empty, it reads from stdin if piped data is available.
func ReadInputs ¶
ReadInputs collects YAML/JSON contents from a list of paths. Each path may be a file, a directory (walked for *.yaml / *.yml / *.json; descends into subdirs only when recursive is true), or "-" to read from stdin. Returns one []byte per source file — callers should pass each through SplitYAMLDocuments to handle multi-doc streams.
func RegisterDefaultName ¶
func RegisterDefaultName(gvk schema.GroupVersionKind, fn func(data []byte) (string, error))
RegisterDefaultName registers a function that derives metadata.name from raw resource data for resources of the given GVK.
func SplitYAMLDocuments ¶
SplitYAMLDocuments splits a multi-doc YAML stream on "\n---" boundaries. Empty documents are dropped.
Types ¶
type ApplyOptions ¶
type ApplyOptions struct {
// FieldManager identifies the actor for managed-fields tracking.
// Defaults to "apoxy-cli" when empty.
FieldManager string
// Force resolves field-ownership conflicts in this caller's favor.
Force bool
}
ApplyOptions controls server-side apply behavior.
type CustomPrinterConfig ¶
type CustomPrinterConfig[T, TList any] struct { Header func(showLabels bool) pretty.Header BuildRow func(item T, showLabels bool) []interface{} GetItems func(list TList) []T }
CustomPrinterConfig configures printing for types that use pretty.Table.
type Object ¶
Object combines runtime.Object with metav1.Object to allow accessing both Kubernetes object metadata (Name, Labels, etc.) and runtime type information.
type ResourceClient ¶
type ResourceClient[T, TList any] interface { Get(ctx context.Context, name string, opts metav1.GetOptions) (T, error) List(ctx context.Context, opts metav1.ListOptions) (TList, error) Create(ctx context.Context, obj T, opts metav1.CreateOptions) (T, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (T, error) }
ResourceClient is the subset of the generated Kubernetes client interface needed for CRUD operations.
type ResourceCommand ¶
type ResourceCommand[T Object, TList runtime.Object] struct { Use string Aliases []string Short string Long string KindName string ClientFunc func(*rest.APIClient) ResourceClient[T, TList] // Exactly one of these must be set. TablePrinter *TablePrinterConfig[T, TList] CustomPrinter *CustomPrinterConfig[T, TList] // PostGet is an optional hook called after Get to display additional information. PostGet func(ctx context.Context, c *rest.APIClient, name string, obj T) error // ListFlags registers custom flags on both the root and list commands. // Returns a function that produces a field selector string from those flags. ListFlags func(cmd *cobra.Command) func() string // ListLabelFlags registers custom flags on both the root and list commands. // Returns a function that produces a label selector string from those flags. ListLabelFlags func(cmd *cobra.Command) func() string // ListArgLabelSelector, if set, allows the root and list commands to // accept an optional single positional argument (typically a parent // resource's name) and turns it into a label selector, mirroring how // `get <name>` takes its name positionally instead of via a flag. ListArgLabelSelector func(arg string) string // NameTransform converts a user-facing name argument into the internal // metadata.name used by the API. If nil, the argument is used as-is. NameTransform func(string) (string, error) // ResolveName converts a user-facing name argument into the internal // metadata.name, with API access for lookups (e.g. resolving an alias // or a spec field back to the object name). Takes precedence over // NameTransform in get and delete when set. ResolveName func(ctx context.Context, c *rest.APIClient, arg string) (string, error) // DefaultName derives metadata.name from the object's spec when // metadata.name is empty. Used by the apply command. // If nil, metadata.name must be provided in the input. DefaultName func(T) (string, error) // PreApply is called before server-side apply and may mutate the object // (e.g. set annotations). If nil, no pre-processing is done. PreApply func(ctx context.Context, obj T) error }
ResourceCommand defines a generic CLI resource command that generates get, list, create, delete, and apply subcommands.
func (*ResourceCommand[T, TList]) Build ¶
func (r *ResourceCommand[T, TList]) Build() *cobra.Command
Build returns a fully-wired *cobra.Command with get/list/create/delete/apply subcommands and all standard flags.
type TableConverter ¶
type TableConverter interface {
ConvertToTable(ctx context.Context, tableOptions runtime.Object) (*metav1.Table, error)
}
TableConverter is implemented by types that can convert to a metav1.Table.
type TablePrinterConfig ¶
type TablePrinterConfig[T, TList any] struct { ObjToTable func(T) TableConverter ListToTable func(TList) TableConverter }
TablePrinterConfig configures printing for types that implement ConvertToTable.