controllercmd

package
v0.0.0-...-6018a90 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 45 Imported by: 195

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadYAML

func ReadYAML(data []byte, configScheme *runtime.Scheme, versions ...schema.GroupVersion) (runtime.Object, error)

ReadYAML decodes a runtime.Object from the provided scheme TODO versions goes away with more complete scheme in 1.11

func ReadYAMLFile

func ReadYAMLFile(filename string, configScheme *runtime.Scheme, versions ...schema.GroupVersion) (runtime.Object, error)

ReadYAMLFile read a file and decodes a runtime.Object from the provided scheme

Types

type ControllerBuilder

type ControllerBuilder struct {
	// contains filtered or unexported fields
}

ControllerBuilder allows the construction of an controller in optional pieces.

func NewController

func NewController(componentName string, startFunc StartFunc, clock clock.Clock) *ControllerBuilder

NewController returns a builder struct for constructing the command you want to run

func (*ControllerBuilder) Run

Run starts your controller for you. It uses leader election if you asked, otherwise it directly calls you

func (*ControllerBuilder) WithComponentNamespace

func (b *ControllerBuilder) WithComponentNamespace(ns string) *ControllerBuilder

func (*ControllerBuilder) WithComponentOwnerReference

func (b *ControllerBuilder) WithComponentOwnerReference(reference *corev1.ObjectReference) *ControllerBuilder

WithComponentOwnerReference overrides controller reference resolution for event recording

func (*ControllerBuilder) WithEventRecorderOptions

func (b *ControllerBuilder) WithEventRecorderOptions(options record.CorrelatorOptions) *ControllerBuilder

WithEventRecorderOptions allows to override the default Kubernetes event recorder correlator options. This is needed if the binary is sending a lot of events. Using events.DefaultOperatorEventRecorderOptions here makes a good default for normal operator binary.

func (*ControllerBuilder) WithHTTP2

func (b *ControllerBuilder) WithHTTP2() *ControllerBuilder

WithHTTP2 indicates that http2 should be enabled

func (*ControllerBuilder) WithHealthChecks

func (b *ControllerBuilder) WithHealthChecks(healthChecks ...healthz.HealthChecker) *ControllerBuilder

WithHealthChecks adds a list of healthchecks to the server

func (*ControllerBuilder) WithInstanceIdentity

func (b *ControllerBuilder) WithInstanceIdentity(identity string) *ControllerBuilder

WithInstanceIdentity sets the instance identity to use if you need something special. The default is just a UID which is usually fine for a pod.

func (*ControllerBuilder) WithKubeConfigFile

func (b *ControllerBuilder) WithKubeConfigFile(kubeConfigFilename string, defaults *client.ClientConnectionOverrides) *ControllerBuilder

WithKubeConfigFile sets an optional kubeconfig file. inclusterconfig will be used if filename is empty

func (*ControllerBuilder) WithLeaderElection

func (b *ControllerBuilder) WithLeaderElection(leaderElection configv1.LeaderElection, defaultNamespace, defaultName string) *ControllerBuilder

WithLeaderElection adds leader election options

func (*ControllerBuilder) WithRestartOnChange

func (b *ControllerBuilder) WithRestartOnChange(stopCh chan<- struct{}, startingFileContent map[string][]byte, files ...string) *ControllerBuilder

WithRestartOnChange will enable a file observer controller loop that observes changes into specified files. If a change to a file is detected, the specified channel will be closed (allowing to graceful shutdown for other channels).

func (*ControllerBuilder) WithServer

WithServer adds a server that provides metrics and healthz

func (*ControllerBuilder) WithTopologyDetector

func (b *ControllerBuilder) WithTopologyDetector(topologyDetector TopologyDetector) *ControllerBuilder

func (*ControllerBuilder) WithVersion

func (b *ControllerBuilder) WithVersion(info version.Info) *ControllerBuilder

WithVersion accepts a getting that provide binary version information that is used to report build_info information to prometheus

type ControllerCommandConfig

type ControllerCommandConfig struct {

	// DisableServing disables serving metrics, debug and health checks and so on.
	DisableServing bool

	// Allow enabling HTTP2
	EnableHTTP2 bool

	// DisableLeaderElection allows leader election to be suspended
	DisableLeaderElection bool

	// LeaseDuration is the duration that non-leader candidates will
	// wait to force acquire leadership. This is measured against time of
	// last observed ack.
	LeaseDuration metav1.Duration

	// RenewDeadline is the duration that the acting controlplane will retry
	// refreshing leadership before giving up.
	RenewDeadline metav1.Duration

	// RetryPeriod is the duration the LeaderElector clients should wait
	// between tries of actions.
	RetryPeriod metav1.Duration

	// TopologyDetector is used to plug in topology detection.
	TopologyDetector TopologyDetector

	ComponentOwnerReference *corev1.ObjectReference
	// contains filtered or unexported fields
}

ControllerCommandConfig holds values required to construct a command to run.

func NewControllerCommandConfig

func NewControllerCommandConfig(componentName string, version version.Info, startFunc StartFunc, clock clock.Clock) *ControllerCommandConfig

