common

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplicateTo         = "kube-external-sync.io/replicate-to"
	ReplicateToMatching = "kube-external-sync.io/replicate-to-matching"
	StripLabels         = "kube-external-sync.io/strip-labels"
	StripAnnotations    = "kube-external-sync.io/strip-annotations"
	TopLevelDomain      = "kube-external-sync.io/top-level-domain"
	TLDSecretName       = "kube-external-sync.io/tld-secret-name"
	ExternalNameSuffix  = "kube-external-sync.io/external-name-suffix"
	KeepOwnerReferences = "kube-external-sync.io/keep-owner-references"
)

Annotations that are added to resources and used by this Controller

View Source
const (
	ReplicatedFromAnnotation        = "kube-external-sync.io/replicated-from"
	ReplicatedAtAnnotation          = "kube-external-sync.io/replicated-at"
	ReplicatedFromVersionAnnotation = "kube-external-sync.io/replicated-from-version"
)

Annotations that are added to replicated resources by this Controller

View Source
const (
	DefaultExternalNameSuffix     = "svc.cluster.local"
	TraefikMeshExternalNameSuffix = "traefik.mesh"
)

ExternalName suffix options

View Source
const LastAppliedConfigurationAnnotationKey = "kubectl.kubernetes.io/last-applied-configuration"

LastAppliedConfigurationAnnotationKey is an annotation created by Kubernetes to keep track of last config

View Source
const ManagedByLabelKey = "app.kubernetes.io/managed-by"

ManagedByLabelKey is an label key appended to kube-external-sync managed resources.

View Source
const ManagedByLabelValue = "kube-external-sync"

ManagedByLabelValue is an label value appended to kube-external-sync managed resources.

Variables

DefaultStripAnnotations contains the annotations that are to be stripped when replicating a resource

Functions

func BuildStrictRegex

func BuildStrictRegex(regex string) string

func CompileStrictRegex

func CompileStrictRegex(pattern string) (*regexp.Regexp, error)

func CopyAnnotations

func CopyAnnotations(m map[string]string) map[string]string

CopyAnnotations copies all non-controlled annotations

func CopyLabels

func CopyLabels(m map[string]string) map[string]string

CopyLabels copies all non-controlled Labels

func IsManagedBy

func IsManagedBy(source metav1.Object) bool

IsManagedBy checks the sources labels to see if the resource is currently being managed-by this controller

func MatchStrictRegex

func MatchStrictRegex(pattern, str string) (bool, error)

func MustGetKey

func MustGetKey(obj interface{}) string

MustGetKey creates a key from Kubernetes resource in the format <namespace>/<name>

func MustGetObject

func MustGetObject(obj interface{}) metav1.Object

MustGetObject casts the object into a Kubernetes `metav1.Object`

func PrepareAnnotations

func PrepareAnnotations(source metav1.ObjectMeta) map[string]string

PrepareAnnotations prepares a new map of annotations based on the provided resource

func PrepareLabels

func PrepareLabels(source metav1.ObjectMeta) map[string]string

PrepareLabels prepares a new map of labels based on the provided resource

func PrepareOwnerReferences

func PrepareOwnerReferences(source metav1.ObjectMeta) []metav1.OwnerReference

PrepareOwnerReferences prepares the OwnerReferences array

func PrepareTLD added in v1.1.0

func PrepareTLD(namespace, tld string) string

func StringToPatternList

func StringToPatternList(list string) (result []*regexp.Regexp)

Types

type AddFunc

type AddFunc func(obj *v1.Namespace)

type GenericReplicator

type GenericReplicator struct {
	ReplicatorConfig
	Store      cache.Store
	Controller cache.Controller
	Context    context.Context

	UpdateFuncs UpdateFuncs

	// ReplicateToList is a set that caches the names of all resources that have a
	// "replicate-to" annotation.
	ReplicateToList map[string]struct{}

	// ReplicateToMatchingList is a set that caches the names of all resources
	// that have a "replicate-to-matching" annotation.
	ReplicateToMatchingList map[string]labels.Selector
}

GenericReplicator represents the top-level Replicator

func NewGenericReplicator

func NewGenericReplicator(ctx context.Context, config ReplicatorConfig) *GenericReplicator

NewGenericReplicator creates a new GenericReplicator

func (*GenericReplicator) HasDefaultIngressHostname added in v1.2.0

func (r *GenericReplicator) HasDefaultIngressHostname() bool

