Documentation
¶
Index ¶
- Constants
- func NewNamespace(nsName string) *unstructured.Unstructured
- type Environment
- type Fixture
- type KubeClient
- func (k *KubeClient) KindIsNamespaced(kind schema.GroupVersionKind) (bool, error)
- func (k *KubeClient) NamespaceExists(nsName string) (bool, error)
- func (k *KubeClient) ResourceForKind(kind schema.GroupVersionKind) (schema.GroupVersionResource, error)
- func (k *KubeClient) ResourcesForName(name string) ([]schema.GroupVersionResource, error)
- func (k *KubeClient) RunIDFor(u *unstructured.Unstructured) (string, error)
- func (k *KubeClient) SelectObjects(kind schema.GroupVersionKind, selector labels.Selector) ([]*unstructured.Unstructured, error)
- func (k *KubeClient) SelectObjectsByLabel(label string, value string) ([]*unstructured.Unstructured, error)
- func (k *KubeClient) ServerResources() ([]metav1.APIResource, error)
- func (k *KubeClient) SetUserAgent(ua string)
- type LockingResourceEventHandler
- type MuxingResourceEventHandler
- func (m *MuxingResourceEventHandler) Add(c cache.ResourceEventHandler) int
- func (m *MuxingResourceEventHandler) Clear()
- func (m *MuxingResourceEventHandler) OnAdd(newObj interface{})
- func (m *MuxingResourceEventHandler) OnDelete(oldObj interface{})
- func (m *MuxingResourceEventHandler) OnUpdate(oldObj, newObj interface{})
- func (m *MuxingResourceEventHandler) Remove(which int)
- type Object
- type ObjectDriver
- type ObjectOperationType
- type ObjectReference
- type OperationResult
- type RegoDriver
- type RegoOpt
- type RegoTracer
- type WrappingResourceEventHandlerFuncs
Constants ¶
const ( // ObjectOperationDelete indicates this object should be deleted. ObjectOperationDelete = "delete" // ObjectOperationUpdate indicates this object should be // updated (i.e created or patched). ObjectOperationUpdate = "update" )
const DefaultResyncPeriod = time.Minute * 5
DefaultResyncPeriod is the default informer resync interval.
Variables ¶
This section is empty.
Functions ¶
func NewNamespace ¶
func NewNamespace(nsName string) *unstructured.Unstructured
NewNamespace returns a v1/Namespace object named by nsName and converted to an unstructured.Unstructured object.
Types ¶
type Environment ¶
type Environment interface { // UniqueID returns a unique identifier for this Environment instance. UniqueID() string // HydrateObject ... HydrateObject(objData []byte) (*Object, error) }
Environment holds metadata that describes the context of a test.
type Fixture ¶
type Fixture struct {
As string
}
Fixture is a marker to tell the Environment that a Kubernetes object is a fixture placeholder.
type KubeClient ¶
type KubeClient struct { Config *rest.Config // XXX(jpeach): remove this, it's only needed for init Client *kubernetes.Clientset Dynamic dynamic.Interface Discovery discovery.CachedDiscoveryInterface }
KubeClient collects various Kubernetes client interfaces.
func NewKubeClient ¶
func NewKubeClient() (*KubeClient, error)
NewKubeClient returns a new set of Kubernetes client interfaces that are configured to use the default Kubernetes context.
func (*KubeClient) KindIsNamespaced ¶
func (k *KubeClient) KindIsNamespaced(kind schema.GroupVersionKind) (bool, error)
KindIsNamespaced returns whether the given kind can be created within a namespace.
func (*KubeClient) NamespaceExists ¶
func (k *KubeClient) NamespaceExists(nsName string) (bool, error)
NamespaceExists tests whether the given namespace is present.
func (*KubeClient) ResourceForKind ¶
func (k *KubeClient) ResourceForKind(kind schema.GroupVersionKind) (schema.GroupVersionResource, error)
ResourceForKind returns the schema.GroupVersionResource corresponding to kind.
func (*KubeClient) ResourcesForName ¶
func (k *KubeClient) ResourcesForName(name string) ([]schema.GroupVersionResource, error)
ResourcesForName returns the possible set of schema.GroupVersionResource corresponding to the given resource name.
func (*KubeClient) RunIDFor ¶
func (k *KubeClient) RunIDFor(u *unstructured.Unstructured) (string, error)
RunIDFor returns the test run ID for u, if there is one. If there is no run ID, it returns "".
func (*KubeClient) SelectObjects ¶
func (k *KubeClient) SelectObjects(kind schema.GroupVersionKind, selector labels.Selector) ( []*unstructured.Unstructured, error)
SelectObjects lists the objects matching the given kind and selector.
func (*KubeClient) SelectObjectsByLabel ¶
func (k *KubeClient) SelectObjectsByLabel(label string, value string) ([]*unstructured.Unstructured, error)
SelectObjectsByLabel lists all objects that are labeled as managed.
func (*KubeClient) ServerResources ¶
func (k *KubeClient) ServerResources() ([]metav1.APIResource, error)
ServerResources returns the list of all the resources supported by the API server. Note that this method guarantees to populate the Group and Version fields in the result.
func (*KubeClient) SetUserAgent ¶
func (k *KubeClient) SetUserAgent(ua string)
SetUserAgent sets the HTTP User-Agent on the Client.
type LockingResourceEventHandler ¶
type LockingResourceEventHandler struct { Next cache.ResourceEventHandler Lock sync.Mutex }
LockingResourceEventHandler holds its lock, then invokes the next handler.
func (*LockingResourceEventHandler) OnAdd ¶
func (l *LockingResourceEventHandler) OnAdd(newObj interface{})
OnAdd ...
func (*LockingResourceEventHandler) OnDelete ¶
func (l *LockingResourceEventHandler) OnDelete(oldObj interface{})
OnDelete ...
func (*LockingResourceEventHandler) OnUpdate ¶
func (l *LockingResourceEventHandler) OnUpdate(oldObj, newObj interface{})
OnUpdate ...
type MuxingResourceEventHandler ¶
type MuxingResourceEventHandler struct { Handlers map[int]cache.ResourceEventHandler // contains filtered or unexported fields }
MuxingResourceEventHandler sends each event to every attached handler, in no particular order.
func (*MuxingResourceEventHandler) Add ¶
func (m *MuxingResourceEventHandler) Add(c cache.ResourceEventHandler) int
Add registers a new handler and returns a removal token.
func (*MuxingResourceEventHandler) Clear ¶
func (m *MuxingResourceEventHandler) Clear()
Clear removes all the registered handlers.
func (*MuxingResourceEventHandler) OnAdd ¶
func (m *MuxingResourceEventHandler) OnAdd(newObj interface{})
OnAdd ...
func (*MuxingResourceEventHandler) OnDelete ¶
func (m *MuxingResourceEventHandler) OnDelete(oldObj interface{})
OnDelete ...
func (*MuxingResourceEventHandler) OnUpdate ¶
func (m *MuxingResourceEventHandler) OnUpdate(oldObj, newObj interface{})
OnUpdate ...
func (*MuxingResourceEventHandler) Remove ¶
func (m *MuxingResourceEventHandler) Remove(which int)
Remove unregisters a handler using the removal token from a previous Add.
type Object ¶
type Object struct { // Object is the object to apply. Object *unstructured.Unstructured // Check is a Rego check to run on the apply. Check *ast.Module // Operation specifies whether we are updating or deleting the object. Operation ObjectOperationType // Fixture specifies that we should replace this object with the corresponding fixture. Fixture *Fixture }
Object captures an Unstructured Kubernetes API object and its associated metadata.
TODO(jpeach): this is a terrible name. Refactor this whole bizarre atrocity.
type ObjectDriver ¶
type ObjectDriver interface { // Eval creates or updates the specified object. Apply(*unstructured.Unstructured) (*OperationResult, error) // Delete deleted the specified object. Delete(*unstructured.Unstructured) (*OperationResult, error) // Adopt tells the driver to take ownership of and to start tracking // the specified object. Any adopted objects will be included in a // DeleteAll operation. Adopt(*unstructured.Unstructured) error // DeleteAll deletes all the objects that have been adopted by this driver. DeleteAll() error // InformOn establishes an informer for the given resource. // Events received by this informer will be delivered to all // watchers. InformOn(gvr schema.GroupVersionResource) error // Watch registers an event handler to receive events from // all the informers managed by the driver. Watch(cache.ResourceEventHandler) func() // Done marks this driver session as complete. All informers // are released, watchers are unregistered and adopted objects // are forgotten. Done() }
ObjectDriver is a driver that is responsible for the lifecycle of Kubernetes API documents, expressed as unstructured.Unstructured objects.
func NewObjectDriver ¶
func NewObjectDriver(client *KubeClient) ObjectDriver
NewObjectDriver returns a new ObjectDriver.
type ObjectOperationType ¶
type ObjectOperationType string
ObjectOperationType desscribes the type of operation to apply to this object. This is derived from the "$apply" pseudo-field.
type ObjectReference ¶
type ObjectReference struct { Name string `json:"name"` Namespace string `json:"namespace"` Meta struct { Group string `json:"group"` Version string `json:"version"` Kind string `json:"kind"` } `json:"meta"` }
ObjectReference uniquely identifies Kubernetes API object.
func (*ObjectReference) FromUnstructured ¶
func (o *ObjectReference) FromUnstructured(u *unstructured.Unstructured) *ObjectReference
FromUnstructured initializes an ObjectReference from a unstructured.Unstructured object.
type OperationResult ¶
type OperationResult struct { Error *metav1.Status `json:"error"` Latest *unstructured.Unstructured `json:"latest"` Target ObjectReference `json:"target"` }
OperationResult describes the result of an attempt to apply a Kubernetes object update.
func (*OperationResult) Succeeded ¶
func (o *OperationResult) Succeeded() bool
Succeeded returns true if the operation was successful.
type RegoDriver ¶
type RegoDriver interface { // Eval evaluates the given module and returns and check results. Eval(*ast.Module, ...RegoOpt) ([]result.Result, error) Trace(RegoTracer) // StoreItem stores the value at the given path in the Rego data document. StoreItem(string, interface{}) error // StorePath creates the given path in the Rego data document. StorePath(where string) error // RemovePath remove any object at the given path in the Rego data document. RemovePath(where string) error }
RegoDriver is a driver for running Rego policy checks.
func NewRegoDriver ¶
func NewRegoDriver() RegoDriver
NewRegoDriver creates a new RegoDriver that evaluates checks written in Rego.
See https://www.openpolicyagent.org/docs/latest/policy-language/
type RegoTracer ¶
RegoTracer is a tracer for check execution.
func NewRegoTracer ¶
func NewRegoTracer(w io.Writer) RegoTracer
NewRegoTracer returns a new RegoTracer that traces to w.
type WrappingResourceEventHandlerFuncs ¶
type WrappingResourceEventHandlerFuncs struct { AddFunc func(obj interface{}) UpdateFunc func(oldObj, newObj interface{}) DeleteFunc func(obj interface{}) Next cache.ResourceEventHandler }
WrappingResourceEventHandlerFuncs is the equivalent of cache.ResourceEventHandlerFuncs, except that after invoking the local handler. it also invoked the one pointer to by Next.
func (*WrappingResourceEventHandlerFuncs) OnAdd ¶
func (r *WrappingResourceEventHandlerFuncs) OnAdd(newObj interface{})
OnAdd ...
func (*WrappingResourceEventHandlerFuncs) OnDelete ¶
func (r *WrappingResourceEventHandlerFuncs) OnDelete(oldObj interface{})
OnDelete ...
func (*WrappingResourceEventHandlerFuncs) OnUpdate ¶
func (r *WrappingResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{})
OnUpdate ...