# README
Binding Context Generator
Binding Context Generator provides the ability to generate binding contexts for hooks testing purposes.
Usage example:
- 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`
- Initial objects state
initialState := `
---
apiVersion: v1
kind: Pod
metadata:
name: pod-0
---
apiVersion: v1
kind: Pod
metadata:
name: pod-1
`
- New state
newState := `
---
apiVersion: v1
kind: Pod
metadata:
name: pod-0
`
- Create new binding context controller
c := context.NewBindingContextController(config, initialState)
- 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)
- Run controller to get initial binding context
contexts, err := c.Run()
if err != nil {
return err
}
testContexts(contexts)
- Change state to get new binding contexts
contexts, err = c.ChangeState(newState)
if err != nil {
return err
}
testNewContexts(contexts)
- Run schedule to get binding contexts for a cron task
contexts, err = c.RunSchedule("* * * * *")
if err != nil {
return err
}
testScheduleContexts(contexts)