HasDefaultIngressHostname returns a boolean value determining whether or not a default Ingress hostname was provided.

func (*GenericReplicator) ListFilteredNamespaces

func (r *GenericReplicator) ListFilteredNamespaces(current string, patterns string) ([]v1.Namespace, error)

ListFilteredNamespaces retrieve list of namespaces that match the provided patterns

func (*GenericReplicator) ListLabelSelectedNamespaces

func (r *GenericReplicator) ListLabelSelectedNamespaces(namespaceSelectorString string) ([]v1.Namespace, error)

ListLabelSelectedNamespaces retrieves list of namespaces that meet the label selector

func (*GenericReplicator) ListNamespaces

func (r *GenericReplicator) ListNamespaces(listOptions ...metav1.ListOptions) ([]v1.Namespace, error)

ListNamespaces is a simple wrapper for listing namespaces

func (*GenericReplicator) NamespaceAdded

func (r *GenericReplicator) NamespaceAdded(ns *v1.Namespace)

NamespaceAdded replicates resources with ReplicateTo and ReplicateToMatching annotations into newly created namespaces.

func (*GenericReplicator) NamespaceUpdated

func (r *GenericReplicator) NamespaceUpdated(nsOld *v1.Namespace, nsNew *v1.Namespace)

NamespaceUpdated checks if namespace's labels changed and deletes any 'replicate-to-matching' resources the namespace no longer qualifies for. Then it attempts to replicate resources into the updated ns based on the updated set of labels

func (*GenericReplicator) ObjectFromStore

func (r *GenericReplicator) ObjectFromStore(key string) (interface{}, error)

ObjectFromStore gets object from store cache

func (*GenericReplicator) ResourceAdded

func (r *GenericReplicator) ResourceAdded(obj interface{})

ResourceAdded checks resources with ReplicateTo or ReplicateFromAnnotation annotation

func (*GenericReplicator) ResourceDeleted

func (r *GenericReplicator) ResourceDeleted(source interface{})

ResourceDeleted watches for the deletion of resources

func (*GenericReplicator) ResourceUpdated

func (r *GenericReplicator) ResourceUpdated(old interface{}, new interface{})

ResourceUpdated checks resources with ReplicateTo or ReplicateFromAnnotation annotation

func (*GenericReplicator) Run

func (r *GenericReplicator) Run()

Run starts the controller

func (*GenericReplicator) Synced

func (r *GenericReplicator) Synced() bool

Synced reports whether or not the controller has been synced

type NamespaceWatcher

type NamespaceWatcher struct {
	NamespaceStore      cache.Store
	NamespaceController cache.Controller

	AddFuncs    []AddFunc
	UpdateFuncs []UpdateFunc
	// contains filtered or unexported fields
}

func (*NamespaceWatcher) OnNamespaceAdded

func (nw *NamespaceWatcher) OnNamespaceAdded(ctx context.Context, client kubernetes.Interface, resyncPeriod time.Duration, addFunc AddFunc)

OnNamespaceAdded will add another method to a list of functions to be called when a new namespace is created

func (*NamespaceWatcher) OnNamespaceUpdated

func (nw *NamespaceWatcher) OnNamespaceUpdated(ctx context.Context, client kubernetes.Interface, resyncPeriod time.Duration, updateFunc UpdateFunc)

OnNamespaceUpdated will add another method to a list of functions to be called when a namespace is updated

type Replicator

type Replicator interface {
	Run()
	Synced() bool
	NamespaceAdded(ns *v1.Namespace)
}

type ReplicatorConfig

type ReplicatorConfig struct {
	Kind                   string
	Client                 kubernetes.Interface
	TraefikClient          *versioned.Clientset
	ResyncPeriod           time.Duration
	DefaultIngressHostname string
	ListFunc               cache.ListFunc
	WatchFunc              cache.WatchFunc
	ObjType                runtime.Object
}

ReplicatorConfig represents configuration for individual resource controllers

type UpdateFunc

type UpdateFunc func(old *v1.Namespace, new *v1.Namespace)

type UpdateFuncs

type UpdateFuncs struct {
	ReplicateDataFrom        func(source interface{}, target interface{}) error
	ReplicateObjectTo        func(source interface{}, target *v1.Namespace) error
	DeleteReplicatedResource func(target interface{}) error
}

UpdateFuncs stores the resource updater functions

Jump to

Keyboard shortcuts

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