NewControllerConfig returns a new ControllerCommandConfig which can be used to wire up all the boiler plate of a controller TODO add more methods around wiring health checks and the like

func (*ControllerCommandConfig) AddDefaultRotationToConfig

func (c *ControllerCommandConfig) AddDefaultRotationToConfig(config *operatorv1alpha1.GenericOperatorConfig, configContent []byte) (map[string][]byte, []string, error)

AddDefaultRotationToConfig starts the provided builder with the default rotation set (config + serving info). Use StartController if you do not need to customize the controller builder. This method modifies config with self-signed default cert locations if necessary.

func (*ControllerCommandConfig) Config

Config returns the configuration of this command. Use StartController if you don't need to customize the default operator. This method does not modify the receiver.

func (*ControllerCommandConfig) NewCommand

func (c *ControllerCommandConfig) NewCommand() *cobra.Command

NewCommand returns a new command that a caller must set the Use and Descriptions on. It wires default log, profiling, leader election and other "normal" behaviors. Deprecated: Use the NewCommandWithContext instead, this is here to be less disturbing for existing usages.

func (*ControllerCommandConfig) NewCommandWithContext

func (c *ControllerCommandConfig) NewCommandWithContext(ctx context.Context) *cobra.Command

NewCommandWithContext returns a new command that a caller must set the Use and Descriptions on. It wires default log, profiling, leader election and other "normal" behaviors. The context passed will be passed down to controller loops and observers and cancelled on SIGTERM and SIGINT signals.

func (*ControllerCommandConfig) StartController

func (c *ControllerCommandConfig) StartController(ctx context.Context) error

StartController runs the controller. This is the recommend entrypoint when you don't need to customize the builder.

func (*ControllerCommandConfig) WithComponentOwnerReference

func (c *ControllerCommandConfig) WithComponentOwnerReference(reference *corev1.ObjectReference) *ControllerCommandConfig

WithComponentOwnerReference overrides controller reference resolution for event recording

func (*ControllerCommandConfig) WithEventRecorderOptions

func (c *ControllerCommandConfig) WithEventRecorderOptions(eventRecorderOptions record.CorrelatorOptions) *ControllerCommandConfig

func (*ControllerCommandConfig) WithHealthChecks

func (c *ControllerCommandConfig) WithHealthChecks(healthChecks ...healthz.HealthChecker) *ControllerCommandConfig

func (*ControllerCommandConfig) WithTopologyDetector

func (c *ControllerCommandConfig) WithTopologyDetector(topologyDetector TopologyDetector) *ControllerCommandConfig

type ControllerContext

type ControllerContext struct {
	ComponentConfig *unstructured.Unstructured

	// Clock is a potentially fake clock that must be used to run controllers.
	Clock clock.Clock

	// KubeConfig provides the REST config with no content type (it will default to JSON).
	// Use this config for CR resources.
	KubeConfig *rest.Config

	// ProtoKubeConfig provides the REST config with "application/vnd.kubernetes.protobuf,application/json" content type.
	// Note that this config might not be safe for CR resources, instead it should be used for other resources.
	ProtoKubeConfig *rest.Config

	// EventRecorder is used to record events in controllers.
	EventRecorder events.Recorder

	// Server is the GenericAPIServer serving healthz checks and debug info
	Server *genericapiserver.GenericAPIServer

	// Namespace where the operator runs. Either specified on the command line or autodetected.
	OperatorNamespace string
}

type ControllerFlags

type ControllerFlags struct {
	// ConfigFile hold the configfile to load
	ConfigFile string
	// KubeConfigFile points to a kubeconfig file if you don't want to use the in cluster config
	KubeConfigFile string
	// Namespace points to a base namespace for the controller and related events
	Namespace string
	// BindAddress is the ip:port to serve on
	BindAddress string
	// TerminateOnFiles is a list of files. If any of these changes, the process terminates.
	TerminateOnFiles []string
}

ControllerFlags provides the "normal" controller flags

func NewControllerFlags

func NewControllerFlags() *ControllerFlags

NewControllerFlags returns flags with default values set

func (*ControllerFlags) AddFlags

func (f *ControllerFlags) AddFlags(cmd *cobra.Command)

AddFlags register and binds the default flags

func (*ControllerFlags) ToClientConfig

func (f *ControllerFlags) ToClientConfig(overrides *client.ClientConnectionOverrides) (*rest.Config, error)

ToClientConfig given completed flags, returns a rest.Config. overrides are optional

func (*ControllerFlags) ToConfigObj

func (f *ControllerFlags) ToConfigObj() ([]byte, *unstructured.Unstructured, error)

ToConfigObj given completed flags, returns a config object for the flag that was specified. TODO versions goes away in 1.11

func (*ControllerFlags) Validate

func (o *ControllerFlags) Validate() error

Validate makes sure the required flags are specified and no illegal combinations are found

type StartFunc

type StartFunc func(context.Context, *ControllerContext) error

StartFunc is the function to call on leader election start

type TopologyDetector

type TopologyDetector interface {
	DetectTopology(ctx context.Context, restClient *rest.Config) (configv1.TopologyMode, error)
}

Jump to

Keyboard shortcuts

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