configgen

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

README

Config-gen

kubebuilder alpha config-gen is a subcommand that generates configuration for kubebuilder projects as a configuration function.

Supports:

  • Generating CRDs and RBAC from code
  • Generating webhook certificates for development
  • Selectively enabling / disabling components such as prometheus and webhooks

Usage

config-gen may be run as a standalone command or from kustomize as a transformer plugin.

Standalone command

config-gen may be run as a standalone program on the commandline.

See examples/standalone

From kustomize

config-gen may be run as a Kustomize plugin using kustomize.

See examples/kustomize

Extending config-gen

config-gen may be extended by composing additional functions on top of it.

See examples of layering additional functions on:

KubebuilderConfigGen

See types.go for KubebuilderConfigGen schema.

See testdata for examples of configuration options.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRDPatchTemplate

func CRDPatchTemplate(kp *KubebuilderConfigGen) framework.PT

CRDPatchTemplate returns the PatchTemplate for crd

func CertManagerPatchTemplate

func CertManagerPatchTemplate(_ *KubebuilderConfigGen) framework.PT

CertManagerPatchTemplate returns the PatchTemplate for cert-manager

func ControllerManagerPatchTemplate

func ControllerManagerPatchTemplate(kp *KubebuilderConfigGen) framework.PT

ControllerManagerPatchTemplate returns the PatchTemplate for controller-manager

func NewCommand

func NewCommand() *cobra.Command

NewCommand returns a new cobra command

Types

type CRDs

type CRDs struct {
	// SourceDirectory is the go project directory containing source code marked up with controller-gen tags.
	// Defaults to the directory containing the KubebuilderConfigGen configuration file.
	// +optional
	SourceDirectory string `json:"sourceDirectory,omitempty" yaml:"sourceDirectory,omitempty"`
}

CRDs configures how controller-gen is run against the project go source code in order to generate CRDs and RBAC.

type CertFilter

type CertFilter struct {
	*KubebuilderConfigGen
}

CertFilter generates and injects certificates into webhook

func (CertFilter) Filter

