Documentation
¶
Index ¶
- Constants
- Variables
- func FixYAML(obj map[string]interface{}, v interface{}) error
- func IntStrFromInt(val int) *intstr.IntOrString
- func IntStrFromStr(val string) *intstr.IntOrString
- func IsSupportedExtension(ext string) bool
- func IsYAMLExtension(ext string) bool
- func ParseYaml(yamlBytes []byte, v interface{}) error
- type Client
- type Opt
- type PrintBuffer
- type PrintHook
Constants ¶
const ( // ExtYAML is the standard YAML file extension. ExtYAML = ".yaml" // ExtYML is the alternative YAML file extension. ExtYML = ".yml" // ExtJSON is the JSON file extension. ExtJSON = ".json" )
File extension constants for supported file formats.
const ( // DefaultPrintBufferLimit caps how many bytes of print output gator keeps in memory. DefaultPrintBufferLimit int64 = 1 << 20 // 1 MiB )
Variables ¶
var ( // ErrNotATemplate indicates the user-indicated file does not contain a // ConstraintTemplate. ErrNotATemplate = errors.New("not a ConstraintTemplate") // ErrNotAConstraint indicates the user-indicated file does not contain a // Constraint. ErrNotAConstraint = errors.New("not a Constraint") // ErrNotAConfig indicates the user-indicated file does not contain a // Config. ErrNotAConfig = errors.New("not a Config") // ErrNotASyncSet indicates the user-indicated file does not contain a // SyncSet. ErrNotASyncSet = errors.New("not a SyncSet") // ErrNotAGVKManifest indicates the user-indicated file does not contain a // GVK Manifest. ErrNotAGVKManifest = errors.New("not a GVKManifest") // ErrNotAnExpansion indicates the user-indicated file does not contain an // ExpansionTemplate. ErrNotAnExpansion = errors.New("not an Expansion Template") // ErrAddingTemplate indicates a problem instantiating a Suite's ConstraintTemplate. ErrAddingTemplate = errors.New("adding template") // ErrAddingConstraint indicates a problem instantiating a Suite's Constraint. ErrAddingConstraint = errors.New("adding constraint") // ErrAddingSyncSet indicates a problem instantiating a user-indicated SyncSet. ErrAddingSyncSet = errors.New("adding syncset") // ErrAddingGVKManifest indicates a problem instantiating a user-indicated GVKManifest. ErrAddingGVKManifest = errors.New("adding gvkmanifest") // ErrAddingConfig indicates a problem instantiating a user-indicated Config. ErrAddingConfig = errors.New("adding config") // ErrInvalidSuite indicates a Suite does not define the required fields. ErrInvalidSuite = errors.New("invalid Suite") // ErrCreatingClient indicates an error instantiating the Client which compiles // Constraints and runs validation. ErrCreatingClient = errors.New("creating client") // ErrInvalidCase indicates a Case cannot be run due to not being configured properly. ErrInvalidCase = errors.New("invalid Case") // ErrNumViolations indicates an Object did not get the expected number of // violations. ErrNumViolations = errors.New("unexpected number of violations") // ErrInvalidRegex indicates a Case specified a Violation regex that could not // be compiled. ErrInvalidRegex = errors.New("message contains invalid regular expression") // ErrInvalidFilter indicates that Filter construction failed. ErrInvalidFilter = errors.New("invalid test filter") // ErrNoObjects indicates that a specified YAML file contained no objects. ErrNoObjects = errors.New("missing objects") // ErrMultipleObjects indicates that a specified YAML file contained multiple objects. ErrMultipleObjects = errors.New("object file must contain exactly one object") // ErrAddInventory indicates that an object that was declared to be part of // data.inventory was unable to be added. ErrAddInventory = errors.New("unable to add object to data.inventory") // ErrConvertingTemplate means we were able to parse a template, but not convert // it into the version-independent format. ErrConvertingTemplate = errors.New("unable to convert template") // ErrValidConstraint occurs when a test's configuration signals an expectation // that a constraint should fail validation but no validation error is raised. ErrValidConstraint = errors.New("constraint should have failed schema validation") // ErrInvalidK8sAdmissionReview occurs when a test attempts to pass in an AdmissionReview // object but we fail to convert the unstructured object into a typed AdmissionReview one. ErrInvalidK8sAdmissionReview = errors.New("not a valid AdmissionReview object") // ErrMissingK8sAdmissionRequest occurs when a test attempts to pass in an AdmissionReview // object but it does not actually pass in an AdmissionRequest object. ErrMissingK8sAdmissionRequest = errors.New("missing an AdmissionRequest object") // ErrReviewObject occurs when a test attempts to pass in an AdmissionRequest with no // object or oldObject for the underlying framework to review. // This mimicks the k8s api server behvaior. ErrNoObjectForReview = errors.New("no object or oldObject found to review") // ErrInvalidYAML indicates that a .yaml/.yml file was not parseable. ErrInvalidYAML = errors.New("invalid yaml") // ErrUnmarshallObject happens when the yaml defines an invalid object or oldObject. ErrUnmarshallObject = errors.New("object or oldObject cannot be unmarshalled") )
Functions ¶
func FixYAML ¶
Pass through JSON since k8s parsing logic doesn't fully handle objects parsed directly from YAML. Without passing through JSON, the OPA client panics when handed scalar types it doesn't recognize.
func IntStrFromInt ¶
func IntStrFromInt(val int) *intstr.IntOrString
func IntStrFromStr ¶
func IntStrFromStr(val string) *intstr.IntOrString
func IsSupportedExtension ¶ added in v3.22.0
IsSupportedExtension returns true if the extension is supported (YAML or JSON).
func IsYAMLExtension ¶ added in v3.22.0
IsYAMLExtension returns true if the extension is a valid YAML extension.
Types ¶
type Client ¶
type Client interface {
// AddTemplate adds a Template to the Client. Templates define the structure
// and parameters of potential Constraints.
AddTemplate(ctx context.Context, templ *templates.ConstraintTemplate) (*types.Responses, error)
// AddConstraint adds a Constraint to the Client. Must map to one of the
// previously-added Templates.
//
// Returns an error if the referenced Template does not exist, or the
// Constraint does not match the structure defined by the referenced Template.
AddConstraint(ctx context.Context, constraint *unstructured.Unstructured) (*types.Responses, error)
// AddData adds the state of the cluster. For use in referential Constraints.
AddData(ctx context.Context, data interface{}) (*types.Responses, error)
// RemoveData removes objects from the state of the cluster. For use in
// referential constraints.
RemoveData(ctx context.Context, data interface{}) (*types.Responses, error)
// Review runs all Constraints against obj.
Review(ctx context.Context, obj interface{}, opts ...reviews.ReviewOpt) (*types.Responses, error)
}
type Opt ¶ added in v3.22.0
type Opt func() ([]constraintclient.Opt, []rego.Arg, error)
func WithK8sCEL ¶ added in v3.22.0
func WithK8sCEL() Opt
func WithPrintHook ¶ added in v3.22.0
type PrintBuffer ¶ added in v3.23.0
type PrintBuffer struct {
// contains filtered or unexported fields
}
PrintBuffer is an in-memory writer with a fixed size limit.
func NewPrintBuffer ¶ added in v3.23.0
func NewPrintBuffer(limit int64) *PrintBuffer
NewPrintBuffer creates a buffer that stores at most limit bytes.
func (*PrintBuffer) Len ¶ added in v3.23.0
func (b *PrintBuffer) Len() int
func (*PrintBuffer) String ¶ added in v3.23.0
func (b *PrintBuffer) String() string
type PrintHook ¶ added in v3.22.0
type PrintHook struct {
// contains filtered or unexported fields
}
PrintHook implements the OPA print hook interface to capture print statement output from Rego policies.
func NewPrintHook ¶ added in v3.22.0
NewPrintHook creates and returns a new instance of PrintHook and writes to writer.
Directories
¶
| Path | Synopsis |
|---|---|
|
fixtures package contains commonly used ConstraintTemplates, Constraints, Objects and other k8s resources mostly used for testing.
|
fixtures package contains commonly used ConstraintTemplates, Constraints, Objects and other k8s resources mostly used for testing. |
|
sync
|
|