Documentation ¶
Overview ¶
Package graffiti decideds whether an object should be graffiti'd, according to a rule, and then produces and JSON patch with the desired modification. Mutate either kubernetes admission request objects or plain raw objects.
Index ¶
- func MatchLabelSelector(selector string, target map[string]string) (bool, error)
- func StringToBooleanOperatorFunc() mapstructure.DecodeHookFunc
- func ValidateLabelSelector(selector string) error
- type Additions
- type BooleanOperator
- func (i BooleanOperator) IsABooleanOperator() bool
- func (i BooleanOperator) MarshalJSON() ([]byte, error)
- func (i BooleanOperator) MarshalYAML() (interface{}, error)
- func (i BooleanOperator) String() string
- func (i *BooleanOperator) UnmarshalJSON(data []byte) error
- func (i *BooleanOperator) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Deletions
- type Matchers
- type Payload
- type Rule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchLabelSelector ¶
matchLabelSelector will apply a kubernetes labels.Selector to a map[string]string and return a matched bool and error. It is exported so that it can be used in 'existing' package for processing namespace selectors.
func StringToBooleanOperatorFunc ¶
func StringToBooleanOperatorFunc() mapstructure.DecodeHookFunc
StringToBooleanOperatorFunc allows mapstructure to map string representations of BooleanOperators to their enum type values
func ValidateLabelSelector ¶
validateLabelSelector checks that a label selector parses correctly and is used when validating config
Types ¶
type Additions ¶
type Additions struct { Annotations map[string]string `mapstructure:"annotations" yaml:"annotations,omitempty"` Labels map[string]string `mapstructure:"labels" yaml:"labels,omitempty"` }
Additions contains the additional fields that we want to insert into the object This type is directly marshalled from config and so has mapstructure tags
type BooleanOperator ¶
type BooleanOperator int
BooleanOperator defines the logical boolean operator applied to label and field selector results. It is AND by default, i.e. both label selector and field selector must match to
const ( AND BooleanOperator = iota OR XOR )
func BooleanOperatorString ¶
func BooleanOperatorString(s string) (BooleanOperator, error)
BooleanOperatorString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func BooleanOperatorValues ¶
func BooleanOperatorValues() []BooleanOperator
BooleanOperatorValues returns all values of the enum
func (BooleanOperator) IsABooleanOperator ¶
func (i BooleanOperator) IsABooleanOperator() bool
IsABooleanOperator returns "true" if the value is listed in the enum definition. "false" otherwise
func (BooleanOperator) MarshalJSON ¶
func (i BooleanOperator) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for BooleanOperator
func (BooleanOperator) MarshalYAML ¶
func (i BooleanOperator) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for BooleanOperator
func (BooleanOperator) String ¶
func (i BooleanOperator) String() string
func (*BooleanOperator) UnmarshalJSON ¶
func (i *BooleanOperator) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for BooleanOperator
func (*BooleanOperator) UnmarshalYAML ¶
func (i *BooleanOperator) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for BooleanOperator
type Deletions ¶
type Deletions struct { Annotations []string `mapstructure:"annotations" yaml:"annotations,omitempty"` Labels []string `mapstructure:"labels" yaml:"labels,omitempty"` }
Deletions contains the names of labels or annotations which you wish to remove
type Matchers ¶
type Matchers struct { LabelSelectors []string `mapstructure:"label-selectors" yaml:"label-selectors,omitempty"` FieldSelectors []string `mapstructure:"field-selectors" yaml:"field-selectors,omitempty"` BooleanOperator BooleanOperator `mapstructure:"boolean-operator" yaml:"boolean-operator,omitempty"` }
Matchers manages the rules of matching an object This type is directly marshalled from config and so has mapstructure tags
type Payload ¶
type Payload struct { Additions Additions `mapstructure:"additions" yaml:"additions,omitempty"` Deletions Deletions `mapstructure:"deletions" yaml:"deletions,omitempty"` Block bool `mapstructure:"block" yaml:"block,omitempty"` JSONPatch string `mapstructure:"json-patch" yaml:"json-patch,omitempty"` }
Payload contains the actions that we would like to perform when rule matches an object, such as label/annotation additions or deletions, a patch or a block.
type Rule ¶
type Rule struct { Name string `yaml:"name,omitempty"` Matchers Matchers `yaml:"matchers,omitempty"` Payload Payload `yaml:"payload,omitempty"` }
Rule contains a single graffiti rule and contains matchers for choosing which objects to change and payload containing the change. It does not have mapstructure tags because it is not directly marshalled from config
func (Rule) Mutate ¶
Mutate takes a raw object and applies the graffiti rule against it, returning a JSON patch or an error. It performs the logic between selectors and the boolean-operator.
func (Rule) MutateAdmission ¶
func (r Rule) MutateAdmission(req *admission.AdmissionRequest) *admission.AdmissionResponse
MutateAdmission takes an admission request and generates an admission response based on the response from Mutate. It implements the graffitiMutator interface and so can be added to the webhook handler's tagmap