context

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 19 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 provides the ability to generate binding contexts for hooks testing purposes.

Usage example:

  1. 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. Initial objects state
initialState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
`
  1. New state
newState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
`
  1. Create new binding context controller
c := context.NewBindingContextController(config, initialState)
  1. Register CRDs (if it is necessary) 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 get new binding contexts
contexts, err = c.ChangeState(newState)
if err != nil {
  return err
}
testNewContexts(contexts)
  1. Run schedule to get binding contexts for a cron task
contexts, err = c.RunSchedule("* * * * *")
if err != nil {
  return err
}
testScheduleContexts(contexts)

Documentation

Index

Constants

View Source
const TestQueueName string = "test-queue"

TestQueueName is a name of the queue created by ContextCombiner.

View Source
const TestTaskType task.TaskType = "TestTask"

TestTaskType is a type for tasks created by ContextCombiner.

Variables

This section is empty.

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
	// contains filtered or unexported fields
}

func NewBindingContextController

func NewBindingContextController(config string, version ...fake.ClusterVersion) *BindingContextController

func (*BindingContextController) ChangeState

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

func (*BindingContextController) FakeCluster added in v1.0.2

func (b *BindingContextController) FakeCluster() *fake.Cluster

func (*BindingContextController) RegisterCRD

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

RegisterCRD registers custom resources for the cluster

func (*BindingContextController) Run

Run generates binding contexts for hook tests

func (*BindingContextController) RunBindingWithAllSnapshots added in v1.0.1

func (b *BindingContextController) RunBindingWithAllSnapshots(binding types.BindingType) (GeneratedBindingContexts, error)

func (*BindingContextController) RunSchedule

func (*BindingContextController) Stop

func (b *BindingContextController) Stop()

func (*BindingContextController) WithHook

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

type ContextCombiner added in v1.0.1

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

ContextCombiner is used to bring logic behind the CombineBindingContextForHook method into tests. This method requires a ShellOperator instance with at least one queue with tasks.

func NewContextCombiner added in v1.0.1

func NewContextCombiner() *ContextCombiner

func (*ContextCombiner) AddBindingContext added in v1.0.1

func (c *ContextCombiner) AddBindingContext(bindingType types.BindingType, info controller.BindingExecutionInfo)

func (*ContextCombiner) Combined added in v1.0.1

CombinedContext returns a combined context or a binding context from the first task.

func (*ContextCombiner) CombinedAndUpdated added in v1.0.1

func (c *ContextCombiner) CombinedAndUpdated(hookCtrl controller.HookController) (GeneratedBindingContexts, error)

func (*ContextCombiner) QueueLen added in v1.0.1

func (c *ContextCombiner) QueueLen() int

type GeneratedBindingContexts

type GeneratedBindingContexts struct {
	Rendered        string
	BindingContexts []BindingContext
}

func ConvertToGeneratedBindingContexts added in v1.0.1

func ConvertToGeneratedBindingContexts(bindingContexts []binding_context.BindingContext) (GeneratedBindingContexts, error)

type StateController

type StateController struct {
	CurrentState map[string]manifest.Manifest
	// contains filtered or unexported fields
}

StateController holds objects state for FakeCluster

func NewStateController

func NewStateController(fc *fake.Cluster, ev kubeeventsmanager.KubeEventsManager) *StateController

NewStateController creates controller to apply state changes

func (*StateController) ChangeState

func (c *StateController) ChangeState(newRawState string) 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