kgen

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 2

README

kgen

write helm templates using Go

kgen is a Go library to generate Kubernetes manifests using Go code.

Why?

Kubernetes resources are defined in YAML files. This is a good thing, because it allows us to use the same tooling to manage them as we use to manage our application code. However, it also means that we lose the ability to use the type system to validate our resources.

Kube GoGen allows us to define our Kubernetes resources in Go code, and then generate the YAML files from that code. This means that we can use the type system to validate our resources, and we can use our IDE to provide autocompletion and documentation.

Documentation


Documentation

Index

Constants

View Source
const (
	// All resources are output into a single YAML file.
	YamlOutputTypeSingleFile yamlOutputType = "single"
	// Resources are split into seperate files by scope.
	YamlOutputTypeFilePerScope yamlOutputType = "scope"
	// Each resource is output to its own file.
	YamlOutputTypeFilePerResource yamlOutputType = "resource"
	// Each resource is output to its own file in a folder named after the scope.
	YamlOutputTypeFolderPerScopeFilePerResource yamlOutputType = "folder"
	// Resources are split into seperate files by scope, while creating a folder for each scope.
	YamlOutputTypeFolderPerScopeFilePerLeafScope yamlOutputType = "folder-per-parent"
)

inspired by cdk8s (https://cdk8s.io/docs/latest/reference/cdk8s/python/#yamloutputtype)

Variables

This section is empty.

Functions

func GenerateContextKey

func GenerateContextKey() string

Types

type ApiObject

type ApiObject interface {
	metav1.Type
	metav1.Object
	ToYAML() []byte
	GetObject() runtime.Object
	ReplaceObject(v runtime.Object)
}

type ApiObjectProps

type ApiObjectProps struct {
	*unstructured.Unstructured
}

type Builder

type Builder interface {
	Scope
	RenderManifests(opts RenderManifestsOptions)
}

func NewBuilder

func NewBuilder(opts BuilderOptions) Builder

type BuilderOptions

type BuilderOptions struct {
	SchemeBuilder runtime.SchemeBuilder
	Logger        Logger
}

type CustomLoggerOptions added in v0.0.2

type CustomLoggerOptions struct {
	InfofFn  func(msg string, args ...any)
	WarnfFn  func(msg string, args ...any)
	PanicfFn func(msg string, args ...any)
}

type Logger added in v0.0.2

type Logger interface {
	Infof(msg string, args ...any)
	Warnf(msg string, args ...any)
	Panicf(msg string, args ...any)
}

func NewCustomLogger added in v0.0.2

func NewCustomLogger(props *CustomLoggerOptions) Logger

type RenderManifestsOptions added in v0.0.2

type RenderManifestsOptions struct {
	Outdir                   string
	YamlOutputType           yamlOutputType
	IncludeNumberInFilenames bool
	DeleteOutDir             bool
	PatchObject              func(ApiObject) error
}

type Scope

type Scope interface {
	ID() string
	Namespace() string
	CreateScope(id string, props ScopeProps) Scope
	GetContext(key string) any
	SetContext(key string, value any)
	AddApiObject(obj runtime.Object) ApiObject
	AddApiObjectFromMap(props map[string]any) ApiObject
	WalkApiObjects(walkFn func(ApiObject) error) error
	Logger() Logger
}

type ScopeProps

type ScopeProps struct {
	Namespace string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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