polling

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: Apache-2.0 Imports: 11 Imported by: 35

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 (
  "sigs.k8s.io/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.Options{})
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 {
	// PollInterval defines how often the PollerEngine should poll the cluster for the latest
	// state of the resources.
	PollInterval time.Duration

	// UseCache defines whether the ClusterReader should use LIST calls to fetch
	// all needed resources before each polling cycle. If this is set to false,
	// then each resource will be fetched when needed with GET calls.
	UseCache bool
}

Options 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) *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 (*StatusPoller) Poll

func (s *StatusPoller) Poll(ctx context.Context, identifiers []object.ObjMetadata, options Options) <-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