controller

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OnCreateAndUpdateFilter = predicate.Funcs{
	CreateFunc: func(e event.CreateEvent) bool {
		return e.Object != nil
	},
	UpdateFunc: func(e event.UpdateEvent) bool {
		return e.ObjectNew != nil
	},
	DeleteFunc: func(_ event.DeleteEvent) bool {
		return false
	},
}

OnCreateAndUpdateFilter is an event filter that keeps only create and update events, and not deletes.

Functions

func DeclareOwner

func DeclareOwner(ip *v1beta1.NetBoxIP, obj client.Object) error

DeclareOwner sets the provided object as the controller of the given NetBoxIP.

func HasPublishLabels added in v0.2.0

func HasPublishLabels(publishLabels map[string]bool, objLabels map[string]string) bool

HasPublishLabels checks if the given object labels contain any of the publish labels (i.e. labels that indicate its IP should be exported).

func NetBoxIPName

func NetBoxIPName(obj client.Object, suffix string) string

NetBoxIPName derives NetBoxIP name from the object's metadata. suffix may be an empty string, in which case it is ignored. Otherwise, it is appended to the returned name to provide additional context to the IP (such as including the IP address' scheme as part of the name)

func Scheme

func Scheme(ip netip.Addr) string

Scheme returns the name of the scheme of the given IP (ipv4 or ipv6), or an empty string if ip is not a valid IP address.

func UpsertNetBoxIP

func UpsertNetBoxIP(ctx context.Context, kubeClient client.Client, ll *log.Logger, ip *v1beta1.NetBoxIP) error

UpsertNetBoxIP creates or updates (if exists) the NetBoxIP provided.

Types

type Controller

type Controller interface {
	AddToManager(manager.Manager) error
}

Controller is responsible for updating IPs of a single k8s resource.

type IPs

type IPs struct {
	IPv4 *v1beta1.NetBoxIP
	IPv6 *v1beta1.NetBoxIP
}

IPs is a struct used to store the NetBoxIPs belonging to a pod or service. A nil value means the pod or service does not have an IP of that scheme. If dual stack is not enabled, at least one of the two IPs will be nil

func CreateNetBoxIPs

func CreateNetBoxIPs(ips []string, config NetBoxIPConfig) (*IPs, error)

CreateNetBoxIPs takes a slice of IP addresses in string form and creates NetBoxIPs according to the configuration specified by config The IP addresses are returned in the form of an IPs struct. If IPv4 or IPv6 is nil in the returned struct, that means no IP address of that scheme was given as input

type NetBoxIPConfig

type NetBoxIPConfig struct {
	Object           client.Object
	DNSName          string
	ReconcilerTags   []netbox.Tag
	ReconcilerLabels map[string]bool
}

NetBoxIPConfig is a struct used to pass configuration parameters for the NetBoxIPs created by CreateNetBoxIPs

type Option

type Option func(*Settings) error

Option can be used to tune controller settings.

func WithClusterDomain

func WithClusterDomain(domain string) Option

WithClusterDomain sets the k8s cluster domain name.

func WithDualStackIP

func WithDualStackIP() Option

WithDualStackIP enables registering both IPv6 and IPv4 address in netbox for dual stack pods and services.

func WithLabels

func WithLabels(labels map[string]bool) Option

WithLabels sets the k8s object labels that are added to the description of every IP published by the controller.

func WithLogger

func WithLogger(logger *log.Logger) Option

WithLogger sets the logger to be used by the controller.

func WithNetBoxClient

func WithNetBoxClient(client netbox.Client) Option

WithNetBoxClient sets the NetBox client to be used by the controller.

func WithTags

func WithTags(tags []string, netboxClient netbox.Client) Option

WithTags sets the tags that are applied to every IP published by the controller.

type Settings

type Settings struct {
	NetBoxClient  netbox.Client
	Tags          []netbox.Tag
	Labels        map[string]bool
	ClusterDomain string
	Logger        *log.Logger
	DualStackIP   bool
}

Settings specify configuration of a controller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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