kube

package
v0.0.0-...-862afa6 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 26 Imported by: 17

Documentation

Overview

Package kube provides APIs to convert Kubernetes manifests YAML from and to Go code. The main value of this package is to provide a way to manage kubernetes objects by converting them from YAML to Go code, and back again. This is useful when modifying and managing Go code as a source of truth for your kubernetes platform while still being able to export to YAML which is the de facto standard for kubernetes manifests.

Have a look at the tests for more examples.

From YAML to Go code

The Import function converts Kubernetes manifests from YAML to Go code. It is flexible as it accepts a number of options to customize the output. All the functions starting with `With` are options.

From Go to YAML

The Export function converts Kubernetes manifests from Go code to YAML.

Explode manifests into separate files

The Explode function organizes Kubernetes manifests as separate files in a directory structure. It represents more closely the way they appear in a kubernetes cluster.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrFieldMissing      = errors.New("missing")
	ErrDuplicateDetected = errors.New("duplicate detected")
)
View Source
var (
	ErrIncompatibleOptions = errors.New("incompatible options")
)

Functions

func DirectoryName

func DirectoryName(ns, kind string) string

DirectoryName returns the directory name for the given namespace and kind

Example (Clusterrole)
fmt.Println(DirectoryName("", "ClusterRole"))
Output:

_cluster/rbac
Example (Crd)
fmt.Println(DirectoryName("", "CustomResourceDefinition"))
Output:

_cluster/crd
Example (DefaultNamespace)
fmt.Println(DirectoryName("myapps", "Deployment"))
Output:

myapps

func Explode

func Explode(r io.Reader, dir string) error

Explode reads a YAML manifests from io.Reader and writes the objects to files in dir. Each object is written to a file named after the object's kind and name. The file name is prefixed with a number that indicates the rank of the kind. The rank is used to sort the files in the directory and prioritize the order in which they are applied. For example, a namespace should be applied before any other object in the namespace.

Example
package main

import (
	"fmt"
	"os"
	"sort"

	"github.com/volvo-cars/lingon/pkg/kube"
	"github.com/volvo-cars/lingon/pkg/kubeutil"
)

func main() {
	out := "./out/explode"
	_ = os.RemoveAll(out)
	defer func() {
		_ = os.RemoveAll(out)
	}()
	fp, err := os.Open("./testdata/karpenter.yaml")
	if err != nil {
		panic(fmt.Errorf("open file: %w", err))
	}
	defer func() {
		_ = fp.Close()
	}()

	// explode them into individual files
	if err = kube.Explode(fp, out); err != nil {
		panic(fmt.Errorf("explode manifest files: %w", err))
	}

	got, err := kubeutil.ListYAMLFiles("./out/explode")
	if err != nil {
		panic(fmt.Errorf("list yaml files: %w", err))
	}
	// sort the files to make the output deterministic
	sort.Strings(got)

	for _, f := range got {
		fmt.Println(f)
	}
}
Output:


out/explode/_cluster/rbac/1_karpenter-admin_cr.yaml
out/explode/_cluster/rbac/1_karpenter-core_cr.yaml
out/explode/_cluster/rbac/1_karpenter_cr.yaml
out/explode/_cluster/rbac/2_karpenter-core_crb.yaml
out/explode/_cluster/rbac/2_karpenter_crb.yaml
out/explode/_cluster/webhook/4_defaulting.webhook.karpenter.k8s.aws_mutatingwebhookconfigurations.yaml
out/explode/_cluster/webhook/4_defaulting.webhook.karpenter.sh_mutatingwebhookconfigurations.yaml
out/explode/_cluster/webhook/4_validation.webhook.config.karpenter.sh_validatingwebhookconfigurations.yaml
out/explode/_cluster/webhook/4_validation.webhook.karpenter.k8s.aws_validatingwebhookconfigurations.yaml
out/explode/_cluster/webhook/4_validation.webhook.karpenter.sh_validatingwebhookconfigurations.yaml
out/explode/karpenter/1_karpenter_role.yaml
out/explode/karpenter/1_karpenter_sa.yaml
out/explode/karpenter/1_karpenter_svc.yaml
out/explode/karpenter/2_config-logging_cm.yaml
out/explode/karpenter/2_karpenter-cert_secrets.yaml
out/explode/karpenter/2_karpenter-global-settings_cm.yaml
out/explode/karpenter/2_karpenter_rb.yaml
out/explode/karpenter/3_karpenter_deploy.yaml
out/explode/karpenter/4_karpenter_pdb.yaml
out/explode/kube-system/1_karpenter-dns_role.yaml
out/explode/kube-system/2_karpenter-dns_rb.yaml
Example (Reader)
package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/volvo-cars/lingon/pkg/kube"
	"github.com/volvo-cars/lingon/pkg/kubeutil"
)

