polling

package
v0.36.0-flux.11 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package polling is a library for computing the status of kubernetes resources based on polling of resource state from a cluster. It can keep polling until either some condition is met, or until it is cancelled through the provided context. Updates on the status of resources are streamed back to the caller through a channel.

This package provides a simple interface based on the built-in features. But the actual code is in the subpackages and there are several interfaces that can be implemented to support custom behavior.

Polling Resources

In order to poll a set of resources, create a StatusPoller and pass in the list of ResourceIdentifiers to the Poll function.

import (
  "github.com/fluxcd/cli-utils/pkg/kstatus/polling"
)

identifiers := []prune.ObjMetadata{
  {
    GroupKind: schema.GroupKind{
      Group: "apps",
      Kind: "Deployment",
    },
    Name: "dep",
    Namespace: "default",
  }
}

poller := polling.NewStatusPoller(reader, mapper, true)
eventsChan := poller.Poll(context.Background(), identifiers, polling.PollOptions{})
for e := range eventsChan {
   // Handle event
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// CustomStatusReaders specifies any implementations of the engine.StatusReader interface that will
	// be used to compute reconcile status for resources.
	CustomStatusReaders []engine.StatusReader

	// ClusterReaderFactory allows for custom implementations of the engine.ClusterReader interface
	// in the StatusPoller. The default implementation if the clusterreader.CachingClusterReader.
	ClusterReaderFactory engine.ClusterReaderFactory
}

Options can be provided when creating a new StatusPoller to customize the behavior.

type PollOptions

type PollOptions struct {
	// PollInterval defines how often the PollerEngine should poll the cluster for the latest
	// state of the resources.
	PollInterval time.Duration
}

PollOptions defines the levers available for tuning the behavior of the StatusPoller.

type StatusPoller

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

StatusPoller provides functionality for polling a cluster for status for a set of resources.

func NewStatusPoller

func NewStatusPoller(reader client.Reader, mapper meta.RESTMapper, o Options) *StatusPoller

NewStatusPoller creates a new StatusPoller using the given clusterreader and mapper. The StatusPoller will use the client for all calls to the cluster.

func NewStatusPollerFromFactory

func NewStatusPollerFromFactory(f cmdutil.Factory, o Options) (*StatusPoller, error)

NewStatusPollerFromFactory creates a new StatusPoller instance from the passed in factory.

func (*StatusPoller) Poll

func (s *StatusPoller) Poll(ctx context.Context, identifiers object.ObjMetadataSet, options PollOptions) <-chan event.Event

Poll will create a new statusPollerRunner that will poll all the resources provided and report their status back on the event channel returned. The statusPollerRunner can be cancelled at any time by cancelling the context passed in.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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