func (c CertFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

Filter implements kio.Filter TODO: when v1 CRDs are supported, scaffold conversion webhook versions.

type CertManagerCertificate

type CertManagerCertificate struct {
}

CertManagerCertificate will generate cert-manager.io/v1 Issuer and Certificate resources.

type CertificateSource

type CertificateSource struct {
	// Type is a discriminator for this union.
	// One of: ["certManager", "dev", "manual"].
	// Defaults to "manual".
	Type string `json:"type,omitempty" yaml:"type,omitempty"`

	// ManualCertificate requires the user to provide a certificate.
	// Requires "manual" as the type.
	ManualCertificate *ManualCertificate `json:"manualCertificate,omitempty" yaml:"manualCertificate,omitempty"`

	// CertManagerCertificate relies on the certificate manager operator installed separately.
	// Requires "certManager" as the type.
	//nolint:lll
	CertManagerCertificate *CertManagerCertificate `json:"certManagerCertificate,omitempty" yaml:"certManagerCertificate,omitempty"`

	// GenerateCert will generate self signed certificate and inject it into the caBundles.
	// For development only, not a production grade solution.
	// Requires "dev" as the type.
	DevCertificate *DevCertificate `json:"devCertificate,omitempty" yaml:"devCertificate,omitempty"`
}

CertificateSource configures where to get webhook certificates from. It is a discriminated union.

type ComponentConfig

type ComponentConfig struct {
	// Enable if set to true will use component config rather than flags.
	Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`

	// ConfigFilepath is the relative path to a file containing component config.
	ConfigFilepath string `json:"configFilepath,omitempty" yaml:"configFilepath,omitempty"`
}

ComponentConfig configures how to setup the controller-manager to use component config rather than flag driven options.

type ComponentFilter

type ComponentFilter struct {
	*KubebuilderConfigGen
}

ComponentFilter inserts the component config read from disk into the ConfigMap

func (ComponentFilter) Filter

func (cf ComponentFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

Filter sets the component config in the configmap

type ControllerGenFilter

type ControllerGenFilter struct {
	*KubebuilderConfigGen
}

ControllerGenFilter generates resources from go code using the controller-gen libraries

func (ControllerGenFilter) Filter

func (cgr ControllerGenFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

Filter implements kio.Filter

type ControllerManager

type ControllerManager struct {
	// Image is the container image to run as the controller-manager.
	Image string `json:"image,omitempty" yaml:"image,omitempty"`

	// Metrics configures how prometheus metrics are exposed.
	Metrics Metrics `json:"metrics,omitempty" yaml:"metrics,omitempty"`

	// ComponentConfig configures how the controller-manager is configured.
	// +optional
	ComponentConfig ComponentConfig `json:"componentConfig,omitempty" yaml:"componentConfig,omitempty"`
}

ControllerManager configures how the controller-manager resources are generated.

type DevCertificate

type DevCertificate struct {
	// CertDuration sets the duration for the generated cert.  Defaults to 1 hour.
	CertDuration time.Duration `json:"certDuration,omitempty" yaml:"certDuration,omitempty"`
}

DevCertificate generates a certificate for development purposes and wires it into the appropriate locations.

type KubebuilderConfigGen

type KubebuilderConfigGen struct {
	metav1.TypeMeta `json:",inline" yaml:",omitempty"`

	// ObjectMeta has metadata about the object
	ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// Spec is the configuration spec defining what configuration should be produced.
	Spec KubebuilderConfigGenSpec `json:"spec,omitempty" yaml:"spec,omitempty"`

	// Status is the configuration status defined at runtime.
	Status KubebuilderConfigGenStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

KubebuilderConfigGen implements the API for generating configuration

func (*KubebuilderConfigGen) Default

func (kp *KubebuilderConfigGen) Default() error

Default defaults the values

type KubebuilderConfigGenSpec

type KubebuilderConfigGenSpec struct {
	// CRDs configures how CRDs + related RBAC and Webhook resources are generated.
	CRDs CRDs `json:"crds,omitempty" yaml:"crds,omitempty"`

	// ControllerManager configures how the controller-manager Deployment is generated.
	ControllerManager ControllerManager `json:"controllerManager,omitempty" yaml:"controllerManager,omitempty"`

	// Webhooks configures how webhooks and certificates are generated.
	Webhooks Webhooks `json:"webhooks,omitempty" yaml:"webhooks,omitempty"`
}

KubebuilderConfigGenSpec defines the desired configuration to be generated

type KubebuilderConfigGenStatus

type KubebuilderConfigGenStatus struct {
	// CertCA is the CertCA generated at runtime.
	CertCA string

	// CertKey is the CertKey generated at runtime.
	CertKey string

	// ComponentConfigString is the contents of the component config file read from disk.
	ComponentConfigString string
}

KubebuilderConfigGenStatus is runtime status for the api configuration. It is used to pass values generated at runtime (not directly specified by users) to templates.

type ManualCertificate

type ManualCertificate struct {
}

ManualCertificate will not generate any certificate, and requires the user to manually specify and wire one in.

type Metrics

type Metrics struct {
	// DisableAuthProxy if set to true will disable the auth proxy
	// +optional
	DisableAuthProxy bool `json:"disableAuthProxy,omitempty" yaml:"disableAuthProxy,omitempty"`

	// EnableServiceMonitor if set to true with generate the prometheus ServiceMonitor resource
	// +optional
	EnableServiceMonitor bool `json:"enableServiceMonitor,omitempty" yaml:"enableServiceMonitor,omitempty"`
}

Metrics configures how prometheus metrics are exposed from the controller.

type ObjectMeta

type ObjectMeta struct {
	// Name is used to generate the names of resources.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Namespace defines the namespace for the controller resources.
	// Must be a DNS_LABEL.
	// More info: http://kubernetes.io/docs/user-guide/namespaces
	// Defaults to "${name}-system" -- e.g. if name is "foo", then namespace defaults
	// to "foo-system"
	// +optional
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`

	// Map of string keys and values that can be used to organize and categorize
	// (scope and select) objects. May match selectors of replication controllers
	// and services.
	// More info: http://kubernetes.io/docs/user-guide/labels
	// +optional
	Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`

	// Annotations is an unstructured key value map stored with a resource that may be
	// set by external tools to store and retrieve arbitrary metadata. They are not
	// queryable and should be preserved when modifying objects.
	// More info: http://kubernetes.io/docs/user-guide/annotations
	// +optional
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

ObjectMeta contains metadata about the resource

type SortFilter

type SortFilter struct {
	*KubebuilderConfigGen
}

SortFilter sorts resources so they are installed in the right order

func (SortFilter) Filter

func (cgr SortFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

Filter implements kio.Filter

type Webhooks

type Webhooks struct {
	// Enable if set to true will generate webhook configurations.
	Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`

	// Conversions configures which resource types to enable conversion webhooks for.
	// Conversion will be set in the CRDs for these resource types.
	// The key is the CRD name.
	// Note: This is a map rather than a list so it can be overridden when patched or merged.
	Conversions map[string]bool `json:"conversions,omitempty" yaml:"conversions,omitempty"`

	// CertificateSource defines where to get the webhook certificates from.
	CertificateSource CertificateSource `json:"certificateSource,omitempty" yaml:"certificateSource,omitempty"`
}

Webhooks configures how webhooks are generated.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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