context

package
v1.0.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Binding Context Generator

Binding Context Generator allows to generate binding context values for hook testing purpose.

Usage example:

  1. Declare the hook config
config := `
configVersion: v1
schedule:
- name: every_minute
  crontab: '* * * * *'
  includeSnapshotsFrom:
  - pod
kubernetes:
- apiVersion: v1
  name: pod
  kind: Pod
  watchEvent:
  - Added
  - Modified
  - Deleted
  namespace:
    nameSelector:
      matchNames:
      - default`
  1. Declare initial state of kubernetes objects
initialState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
`
  1. Declare new state (one of pods are deleted)
newState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
`
  1. Create new binding context controller
c, err := context.NewBindingContextController(config, initialState)
if err != nil {
  return err
}
  1. Register CRD (if you use some in tests) in format [Group, Version, Kind, isNamespaced]:
c.RegisterCRD("example.com", "v1", "Example", true)
c.RegisterCRD("example.com", "v1", "ClusterExample", false)
  1. Run controller to get initial binding context
contexts, err := c.Run()
if err != nil {
  return err
}
testContexts(contexts)
  1. Change state to new get binding contexts
contexts, err = c.ChangeState(newState)
if err != nil {
  return err
}
testNewContexts(contexts)
  1. Run schedule to get binding contexts
contexts, err = c.RunSchedule("* * * * *")
if err != nil {
  return err
}
testScheduleContexts(contexts)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FakeCluster *fake.FakeCluster

FakeCluster is global for now. It can be encapsulated in BindingContextController lately.

Functions

This section is empty.

Types

type BindingContextController

type BindingContextController struct {
	Hook       *hook.Hook
	HookCtrl   controller.HookController
	HookMap    map[string]string
	HookConfig string

	Controller        *StateController
	KubeEventsManager kubeeventsmanager.KubeEventsManager
	ScheduleManager   schedulemanager.ScheduleManager

	UpdateTimeout time.Duration
}

func NewBindingContextController

func NewBindingContextController(config string) (*BindingContextController, error)

func (*BindingContextController) ChangeState

func (b *BindingContextController) ChangeState(newState ...string) (GeneratedBindingContexts, error)

func (*BindingContextController) ChangeStateAndWaitForBindingContexts

func (b *BindingContextController) ChangeStateAndWaitForBindingContexts(desiredQuantity int, newState string) (GeneratedBindingContexts, error)

func (*BindingContextController) RegisterCRD

func (b *BindingContextController) RegisterCRD(group, version, kind string, namespaced bool)

RegisterCRD registers custom resources for the cluster

func (*BindingContextController) Run

BindingContextsGenerator generates binding contexts for hook tests

func (*BindingContextController) RunSchedule

func (*BindingContextController) Stop

func (b *BindingContextController) Stop()

func (*BindingContextController) WithHook

func (b *BindingContextController) WithHook(h *hook.Hook)

type GeneratedBindingContexts

type GeneratedBindingContexts struct {
	Rendered        string
	BindingContexts []BindingContext
}

type StateController

type StateController struct {
	CurrentState map[string]manifest.Manifest
}

StateController holds objects state for FakeCluster

func NewStateController

func NewStateController() *StateController

NewStateController creates controller to apply state changes

func (*StateController) ChangeState

func (c *StateController) ChangeState(newRawState string) (int, error)

ChangeState apply changes to current objects state

func (*StateController) SetInitialState

func (c *StateController) SetInitialState(initialState string) error

Jump to

Keyboard shortcuts

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