config

package
v0.9.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 82

Documentation

Overview

Package config contains functionality for interacting with ComponentConfig files

DeferredFileLoader

This uses a deferred file decoding allowing you to chain your configuration setup. You can pass this into manager.Options#File and it will load your config.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerManagerConfiguration

type ControllerManagerConfiguration interface {
	runtime.Object

	// Complete returns the versioned configuration
	Complete() (v1alpha1.ControllerManagerConfigurationSpec, error)
}

ControllerManagerConfiguration defines the functions necessary to parse a config file and to configure the Options struct for the ctrl.Manager

type DeferredFileLoader

type DeferredFileLoader struct {
	ControllerManagerConfiguration
	// contains filtered or unexported fields
}

DeferredFileLoader is used to configure the decoder for loading controller runtime component config types

Example (AtPath)

This example will load the file from a custom path

package main

import (
	"fmt"
	"os"

	"sigs.k8s.io/controller-runtime/pkg/config"
)

func main() {
	loader := config.File().AtPath("/var/run/controller-runtime/config.yaml")
	_, err := loader.Complete()
	if err != nil {
		fmt.Println("failed to load config")
		os.Exit(1)
	}
}
Output:

Example (InjectScheme)

This example sets up loader with a custom scheme

package main

import (
	"fmt"
	"os"

	"k8s.io/apimachinery/pkg/runtime"
	"sigs.k8s.io/controller-runtime/pkg/config"

	"sigs.k8s.io/controller-runtime/examples/configfile/custom/v1alpha1"
)

var scheme = runtime.NewScheme()

func init() {
	_ = v1alpha1.AddToScheme(scheme)
}

func main() {
	loader := config.File()
	err := loader.InjectScheme(scheme)
	if err != nil {
		fmt.Println("failed to inject scheme")
		os.Exit(1)
	}

	_, err = loader.Complete()
	if err != nil {
		fmt.Println("failed to load config")
		os.Exit(1)
	}
}
Output:

Example (OfKind)

This example sets up the loader with a custom scheme and custom type

package main

import (
	"fmt"
	"os"

	"k8s.io/apimachinery/pkg/runtime"
	"sigs.k8s.io/controller-runtime/pkg/config"

	"sigs.k8s.io/controller-runtime/examples/configfile/custom/v1alpha1"
)

var scheme = runtime.NewScheme()

func init() {
	_ = v1alpha1.AddToScheme(scheme)
}

func main() {
	loader := config.File().OfKind(&v1alpha1.CustomControllerManagerConfiguration{})
	err := loader.InjectScheme(scheme)
	if err != nil {
		fmt.Println("failed to inject scheme")
		os.Exit(1)
	}
	_, err = loader.Complete()
	if err != nil {
		fmt.Println("failed to load config")
		os.Exit(1)
	}
}
Output:

func File

func File() *DeferredFileLoader

File will set up the deferred file loader for the configuration this will also configure the defaults for the loader if nothing is

Defaults:

Path: "./config.yaml"
Kind: GenericControllerManagerConfiguration
Example

This example will load a file using Complete with only defaults set.

package main

import (
	"fmt"
	"os"

	"sigs.k8s.io/controller-runtime/pkg/config"
)

func main() {
	// This will load a config file from ./config.yaml
	loader := config.File()
	_, err := loader.Complete()
	if err != nil {
		fmt.Println("failed to load config")
		os.Exit(1)
	}
}
Output:

func (*DeferredFileLoader) AtPath

func (d *DeferredFileLoader) AtPath(path string) *DeferredFileLoader

AtPath will set the path to load the file for the decoder

func (*DeferredFileLoader) Complete

Complete will use sync.Once to set the scheme

func (*DeferredFileLoader) InjectScheme

func (d *DeferredFileLoader) InjectScheme(scheme *runtime.Scheme) error

InjectScheme will configure the scheme to be used for decoding the file

func (*DeferredFileLoader) OfKind

OfKind will set the type to be used for decoding the file into

Directories

Path Synopsis
Package v1alpha1 provides the ControllerManagerConfiguration used for configuring ctrl.Manager +kubebuilder:object:generate=true
Package v1alpha1 provides the ControllerManagerConfiguration used for configuring ctrl.Manager +kubebuilder:object:generate=true

Jump to

Keyboard shortcuts

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