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

Using Kure as a Library

Using Kure as a Library

Kure is primarily a Go library. This guide covers the basics of importing it, creating resources, and generating YAML output.

Installation

go get github.com/go-kure/kure

Creating Resources

Kure provides typed builder functions for Kubernetes and FluxCD resources.

FluxCD Resources

import "github.com/go-kure/kure/pkg/kubernetes/fluxcd"

// Create a GitRepository source
repo := fluxcd.GitRepository(&fluxcd.GitRepositoryConfig{
    Name:      "my-repo",
    Namespace: "flux-system",
    URL:       "https://github.com/org/repo",
    Branch:    "main",
    Interval:  "5m",
})

// Create a Kustomization that references the source
ks := fluxcd.Kustomization(&fluxcd.KustomizationConfig{
    Name:      "my-app",
    Namespace: "flux-system",
    Path:      "./clusters/production",
    Interval:  "10m",
    Prune:     true,
    SourceRef: kustv1.CrossNamespaceSourceReference{
        Kind: "GitRepository",
        Name: "my-repo",
    },
})

See the FluxCD Builders reference for all available resource types.

Generating YAML

Use the io package to serialize resources:

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

// Serialize a single object
data, err := io.Marshal(deployment)

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

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

See the IO reference for all output formats.

Working with the Domain Model

For more complex scenarios, use the Stack package to define cluster topologies:

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

cluster := stack.NewClusterBuilder("production").
    WithNode("apps").
        WithBundle("web").
            WithApplication("frontend", frontendConfig).
        End().
    End().
    Build()

Then use the Flux Engine and Layout Engine to generate a complete GitOps repository structure. See the Generating Flux Manifests guide for the full workflow.

Error Handling

All Kure packages use the errors package:

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

if err != nil {
    return errors.Wrap(err, "failed to generate manifests")
}

Next Steps