detector

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Example usage:

Setting up the detector:

    //you would most likely have this code in your main.go
    dc, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
    if err != nil {
        panic("Could not create discovery client")
    }

    d, err := detector.NewAutoDetect(dc)
    if err != nil {
        panic("error creating autodetector: " + err.Error())
    }

    d.Start(5 * time.Second) //scan for new CRDs every 5 seconds

Triggering an action when a particular CRD shows up:

    // and pass this detector instance to the `add` function of your operator's controller, where you could run:
    d.AddCRDTrigger(&package.CRD{
        TypeMeta: metav1.TypeMeta{
            Kind:       package.CrdKind,
            APIVersion: package.SchemeGroupVersion.String(),
        },
    }, func(crd runtime.Object) {
        // Do actions now that the package.CRD exists in the API, e.g begin watching it:
        c.Watch(&source.Kind{Type: &package.CRD{}}, &EnqueueForObject{})
    })

Triggering an action when any of multiple CRDs show up:

    // and pass this detector instance to the `add` function of your operator's controller, where you could run:
    d.AddCRDsTrigger([]runtime.Object{
        &package.CRD{
            TypeMeta: metav1.TypeMeta{
                Kind:       package.CrdKind,
                APIVersion: package.SchemeGroupVersion.String(),
            },
        },
        &package.OtherCrd{
            TypeMeta: metav1.TypeMeta{
                Kind: package.OtherCrdKind:
                APIVersion: package.SchemeGroupVersion.String(),
            },
        },
    }, func(crd runtime.Object) {
        // Do actions now that the package.CRD exists in the API, e.g begin watching it:
        c.Watch(&source.Kind{Type: crd}, &EnqueueForObject{})
    })

Documentation

Index

Constants

View Source
const (
	RealmLabelSelectorsKey = "realmLabelSelectors"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

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

Detector represents a procedure that runs in the background, periodically auto-detecting features

func NewAutoDetect

func NewAutoDetect(dc discovery.DiscoveryInterface) (*Detector, error)

New creates a new auto-detect runner

func (*Detector) AddCRDTrigger

func (d *Detector) AddCRDTrigger(crd runtime.Object, trigger trigger)

AddCRDTrigger to run the trigger function, the first time that the background scanner discovers that the CRD type specified exists

func (*Detector) AddCRDsTrigger

func (d *Detector) AddCRDsTrigger(crds []runtime.Object, trigger trigger)

AddCRDsTrigger to run the trigger function, the first time that the background scanner discovers that each of the CRD types specified exists

func (*Detector) AddCRDsWithTriggers

func (d *Detector) AddCRDsWithTriggers(crdsTriggers map[runtime.Object]trigger)

AddCRDsWithTriggers to run the associated trigger function for the particular CRD, the first time that the background scanner discovers that the CRD type specified exists

func (*Detector) Start

func (d *Detector) Start(interval time.Duration)

Start initializes the auto-detection process that runs in the background

func (*Detector) Stop

func (d *Detector) Stop()

Stop causes the background process to stop auto detecting capabilities

type StateManager

type StateManager struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

func GetStateManager

func GetStateManager() *StateManager

func (*StateManager) Clear

func (sm *StateManager) Clear()

func (*StateManager) GetState

func (sm *StateManager) GetState(key string) interface{}

func (*StateManager) SetState

func (sm *StateManager) SetState(key string, value interface{})

Jump to

Keyboard shortcuts

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