⚠️ Work in Progress
Kure is currently under active development and has not been released yet. APIs and features are subject to change.

IO

IO - YAML Serialization and Resource Printing

The io package provides utilities for parsing, serializing, and printing Kubernetes resources. It supports multiple output formats including YAML, JSON, and kubectl-compatible table views.

Overview

This package handles the I/O boundary of Kure: reading Kubernetes manifests from files, serializing resources to YAML/JSON, and printing resources in human-readable formats. It integrates with Kure’s registered scheme for type-aware parsing.

Parsing

Parse YAML Files

import "github.com/go-kure/kure/pkg/io"

// Parse a multi-document YAML file into typed Kubernetes objects
objects, err := io.ParseFile("manifests/deployment.yaml")

// Parse YAML bytes directly
objects, err := io.ParseYAML(yamlData)

Load and Save

// Load a single object from file
obj, err := io.LoadFile("service.yaml")

// Save an object to file
err := io.SaveFile("output.yaml", deployment)

Serialization

Marshal and Unmarshal

// Serialize to YAML bytes
data, err := io.Marshal(deployment)

// Deserialize from YAML bytes
var obj appsv1.Deployment
err := io.Unmarshal(data, &obj)

Encode Multiple Objects

// Encode as multi-document YAML
yamlData, err := io.EncodeObjectsToYAML(objects)

// Encode as JSON array
jsonData, err := io.EncodeObjectsToJSON(objects)

Printing

Output Formats

The package supports kubectl-compatible output formats:

FormatConstantDescription
YAMLOutputFormatYAMLFull YAML output
JSONOutputFormatJSONFull JSON output
TableOutputFormatTableColumnar table view
WideOutputFormatWideExtended table with extra columns
NameOutputFormatNameResource names only

Usage

// Print as YAML to stdout
err := io.PrintObjectsAsYAML(objects, os.Stdout)

// Print as table
err := io.PrintObjectsAsTable(objects, false, false, os.Stdout)

// Use ResourcePrinter for configurable output
printer := io.NewResourcePrinter(io.PrintOptions{
    OutputFormat: io.OutputFormatTable,
    ShowLabels:   true,
})
err := printer.Print(objects, os.Stdout)
  • errors - Error types for parse failures
  • kubernetes - Scheme registration for type-aware parsing