transform

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 51

Documentation

Index

Constants

View Source
const (
	RequestVersion  = V1
	ResponseVersion = V1
)
View Source
const (
	// Metadata string is the constant string that will be used by the binary-pluigin helper and the cli helpers
	// To notice that
	MetadataString string = "METADATA"
)

Variables

This section is empty.

Functions

func EqualPluginOperation

func EqualPluginOperation(pluginOp1, pluginOp2 PluginOperation) bool

func EqualPluginOperationList

func EqualPluginOperationList(pluginOps1, pluginOps2 []PluginOperation) bool

func GetResourceTypeKey added in v0.1.6

func GetResourceTypeKey(resource unstructured.Unstructured) string

GetResourceTypeKey returns the unique type key for grouping resources Format: "<kind>" for core resources, "<kind>.<group>" for non-core

func ParseOptionalFieldMapVal

func ParseOptionalFieldMapVal(sliceVal string) map[string]string

func ParseOptionalFieldSliceVal

func ParseOptionalFieldSliceVal(sliceVal string) []string

func ReadResourceTypeFile added in v0.1.6

func ReadResourceTypeFile(filename string) ([]unstructured.Unstructured, error)

ReadResourceTypeFile reads a multi-doc YAML file and returns individual resources This is useful for reading output from previous stages in multi-stage pipeline

func SplitNewResourceToSkeletonAndPatch added in v0.1.6

func SplitNewResourceToSkeletonAndPatch(resource unstructured.Unstructured) (unstructured.Unstructured, jsonpatch.Patch, error)

SplitNewResourceToSkeletonAndPatch takes a complete resource generated by a plugin and splits it into a minimal skeleton and a RFC 6902 JSONPatch.

The skeleton contains only: apiVersion, kind, metadata.name, metadata.namespace. Everything else (labels, annotations, spec, status, ...) becomes "add" operations in the returned patch.

This allows new resources to follow the same skeleton + patches flow as transformed resources, keeping the stage directory structure consistent and transparent.

func WriteResourceTypeFile added in v0.1.6

func WriteResourceTypeFile(filename string, resources []unstructured.Unstructured) error

WriteResourceTypeFile writes a group of resources to a multi-doc YAML file Resources are separated by "---" separator as per YAML multi-doc format

Types

type IgnoredOperation added in v0.1.6

type IgnoredOperation struct {
	// Operation is the JSONPatch operation that was ignored
	Operation jsonpatch.Operation

	// Plugin is the name of the plugin that generated this operation
	Plugin string

	// Reason describes why the operation was ignored (e.g., "path-conflict-priority")
	Reason string

	// WinnerPlugin is the name of the plugin whose operation was selected instead
	WinnerPlugin string
}

IgnoredOperation represents a JSONPatch operation that was discarded due to conflicts with higher priority plugins

type Metadata

type Metadata interface {
	Metadata() PluginMetadata
}

type OptionalFields

type OptionalFields struct {
	FlagName string `json:"flagName"`
	Help     string `json:"help"`
	Example  string `json:"example"`
}

type PatchTarget added in v0.1.6

type PatchTarget struct {
	// Group is the API group (empty string for core resources)
	Group string

	// Version is the API version (e.g., "v1", "v1beta1")
	Version string

	// Kind is the resource kind (e.g., "Deployment", "Service")
	Kind string

	// Name is the resource name from metadata.name
	Name string

	// Namespace is the resource namespace from metadata.namespace (optional)
	Namespace string
}

PatchTarget contains Kustomize patch target selector metadata derived from the resource's apiVersion, kind, and metadata

func DeriveTargetFromResource added in v0.1.6

func DeriveTargetFromResource(resource unstructured.Unstructured) PatchTarget

DeriveTargetFromResource extracts PatchTarget metadata from a Kubernetes resource

type Plugin

type Plugin interface {
	PluginRun
	Metadata
}

type PluginMetadata

type PluginMetadata struct {
	Name            string           `json:"name"`
	Version         string           `json:"version"`
	RequestVersion  []Version        `json:"requestVersion"`
	ResponseVersion []Version        `json:"responseVersion"`
	OptionalFields  []OptionalFields `json:"optionalFields,omitempty"`
}

type PluginOperation

type PluginOperation struct {
	PluginName string
	Operation  jsonpatch.Operation
}

func PluginOperationsFromPatch

func PluginOperationsFromPatch(pluginName string, patches jsonpatch.Patch) []PluginOperation

type PluginRequest added in v0.0.2

type PluginRequest struct {
	unstructured.Unstructured `json:",inline"`
	Extras                    map[string]string `json:"extras,omitempty"`
}

type PluginResponse

type PluginResponse struct {
	Version      string                      `json:"version,omitempty"`
	IsWhiteOut   bool                        `json:"isWhiteOut,omitempty"`
	Patches      jsonpatch.Patch             `json:"patches,omitempty"`
	NewResources []unstructured.Unstructured `json:"newResources,omitempty"`
}

type PluginRun

type PluginRun interface {
	// Determine for a given resources what the plugin is deciding to do with this
	Run(PluginRequest) (PluginResponse, error)
}

type ResourceGroup added in v0.1.6

type ResourceGroup struct {
	// TypeKey is the unique identifier for this resource type
	// Format: "<kind>" for core resources, "<kind>.<group>" for others
	// Examples: "deployment", "service", "route.route.openshift.io"
	TypeKey string

	// Resources contains all resources of this type
	Resources []unstructured.Unstructured
}

ResourceGroup represents resources grouped by type (kind + group) for multi-doc YAML file generation

func GroupResourcesByType added in v0.1.6

func GroupResourcesByType(resources []unstructured.Unstructured) []ResourceGroup

GroupResourcesByType groups resources by their type (kind + group) Resources are grouped into ResourceGroup structures for multi-doc YAML file generation

type Runner

type Runner struct {
	// This is where we need to put extra info
	// This should include generic args to be passed to each Plugin
	// This also needs to handle the options that it will need.
	// TODO: Figure out options that the runner will need and implement here.
	PluginPriorities map[string]int
	OptionalFlags    map[string]string
	Log              *logrus.Logger
}

func NewRunner added in v0.1.6

func NewRunner(logger *logrus.Logger, pluginPriorities map[string]int, optionalFlags map[string]string) *Runner

NewRunner creates a new Runner with the required logger. If logger is nil, a new default logger is created.

func (*Runner) Run

func (r *Runner) Run(object unstructured.Unstructured, plugins []Plugin) (RunnerResponse, error)

type RunnerResponse

type RunnerResponse struct {
	TransformFile  []byte
	HaveWhiteOut   bool
	IgnoredPatches []byte
	NewResources   []unstructured.Unstructured
}

RunnerResponse will be responsble for TransformFile is a marshaled jsonpatch.Patch IgnoredPatches is a marshaled []PluginOperation

type TransformArtifact added in v0.1.6

type TransformArtifact struct {
	// Resource is the original Kubernetes resource
	Resource unstructured.Unstructured

	// HaveWhiteOut indicates if this resource should be excluded from output
	HaveWhiteOut bool

	// Patches contains all JSONPatch operations to be applied
	Patches jsonpatch.Patch

	// IgnoredOps contains operations that were ignored due to conflicts
	IgnoredOps []IgnoredOperation

	// Target contains the Kustomize patch target metadata
	Target PatchTarget

	// PluginName is the name of the plugin that generated this artifact (for multi-stage)
	PluginName string
}

TransformArtifact represents the transformation result for a single resource including patches, whiteout status, and metadata for Kustomize generation

type Version

type Version string
const (
	V1 Version = "v1"
)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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