watcher

package
v0.0.0-...-7d6da81 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventParameters

type EventParameters struct {
	v1alpha1.WatchRequest
	Type        pb.EventType
	ClusterName string
	Object      *unstructured.Unstructured
	TimeStamp   time.Time
}

EventParameters is used to send the event related info to GRPCClient

type GRPCClient

type GRPCClient interface {
	SendEvent(ctx context.Context, params EventParameters) (pb.ResponseType, error)
	GetServerParams() (addr, port string)
}

GRPCClient sends events to the edgewatcher server

type Params

type Params struct {
	v1alpha1.WatchRequest

	// InvokeWatcherAgentController is provided by watcheragent controller to
	// invoke the controller's Reconcile(https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Func.Reconcile)
	// func with the correct request (https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Request).
	// This is needed for notifying the controller to update the resourceVersion
	// of a watch in the v1alpha1.WatcherAgentStatus.
	InvokeWatcherAgentController func()

	Clock             clock.Clock
	ResourceInterface dynamic.ResourceInterface
	ClusterName       string
}

Params is used to initialize Watcher

type Watcher

type Watcher struct {
	Cancel context.CancelFunc

	*Params

	// ResourceVersionCh carries the most recent resourceVersion from
	// cache.Reflector for a one time read by watcheragent controller
	ResourceVersionCh chan string
	// contains filtered or unexported fields
}

Watcher watches the k8s resources using cache.Reflector(https://pkg.go.dev/k8s.io/client-go/tools/cache#Reflector). It creates a watcherStore (which implements cache.Store[https://pkg.go.dev/k8s.io/client-go/tools/cache#Store]), which is passed on to cache.Reflector. watcherStore then sends the events provided by cache.Reflector to the GRPCClient. It also sends the current resourceVersion to the watcheragent controller. It first puts the new resourceVersion in the ResourceVersionCh (replacing the old one if present), then it invokes the controller's Reconcile func with the correct ctrl.Request(https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Request) using the Params.InvokeWatcherAgentController func.

func New

func New(ctx context.Context, logger logr.Logger, params *Params, grpcClient GRPCClient) *Watcher

New returns a new Watcher

func (*Watcher) GetGRPCClient

func (w *Watcher) GetGRPCClient() GRPCClient

func (*Watcher) GetRestartCount

func (w *Watcher) GetRestartCount() int

func (*Watcher) ReSync

func (w *Watcher) ReSync(ctx context.Context, source string) error

func (*Watcher) Run

func (w *Watcher) Run()

Run creates a new cache.Reflector and watcherStore and sets them to watch the given resources. It recreates the reflector whenever an error is received since reflector doesn't provide method to forcefully re-list.

func (*Watcher) SetGRPCClient

func (w *Watcher) SetGRPCClient(client GRPCClient)

Jump to

Keyboard shortcuts

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