informers

package
v0.0.0-...-82afb99 Latest Latest
Warning

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

Go to latest
Published: May 16, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NewInformerFunc

type NewInformerFunc func() cache.SharedIndexInformer

NewInformerFunc is a simple factory for creating a new informer

type SharedInformers

type SharedInformers interface {
	// InformerFor registers an informer for the given type. If an informer for the given type has not been
	// registered before, the given constructor function is called to construct the informer.
	InformerFor(runtime.Object, NewInformerFunc) cache.SharedIndexInformer
	// WaitForCacheSync waits for all started informers' cache were synced.
	WaitForCacheSync(context.Context) error
	// Run starts all registered informers.
	Run(context.Context) error
}

SharedInformers allows controllers to register informers that watch the Kubernetes API for changes in various API types and maintain a local cache of those objects.

Example
package main

import (
	"time"

	appsv1 "k8s.io/api/apps/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	appsv1_informers "k8s.io/client-go/informers/apps/v1"

	clientset "k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/cache"

	"github.com/ianlewis/controllerutil/informers"
)

func main() {
	config, _ := rest.InClusterConfig()
	client, _ := clientset.NewForConfig(config)

	i := informers.NewSharedInformers()
	i.InformerFor(
		&appsv1.Deployment{},
		func() cache.SharedIndexInformer {
			return appsv1_informers.NewDeploymentInformer(
				client,
				metav1.NamespaceAll,
				12*time.Hour,
				cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
			)
		},
	)
}
Output:

func NewSharedInformers

func NewSharedInformers() SharedInformers

NewSharedInformers creates an empty SharedInformers instance.

Jump to

Keyboard shortcuts

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