func main() {
	out := "./out/explodereader"
	_ = os.RemoveAll(out)
	defer func() {
		_ = os.RemoveAll(out)
	}()
	manifest, err := kubeutil.ManifestReadFile("./testdata/golden/reader.yaml")
	if err != nil {
		panic(fmt.Errorf("read manifest files: %w", err))
	}
	fakeManifest := `
apiVersion: v1
kind: ConfigMap
metadata:
  name: fake	
`
	manifest = append(manifest, fakeManifest)
	// join the manifest into a single string
	joined := strings.Join(manifest, "\n---\n")
	r := strings.NewReader(joined)

	// explode them into individual files
	// this will fail because the reader.yaml manifest is not valid
	_ = kube.Explode(r, out)

	// but we can still list the files already processed
	got, err := kubeutil.ListYAMLFiles(out)
	if err != nil {
		panic(fmt.Errorf("list yaml files: %w", err))
	}

	for _, f := range got {
		fmt.Println(f)
	}
}
Output:

out/explodereader/default/3_webapp_deploy.yaml

func Export

func Export(km Exporter, opts ...ExportOption) error
Example
package main

import (
	"bytes"
	"fmt"

	"github.com/volvo-cars/lingon/pkg/kube"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// validate the struct implements the interface
var _ kube.Exporter = (*MyK8sApp)(nil)

// MyK8sApp contains kubernetes manifests
type MyK8sApp struct {
	kube.App
	// Namespace is the namespace for the tekton-pipelines
	PipelinesNS *corev1.Namespace
}

// New returns a new MyK8sApp
func New() *MyK8sApp {
	return &MyK8sApp{
		PipelinesNS: &corev1.Namespace{
			TypeMeta: metav1.TypeMeta{
				APIVersion: "v1",
				Kind:       "Namespace",
			},
			ObjectMeta: metav1.ObjectMeta{
				Name: "tekton-pipelines",
				Labels: map[string]string{
					"app.kubernetes.io/name": "tekton-pipelines",
				},
			},
		},
	}
}

func main() {
	tk := New()

	var buf bytes.Buffer
	_ = kube.Export(tk, kube.WithExportWriter(&buf))

	fmt.Printf("%s\n", buf.String())

}
Output:


-- out/0_pipelines_ns.yaml --
apiVersion: v1
kind: Namespace
metadata:
  labels:
    app.kubernetes.io/name: tekton-pipelines
  name: tekton-pipelines
spec: {}
Example (Embedded)
package main

import (
	"bytes"
	"fmt"

	"github.com/volvo-cars/lingon/pkg/kube"
	"github.com/volvo-cars/lingon/pkg/kubeutil"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type SubApp struct {
	kube.App

	CM *corev1.ConfigMap
}

func NewSubApp() *SubApp {
	return &SubApp{
		CM: &corev1.ConfigMap{
			TypeMeta: kubeutil.TypeConfigMapV1,
			ObjectMeta: metav1.ObjectMeta{
				Name:      "config-map-name",
				Namespace: "my-ns",
			},
			Data: map[string]string{"key": "value"},
		},
	}
}

type MainApp struct {
	kube.App

	SubApp *SubApp
	NS     *corev1.Namespace
}

func NewApp() *MainApp {
	return &MainApp{
		SubApp: NewSubApp(),
		NS: &corev1.Namespace{
			TypeMeta:   kubeutil.TypeNamespaceV1,
			ObjectMeta: metav1.ObjectMeta{Name: "my-ns"},
		},
	}
}

func main() {
	app := NewApp()

	var buf bytes.Buffer
	_ = kube.Export(app, kube.WithExportWriter(&buf))

	fmt.Printf("%s\n", buf.String())

}
Output:


-- out/0_ns.yaml --
apiVersion: v1
kind: Namespace
metadata:
  name: my-ns
spec: {}
-- out/2_sub_appcm.yaml --
apiVersion: v1
data:
  key: value
kind: ConfigMap
metadata:
  name: config-map-name
  namespace: my-ns

func Import

func Import(opts ...ImportOption) error
Example
out := filepath.Join("out", "tekton")
_ = os.RemoveAll(out)
defer os.RemoveAll(out)
err := kube.Import(
	// name of the application
	kube.WithImportAppName("tekton"),
	// name of the Go package where the code is generated to
	kube.WithImportPackageName("tekton"),
	// the directory to write the generated code to
	kube.WithImportOutputDirectory(out),
	// the list of manifest files to read and convert
	kube.WithImportManifestFiles([]string{"testdata/tekton.yaml"}),
	// define the types for the CRDs
	kube.WithImportSerializer(defaultSerializer()),
	// will try to remove "tekton" from the name of the variable in the Go code, make them shorter
	kube.WithImportRemoveAppName(true),
	// group all the resources from the same kind into one file each
	// example: 10 ConfigMaps => 1 file "config-map.go" containing 10 variables storing ConfigMap, etc...
	kube.WithImportGroupByKind(true),
	// add convenience methods to the App struct
	kube.WithImportAddMethods(true),
	// do not print verbose information
	kube.WithImportVerbose(false),
	// do not ignore errors
	kube.WithImportIgnoreErrors(false),
	// just for example purposes
	// how to create a logger (see [golang.org/x/tools/slog](https://golang.org/x/tools/slog))
	// this has no effect with WithImportVerbose(false)
	kube.WithImportLogger(kube.Logger(os.Stderr)),
	// remove the status field and
	// other output-only fields from the manifest code before importing it.
	// Note that ConfigMap are not cleaned up as the comments will be lost.
	kube.WithImportCleanUp(true),
)
if err != nil {
	panic(fmt.Errorf("import: %w", err))
}
got, err := kubeutil.ListGoFiles(out)
if err != nil {
	panic(fmt.Errorf("list go files: %w", err))
}
// sort the files to make the output deterministic
sort.Strings(got)

for _, f := range got {
	fmt.Println(f)
}
Output:


out/tekton/app.go
out/tekton/cluster-role-binding.go
out/tekton/cluster-role.go
out/tekton/config-map.go
out/tekton/custom-resource-definition.go
out/tekton/deployment.go
out/tekton/horizontal-pod-autoscaler.go
out/tekton/mutating-webhook-configuration.go
out/tekton/namespace.go
out/tekton/role-binding.go
out/tekton/role.go
out/tekton/secret.go
out/tekton/service-account.go
out/tekton/service.go
out/tekton/validating-webhook-configuration.go
Example (WithWriter)
package main

import (
	"bytes"
	"fmt"
	"os"
	"sort"
	"strings"

	"github.com/volvo-cars/lingon/pkg/kube"
	"github.com/volvo-cars/lingon/pkg/kubeutil"
	"golang.org/x/tools/txtar"
)

func main() {
	filename := "testdata/grafana.yaml"
	file, _ := os.Open(filename)

	var buf bytes.Buffer

	err := kube.Import(
		kube.WithImportAppName("grafana"),
		kube.WithImportPackageName("grafana"),
		// will prefix all files with path "manifests/"
		kube.WithImportOutputDirectory("manifests/"),
		// we could just use kube.WithImportManifestFiles([]string{filename})
		// but this is just an example to show how to use WithImportReader
		// and WithImportWriter
		kube.WithImportReader(file),
		kube.WithImportWriter(&buf),
		// We don't want to group the resources by kind,
		// each file will contain a single resource
		kube.WithImportGroupByKind(false),
		// We rename the files to avoid name collisions.
		// Tip: use the Kind and Name of the resource to
		// create a unique name and avoid collision.
		//
		// Here, we didn't use WithImportGroupByKind,
		// each file will contain a single resource.
		kube.WithImportNameFileFunc(
			func(m kubeutil.Metadata) string {
				return fmt.Sprintf(
					"%s-%s.go",
					strings.ToLower(m.Kind),
					m.Meta.Name,
				)
			},
		),
	)
	if err != nil {
		panic("failed to import")
	}

	// the output contained in bytes.Buffer is in the txtar format
	// for more details, see https://pkg.go.dev/golang.org/x/tools/txtar
	ar := txtar.Parse(buf.Bytes())

	// sort the files to make the output deterministic
	sort.SliceStable(
		ar.Files, func(i, j int) bool {
			return ar.Files[i].Name < ar.Files[j].Name
		},
	)
	for _, f := range ar.Files {
		fmt.Println(f.Name)
	}
}
Output:


manifests/app.go
manifests/clusterrole-grafana-clusterrole.go
manifests/clusterrolebinding-grafana-clusterrolebinding.go
manifests/configmap-grafana-dashboards-default.go
manifests/configmap-grafana-test.go
manifests/configmap-grafana.go
manifests/deployment-grafana.go
manifests/pod-grafana-test.go
manifests/role-grafana.go
manifests/rolebinding-grafana.go
manifests/secret-grafana.go
manifests/service-grafana.go
manifests/serviceaccount-grafana-test.go
manifests/serviceaccount-grafana.go

func Logger

func Logger(w io.Writer) *slog.Logger

Logger returns a logger that writes to w io.Writer. If w is nil, os.Stderr is used. Timestamp is removed and directory from the source's filename is shown.

func NameFieldFunc

func NameFieldFunc(m kubeutil.Metadata) string

NameFieldFunc returns the name of the field in the App struct

Example (AddKind)
m := kubeutil.Metadata{
	Kind: "Deployment",
	Meta: kubeutil.Meta{Name: "super-duper-app"},
}
fmt.Println(NameFieldFunc(m))
Output:

SuperDuperAppDeploy
Example (KindSuffix)
m := kubeutil.Metadata{
	Kind: "Deployment",
	Meta: kubeutil.Meta{Name: "super-duper-deployment"},
}
fmt.Println(NameFieldFunc(m))
Output:

SuperDuperDeploy
Example (KindWithDash)
m := kubeutil.Metadata{
	Kind: "ClusterRole",
	Meta: kubeutil.Meta{Name: "argo-cluster-role"},
}
fmt.Println(NameFieldFunc(m))
Output:

ArgoCR

func NameFileFunc

func NameFileFunc(m kubeutil.Metadata) string

NameFileFunc returns the name of the file containing the kubernetes object

Example
m := kubeutil.Metadata{
	Kind: "Deployment",
	Meta: kubeutil.Meta{Name: "super-duper-app"},
}
fmt.Println(NameFileFunc(m))
Output:

super-duper-app_deploy.go

func NameVarFunc

func NameVarFunc(m kubeutil.Metadata) string

NameVarFunc returns the name of the variable containing the imported kubernetes object.

TIP: ALWAYS put the kind somewhere in the name to avoid collisions

Example (AddKind)
m := kubeutil.Metadata{
	Kind: "Deployment",
	Meta: kubeutil.Meta{Name: "super-duper-app"},
}
fmt.Println(NameVarFunc(m))
Output:

SuperDuperAppDeploy
Example (KindSuffix)
m := kubeutil.Metadata{
	Kind: "Deployment",
	Meta: kubeutil.Meta{Name: "super-duper-deployment"},
}
fmt.Println(NameVarFunc(m))
Output:

SuperDuperDeploy
Example (KindWithDash)
m := kubeutil.Metadata{
	Kind: "ClusterRole",
	Meta: kubeutil.Meta{Name: "argo-cluster-role"},
}
fmt.Println(NameVarFunc(m))
Output:

ArgoCR

func RemoveAppName

func RemoveAppName(name, appName string) string

RemoveAppName removes the app name from the name

Types

type App

type App struct{}

App struct is meant to be embedded in other structs to specify that they are a set of kubernetes manifests

func (*App) Lingon

func (a *App) Lingon()

Lingon is a dummy method to make sure that App implements Exporter

type ExportOption

type ExportOption func(*goky)

ExportOption is used to configure conversion from Go code to kubernetes objects in YAML. Helpers function are provided to those field, see WithExportXXX functions

func WithExportAsSingleFile

func WithExportAsSingleFile(name string) ExportOption

WithExportAsSingleFile flag will write all the manifests in a single file Note that this is not compatible with WithExportExplodeManifests flag

Usage:

err := Export(km,
		WithExportOutputDirectory("./out"),
		WithExportAsSingleFile("manifests.yaml"),
		)

the output file will be written to ./out/manifests.yaml

func WithExportExplodeManifests

func WithExportExplodeManifests(b bool) ExportOption

WithExportExplodeManifests explodes the manifests into separate files organized by namespace to match closely the structure of the kubernetes cluster. See Explode for more info. Note that this option is incompatible WithExportAsSingleFile.

func WithExportKustomize

func WithExportKustomize(b bool) ExportOption

WithExportKustomize adds a kustomization.yaml file to the output.

func WithExportNameFileFunc

func WithExportNameFileFunc(f func(m *kubeutil.Metadata) string) ExportOption

WithExportNameFileFunc sets the function to format the name of the file containing the kubernetes object. Note that the files needs an extension to be added: ".yaml" or ".yml"

Usage:

WithExportNameFileFunc(func(m *kubeutil.Metadata) string {
	return fmt.Sprintf("%s-%s.yaml", strings.ToLower(m.Kind), m.Meta.Name)
})

func WithExportOutputDirectory

func WithExportOutputDirectory(dir string) ExportOption

WithExportOutputDirectory sets the output directory for the generated manifests.

func WithExportOutputJSON

func WithExportOutputJSON(b bool) ExportOption

WithExportOutputJSON sets the format of the output to JSON instead of YAML. Not that in the case of exporting to a single file, the format will be a JSON array of objects.

func WithExportSecretHook

func WithExportSecretHook(f func(s *corev1.Secret) error) ExportOption

WithExportSecretHook is used to process the secrets before they are exported. The hook is called for each secret. This is useful to send secret to a vault (pun intended) and not to save them in plain text. Base64 encoded secrets are not secure.

NOTE: the secrets will *NOT* be written to the output directory or io.Writer if this option is used.

func WithExportStdOut

func WithExportStdOut() ExportOption

WithExportStdOut writes the generated manifests to os.Stdout Note that the format is txtar, for more info on golang.org/x/tools/txtar.Archive format see: https://pkg.go.dev/golang.org/x/tools/txtar See WithExportWriter for more info.

If you want to write in the YAML format, use WithExportAsSingleFile instead.

func WithExportWriter

func WithExportWriter(w io.Writer) ExportOption

WithExportWriter writes the generated manifests to io.Writer. Note that the format is txtar, for more info on golang.org/x/tools/txtar.Archive format see: https://pkg.go.dev/golang.org/x/tools/txtar

A txtar archive is zero or more comment lines and then a sequence of file entries. Each file entry begins with a file marker line of the form "-- FILENAME --" and is followed by zero or more file content lines making up the file data. The comment or file content ends at the next file marker line. The file marker line must begin with the three-byte sequence "-- " and end with the three-byte sequence " --", but the enclosed file name can be surrounding by additional white space, all of which is stripped.

If the txtar file is missing a trailing newline on the final line, parsers should consider a final newline to be present anyway.

There are no possible syntax errors in a txtar archive.

type Exporter

type Exporter interface {
	Lingon()
}

Exporter interfaces for kubernetes objects defined in a Go structs

type ImportOption

type ImportOption func(*jamel)

ImportOption is used to configure conversion from kubernetes objects in YAML to Go code Helpers function are provided to those field, see WithExportXXX functions

func WithImportAddMethods

func WithImportAddMethods(b bool) ImportOption

WithImportAddMethods adds convenience methods to the generated code.

Default: true

// Apply applies the kubernetes objects to the cluster
func (a *Tekton) Apply(ctx context.Context) error

// Export exports the kubernetes objects to YAML files in the given directory
func (a *Tekton) Export(dir string) error

// Apply applies the kubernetes objects contained in [Exporter] to the cluster
func Apply(ctx context.Context, km kube.Exporter) error

func WithImportAppName

func WithImportAppName(name string) ImportOption

WithImportAppName sets the application name for the generated code. This is used to name the generated struct. ex: "tekton"

Default: "app"

Note: the name can be used to name the package if none is defined, see WithImportPackageName

func WithImportCleanUp

func WithImportCleanUp(c bool) ImportOption

WithImportCleanUp sets the flag to remove status field and other output-only fields from the manifest code before importing it. Note that ConfigMap are not cleaned up as the comments will be lost. Default: true

func WithImportGroupByKind

func WithImportGroupByKind(b bool) ImportOption

WithImportGroupByKind groups the kubernetes objects by kind in the same file

if there are 10 ConfigMaps and 5 Secrets, it will generate 2 files:

  • configmaps.go
  • secrets.go

as opposed to 15 files.

Default: false

func WithImportIgnoreErrors

func WithImportIgnoreErrors(e bool) ImportOption

WithImportIgnoreErrors sets the flag to ignore errors when reading manifests. Useful with huge manifests or when there are many CRDs and not all of them are registered with scheme.AddToScheme.

func WithImportLogger

func WithImportLogger(l *slog.Logger) ImportOption

WithImportLogger sets the logger slog.Logger to log the import process.

Default: Logger

func WithImportManifestFiles

func WithImportManifestFiles(files []string) ImportOption

WithImportManifestFiles sets the manifest files to read the kubernetes objects from.

func WithImportNameFieldFunc

func WithImportNameFieldFunc(f func(object kubeutil.Metadata) string) ImportOption

WithImportNameFieldFunc sets the function to format the name of the field in the application struct (containing kube.App).

default: NameFieldFunc

TIP: ALWAYS put the kind somewhere in the name to avoid collisions

type Tekton struct {
	kube.App
	// ...
	ThisIsTheNameFieldCM  *corev1.ConfigMap
}

func WithImportNameFileFunc

func WithImportNameFileFunc(f func(object kubeutil.Metadata) string) ImportOption

WithImportNameFileFunc sets the function to format the name of the file containing the kubernetes object.

default: NameFileFunc

Usage:

WithImportNameFileFunc(func(m kubeutil.Metadata) string {
	return fmt.Sprintf("%s-%s.go", strings.ToLower(m.Kind),	m.Meta.Name)
})

func WithImportNameVarFunc

func WithImportNameVarFunc(f func(object kubeutil.Metadata) string) ImportOption

WithImportNameVarFunc sets the function to format the name of the variable containing the kubernetes object.

default: NameVarFunc

var ThisIsTheNameOfTheVar = &appsv1.Deployment{...}

 // ...

func New() *Tekton {
	return &Tekton{
		NameField:          ThisIsTheNameOfTheVar,
		...
	}
}

func WithImportOutputDirectory

func WithImportOutputDirectory(name string) ImportOption

WithImportOutputDirectory sets the output directory for the generated code. Default: "./out"

func WithImportPackageName

func WithImportPackageName(name string) ImportOption

WithImportPackageName sets the package name for the generated code Note that the package name cannot contain a dash, it will panic otherwise.

ex: "tekton" but not "github.com/xxx/tekton"

package tekton
...

func WithImportReadStdIn

func WithImportReadStdIn() ImportOption

WithImportReadStdIn reads the kubernetes objects from os.Stdin.

func WithImportReader

func WithImportReader(r io.Reader) ImportOption

WithImportReader reads the kubernetes manifest (YAML) from a io.Reader Note that this is exclusive with WithImportManifestFiles

If you want to read from os.Stdin use WithImportReadStdIn.

func WithImportRedactSecrets

func WithImportRedactSecrets(b bool) ImportOption

WithImportRedactSecrets removes the value, but not the keys, of kubernetes secrets. Default: true

func WithImportRemoveAppName

func WithImportRemoveAppName(b bool) ImportOption

WithImportRemoveAppName tries to remove the name of the application from the object name. Default: false

func WithImportSerializer

func WithImportSerializer(s runtime.Decoder) ImportOption

WithImportSerializer sets the serializer runtime.Decoder to decode the kubernetes objects

Usage:

func defaultSerializer() runtime.Decoder {
	// add the scheme of the kubernetes objects you want to import
	// this is useful for CRDs to be converted in Go as well
	_ = otherpackage.AddToScheme(scheme.Scheme)
	// needed for `CustomResourceDefinition` objects
	_ = apiextensions.AddToScheme(scheme.Scheme)
	return scheme.Codecs.UniversalDeserializer()
}
_, _ := kube.Import(WithImportSerializer(defaultSerializer()))

func WithImportSingleManifest

func WithImportSingleManifest(file string) ImportOption

WithImportSingleManifest sets the manifest file to read the kubernetes objects from.

func WithImportVerbose

func WithImportVerbose(v bool) ImportOption

WithImportVerbose sets the flag to enable logging.

func WithImportWriter

func WithImportWriter(w io.Writer) ImportOption

WithImportWriter writes the generated Go code to io.Writer. Note that the format is txtar, for more info on golang.org/x/tools/txtar.Archive format see: https://pkg.go.dev/golang.org/x/tools/txtar

A txtar archive is zero or more comment lines and then a sequence of file entries. Each file entry begins with a file marker line of the form "-- FILENAME --" and is followed by zero or more file content lines making up the file data. The comment or file content ends at the next file marker line. The file marker line must begin with the three-byte sequence "-- " and end with the three-byte sequence " --", but the enclosed file name can be surrounding by additional white space, all of which is stripped.

If the txtar file is missing a trailing newline on the final line, parsers should consider a final newline to be present anyway.

There are no possible syntax errors in a txtar archive.

Jump to

Keyboard shortcuts

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