Documentation ¶
Index ¶
- Constants
- Variables
- func CheckIncludeSnapshots(kubeConfigs []OnKubernetesEventConfig, includes ...string) error
- func ConvertFloatForBinding(value interface{}, bindingName string) (*float64, error)
- func GetSchema(name string) *spec.Schema
- func LoadSchema(name string) (*spec.Schema, error)
- func MergeArrays(a1 []string, a2 []string) []string
- func MonitorConfigID() string
- func MonitorDebugName(configName string, configIndex int) string
- func ScheduleID() string
- func ValidateConfig(dataObj interface{}, s *spec.Schema, rootName string) (multiErr error)
- type HookConfig
- type HookConfigV0
- func (cv0 *HookConfigV0) CheckOnKubernetesEvent(kubeCfg OnKubernetesEventConfigV0, rootPath string) error
- func (cv0 *HookConfigV0) CheckSchedule(schV0 ScheduleConfigV0) error
- func (cv0 *HookConfigV0) ConvertAndCheck(c *HookConfig) (err error)
- func (cv0 *HookConfigV0) ConvertSchedule(schV0 ScheduleConfigV0) (ScheduleConfig, error)
- type HookConfigV1
- func (cv1 *HookConfigV1) CheckAdmission(kubeConfigs []OnKubernetesEventConfig, cfgV1 KubernetesAdmissionConfigV1) (allErr error)
- func (cv1 *HookConfigV1) CheckAndConvertSettings(settings *SettingsV1) (out *Settings, allErr error)
- func (cv1 *HookConfigV1) CheckConversion(kubeConfigs []OnKubernetesEventConfig, cfgV1 KubernetesConversionConfigV1) (allErr error)
- func (cv1 *HookConfigV1) CheckOnKubernetesEvent(kubeCfg OnKubernetesEventConfigV1, rootPath string) (allErr error)
- func (cv1 *HookConfigV1) CheckSchedule(kubeConfigs []OnKubernetesEventConfig, schV1 ScheduleConfigV1) (allErr error)
- func (cv1 *HookConfigV1) ConvertAndCheck(c *HookConfig) (err error)
- func (cv1 *HookConfigV1) ConvertConversion(cfgV1 KubernetesConversionConfigV1) (ConversionConfig, error)
- func (cv1 *HookConfigV1) ConvertSchedule(schV1 ScheduleConfigV1) (ScheduleConfig, error)
- type KubeFieldSelectorV1
- type KubeNameSelectorV1
- type KubeNamespaceSelectorV0
- type KubeNamespaceSelectorV1
- type KubernetesAdmissionConfigV1
- type KubernetesConversionConfigV1
- type OnKubernetesEventConfigV0
- type OnKubernetesEventConfigV1
- type ScheduleConfigV0
- type ScheduleConfigV1
- type SettingsV1
- type VersionedUntyped
Constants ¶
const VersionKey = "configVersion"
Variables ¶
var Schemas = map[string]string{
"v1": `
definitions:
nameSelector:
type: object
additionalProperties: false
required:
- matchNames
properties:
matchNames:
type: array
additionalItems: false
items:
type: string
labelSelector:
type: object
additionalProperties: false
minProperties: 1
maxProperties: 2
properties:
matchLabels:
type: object
additionalProperties:
type: string
matchExpressions:
type: array
items:
type: object
additionalProperties: false
required:
- key
- operator
properties:
key:
type: string
operator:
type: string
enum:
- In
- NotIn
- Exists
- DoesNotExist
values:
type: array
items:
type: string
type: object
additionalProperties: false
required:
- configVersion
minProperties: 2
properties:
configVersion:
type: string
enum:
- v1
settings:
type: object
additionalProperties: false
properties:
executionMinInterval:
type: string
executionBurst:
type: integer
onStartup:
title: onStartup binding
description: |
the value is the order to sort onStartup hooks
type: integer
example: 10
schedule:
title: schedule bindings
description: |
configuration of hooks that should run on schedule
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- crontab
properties:
name:
type: string
crontab:
type: string
allowFailure:
type: boolean
default: false
includeSnapshotsFrom:
type: array
additionalItems: false
minItems: 1
items:
type: string
queue:
type: string
group:
type: string
kubernetes:
title: kubernetes event bindings
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- kind
patternProperties:
"^(watchEvent|executeHookOnEvent)$":
type: array
additionalItems: false
minItems: 0
items:
type: string
enum:
- Added
- Modified
- Deleted
properties:
name:
type: string
apiVersion:
type: string
kind:
type: string
includeSnapshotsFrom:
type: array
additionalItems: false
minItems: 1
items:
type: string
queue:
type: string
jqFilter:
type: string
example: ".metadata.labels"
keepFullObjectsInMemory:
type: boolean
allowFailure:
type: boolean
executeHookOnSynchronization:
type: boolean
waitForSynchronization:
type: boolean
resynchronizationPeriod:
type: string
nameSelector:
"$ref": "#/definitions/nameSelector"
labelSelector:
"$ref": "#/definitions/labelSelector"
fieldSelector:
type: object
additionalProperties: false
required:
- matchExpressions
properties:
matchExpressions:
type: array
items:
type: object
additionalProperties: false
minProperties: 3
maxProperties: 3
properties:
field:
type: string
operator:
type: string
enum: ["=", "==", "Equals", "!=", "NotEquals"]
value:
type: string
group:
type: string
namespace:
type: object
additionalProperties: false
minProperties: 1
maxProperties: 2
properties:
nameSelector:
"$ref": "#/definitions/nameSelector"
labelSelector:
"$ref": "#/definitions/labelSelector"
kubernetesMutating:
title: kubernetesMutatingConfiguration handlers
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- name
properties:
name:
type: string
group:
type: string
includeSnapshotsFrom:
type: array
additionalItems: false
minItems: 1
items:
type: string
failurePolicy:
type: string
enum:
- Ignore
- Fail
sideEffects:
type: string
enum:
- None
- NoneOnDryRun
timeoutSeconds:
type: integer
example: 10
labelSelector:
"$ref": "#/definitions/labelSelector"
namespace:
type: object
additionalProperties: false
required:
- labelSelector
properties:
labelSelector:
"$ref": "#/definitions/labelSelector"
rules:
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- apiVersions
- apiGroups
- resources
- operations
properties:
apiVersions:
type: array
minItems: 1
items:
type: string
apiGroups:
type: array
minItems: 1
items:
type: string
resources:
type: array
minItems: 1
items:
type: string
operations:
type: array
minItems: 1
items:
type: string
enum:
- "CREATE"
- "UPDATE"
- "*"
scope:
type: string
enum:
- "Cluster"
- "Namespaced"
- "*"
kubernetesValidating:
title: ValidatingWebhookConfiguration handlers
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- name
properties:
name:
type: string
group:
type: string
includeSnapshotsFrom:
type: array
additionalItems: false
minItems: 1
items:
type: string
failurePolicy:
type: string
enum:
- Ignore
- Fail
sideEffects:
type: string
enum:
- None
- NoneOnDryRun
timeoutSeconds:
type: integer
example: 10
labelSelector:
"$ref": "#/definitions/labelSelector"
namespace:
type: object
additionalProperties: false
required:
- labelSelector
properties:
labelSelector:
"$ref": "#/definitions/labelSelector"
rules:
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- apiVersions
- apiGroups
- resources
- operations
properties:
apiVersions:
type: array
minItems: 1
items:
type: string
apiGroups:
type: array
minItems: 1
items:
type: string
resources:
type: array
minItems: 1
items:
type: string
operations:
type: array
minItems: 1
items:
type: string
enum:
- "CREATE"
- "UPDATE"
- "*"
scope:
type: string
enum:
- "Cluster"
- "Namespaced"
- "*"
kubernetesCustomResourceConversion:
title: Conversion handlers for CustomResourceDefinition versions
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- name
- crdName
- conversions
properties:
name:
type: string
group:
type: string
includeSnapshotsFrom:
type: array
additionalItems: false
minItems: 1
items:
type: string
crdName:
type: string
conversions:
type: array
additionalItems: false
minItems: 1
items:
type: object
additionalProperties: false
required:
- fromVersion
- toVersion
properties:
fromVersion:
type: string
toVersion:
type: string
`,
"v0": `
type: object
additionalProperties: false
minProperties: 1
properties:
onStartup:
title: onStartup binding
description: |
the value is the order to sort onStartup hooks
type: integer
schedule:
type: array
items:
type: object
onKubernetesEvent:
type: array
items:
type: object
`,
}
var SchemasCache = map[string]*spec.Schema{}
Functions ¶
func CheckIncludeSnapshots ¶
CheckIncludeSnapshots check if all includes has corresponding kubernetes binding. Rules:
- binding name should exists,
- binding name should not be repeated.
func ConvertFloatForBinding ¶
func LoadSchema ¶
LoadSchema returns spec.Schema object loaded from yaml in Schemas map.
func MergeArrays ¶
MergeArrays returns merged array with unique elements. Preserve elements order.
func MonitorConfigID ¶
func MonitorConfigID() string
TODO uuid is not a good choice here. Make it more readable.
func MonitorDebugName ¶
func ScheduleID ¶
func ScheduleID() string
TODO uuid is not a good choice here. Make it more readable.
func ValidateConfig ¶
Types ¶
type HookConfig ¶
type HookConfig struct { // effective version of config Version string // versioned raw config values V0 *HookConfigV0 V1 *HookConfigV1 // effective config values OnStartup *OnStartupConfig Schedules []ScheduleConfig OnKubernetesEvents []OnKubernetesEventConfig KubernetesValidating []ValidatingConfig KubernetesMutating []MutatingConfig KubernetesConversion []ConversionConfig Settings *Settings }
HookConfig is a structure with versioned hook configuration
func (*HookConfig) Bindings ¶
func (c *HookConfig) Bindings() []BindingType
Bindings returns a list of binding types in hook configuration.
func (*HookConfig) ConvertAndCheck ¶
func (c *HookConfig) ConvertAndCheck(data []byte) error
ConvertAndCheck transforms a versioned configuration to latest internal structures.
func (*HookConfig) ConvertOnStartup ¶
func (c *HookConfig) ConvertOnStartup(value interface{}) (*OnStartupConfig, error)
func (*HookConfig) HasBinding ¶
func (c *HookConfig) HasBinding(binding BindingType) bool
HasBinding returns true if a hook configuration has binding type.
func (*HookConfig) LoadAndValidate ¶
func (c *HookConfig) LoadAndValidate(data []byte) error
LoadAndValidate loads config from bytes and validate it. Returns multierror.
type HookConfigV0 ¶
type HookConfigV0 struct { OnStartup interface{} `json:"onStartup"` Schedule []ScheduleConfigV0 `json:"schedule"` OnKubernetesEvent []OnKubernetesEventConfigV0 `json:"onKubernetesEvent"` }
func (*HookConfigV0) CheckOnKubernetesEvent ¶
func (cv0 *HookConfigV0) CheckOnKubernetesEvent(kubeCfg OnKubernetesEventConfigV0, rootPath string) error
func (*HookConfigV0) CheckSchedule ¶
func (cv0 *HookConfigV0) CheckSchedule(schV0 ScheduleConfigV0) error
func (*HookConfigV0) ConvertAndCheck ¶
func (cv0 *HookConfigV0) ConvertAndCheck(c *HookConfig) (err error)
ConvertAndCheckV0 fills non-versioned structures and run inter-field checks not covered by OpenAPI schemas.
func (*HookConfigV0) ConvertSchedule ¶
func (cv0 *HookConfigV0) ConvertSchedule(schV0 ScheduleConfigV0) (ScheduleConfig, error)
type HookConfigV1 ¶
type HookConfigV1 struct { ConfigVersion string `json:"configVersion"` OnStartup interface{} `json:"onStartup"` Schedule []ScheduleConfigV1 `json:"schedule"` OnKubernetesEvent []OnKubernetesEventConfigV1 `json:"kubernetes"` KubernetesValidating []KubernetesAdmissionConfigV1 `json:"kubernetesValidating"` KubernetesMutating []KubernetesAdmissionConfigV1 `json:"kubernetesMutating"` KubernetesConversion []KubernetesConversionConfigV1 `json:"kubernetesCustomResourceConversion"` Settings *SettingsV1 `json:"settings"` }
func (*HookConfigV1) CheckAdmission ¶ added in v1.2.0
func (cv1 *HookConfigV1) CheckAdmission(kubeConfigs []OnKubernetesEventConfig, cfgV1 KubernetesAdmissionConfigV1) (allErr error)
func (*HookConfigV1) CheckAndConvertSettings ¶
func (cv1 *HookConfigV1) CheckAndConvertSettings(settings *SettingsV1) (out *Settings, allErr error)
CheckAndConvertSettings validates a duration and returns a Settings struct.
func (*HookConfigV1) CheckConversion ¶
func (cv1 *HookConfigV1) CheckConversion(kubeConfigs []OnKubernetesEventConfig, cfgV1 KubernetesConversionConfigV1) (allErr error)
func (*HookConfigV1) CheckOnKubernetesEvent ¶
func (cv1 *HookConfigV1) CheckOnKubernetesEvent(kubeCfg OnKubernetesEventConfigV1, rootPath string) (allErr error)
func (*HookConfigV1) CheckSchedule ¶
func (cv1 *HookConfigV1) CheckSchedule(kubeConfigs []OnKubernetesEventConfig, schV1 ScheduleConfigV1) (allErr error)
func (*HookConfigV1) ConvertAndCheck ¶
func (cv1 *HookConfigV1) ConvertAndCheck(c *HookConfig) (err error)
ConvertAndCheck fills non-versioned structures and run inter-field checks not covered by OpenAPI schemas.
func (*HookConfigV1) ConvertConversion ¶
func (cv1 *HookConfigV1) ConvertConversion(cfgV1 KubernetesConversionConfigV1) (ConversionConfig, error)
func (*HookConfigV1) ConvertSchedule ¶
func (cv1 *HookConfigV1) ConvertSchedule(schV1 ScheduleConfigV1) (ScheduleConfig, error)
type KubeFieldSelectorV1 ¶
type KubeFieldSelectorV1 FieldSelector
type KubeNameSelectorV1 ¶
type KubeNameSelectorV1 NameSelector
type KubeNamespaceSelectorV0 ¶
type KubeNamespaceSelectorV1 ¶
type KubeNamespaceSelectorV1 NamespaceSelector
type KubernetesAdmissionConfigV1 ¶ added in v1.2.0
type KubernetesAdmissionConfigV1 struct { Name string `json:"name,omitempty"` IncludeSnapshotsFrom []string `json:"includeSnapshotsFrom,omitempty"` Group string `json:"group,omitempty"` Rules []v1.RuleWithOperations `json:"rules,omitempty"` FailurePolicy *v1.FailurePolicyType `json:"failurePolicy"` LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"` Namespace *KubeNamespaceSelectorV1 `json:"namespace,omitempty"` SideEffects *v1.SideEffectClass `json:"sideEffects"` TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"` }
version 1 of kubernetes vali configuration
type KubernetesConversionConfigV1 ¶
type KubernetesConversionConfigV1 struct { Name string `json:"name,omitempty"` IncludeSnapshotsFrom []string `json:"includeSnapshotsFrom,omitempty"` Group string `json:"group,omitempty"` CrdName string `json:"crdName,omitempty"` Conversions []conversion.Rule `json:"conversions,omitempty"` }
version 1 of kubernetes conversion configuration
type OnKubernetesEventConfigV0 ¶
type OnKubernetesEventConfigV0 struct { Name string `json:"name,omitempty"` EventTypes []string `json:"event,omitempty"` Kind string `json:"kind,omitempty"` Selector *metav1.LabelSelector `json:"selector,omitempty"` ObjectName string `json:"objectName,omitempty"` NamespaceSelector *KubeNamespaceSelectorV0 `json:"namespaceSelector,omitempty"` JqFilter string `json:"jqFilter,omitempty"` AllowFailure bool `json:"allowFailure,omitempty"` }
Legacy version of kubernetes event configuration
type OnKubernetesEventConfigV1 ¶
type OnKubernetesEventConfigV1 struct { Name string `json:"name,omitempty"` WatchEventTypes []WatchEventType `json:"watchEvent,omitempty"` ExecuteHookOnEvents []WatchEventType `json:"executeHookOnEvent,omitempty"` ExecuteHookOnSynchronization string `json:"executeHookOnSynchronization,omitempty"` WaitForSynchronization string `json:"waitForSynchronization,omitempty"` KeepFullObjectsInMemory string `json:"keepFullObjectsInMemory,omitempty"` Mode KubeEventMode `json:"mode,omitempty"` ApiVersion string `json:"apiVersion,omitempty"` Kind string `json:"kind,omitempty"` NameSelector *KubeNameSelectorV1 `json:"nameSelector,omitempty"` LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"` FieldSelector *KubeFieldSelectorV1 `json:"fieldSelector,omitempty"` Namespace *KubeNamespaceSelectorV1 `json:"namespace,omitempty"` JqFilter string `json:"jqFilter,omitempty"` AllowFailure bool `json:"allowFailure,omitempty"` ResynchronizationPeriod string `json:"resynchronizationPeriod,omitempty"` IncludeSnapshotsFrom []string `json:"includeSnapshotsFrom,omitempty"` Queue string `json:"queue,omitempty"` Group string `json:"group,omitempty"` }
version 1 of kubernetes event configuration
type ScheduleConfigV0 ¶
type ScheduleConfigV0 struct { Name string `json:"name"` Crontab string `json:"crontab"` AllowFailure bool `json:"allowFailure"` }
Schedule configuration
type ScheduleConfigV1 ¶
type ScheduleConfigV1 struct { Name string `json:"name"` Crontab string `json:"crontab"` AllowFailure bool `json:"allowFailure"` IncludeSnapshotsFrom []string `json:"includeSnapshotsFrom"` Queue string `json:"queue"` Group string `json:"group,omitempty"` }
Schedule configuration
type SettingsV1 ¶
type SettingsV1 struct { ExecutionMinInterval string `json:"executionMinInterval,omitempty"` ExecutionBurst string `json:"executionBurst,omitempty"` }
version 1 of hook settings
type VersionedUntyped ¶
type VersionedUntyped struct { Obj map[string]interface{} Version string VersionKey string VersionValidator func(string, bool) (string, error) }
func NewDefaultVersionedUntyped ¶
func NewDefaultVersionedUntyped() *VersionedUntyped
NewDefaultVersionedUntyped is a VersionedUntyper object with default version key and version validator against Schemas map
func (*VersionedUntyped) GetString ¶
func (u *VersionedUntyped) GetString(key string) (value string, found bool, err error)
GetString returns string value by key
func (*VersionedUntyped) Load ¶
func (u *VersionedUntyped) Load(data []byte) error
func (*VersionedUntyped) LoadConfigVersion ¶
func (u *VersionedUntyped) LoadConfigVersion() (string, error)
LoadConfigVersion