package
1.11.1
Repository: https://github.com/flant/shell-operator.git
Documentation: pkg.go.dev

# 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)