Documentation ¶
Index ¶
- func CleanObjectForMarshalling(o runtime.Object) (runtime.Object, error)
- func ConvertUnstructured(in runtime.Object) (runtime.Object, error)
- func CreateOrUpdate(ctx context.Context, cl client.Client, obj runtime.Object, retryOnError bool) (updated bool, err error)
- func FakeDiscoveryClient() discovery.DiscoveryInterface
- func GetAPIResource(dClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (metav1.APIResource, error)
- func GetArgs(ctx context.Context, command string, cmd kudo.Command, namespace string) (*exec.Cmd, error)
- func InstallManifests(ctx context.Context, client client.Client, ...) ([]runtime.Object, error)
- func IsJSONSyntaxError(err error) bool
- func IsSubset(expected, actual interface{}) error
- func Kubeconfig(cfg *rest.Config, w io.Writer) error
- func LoadYAML(path string) ([]runtime.Object, error)
- func MarshalObject(o runtime.Object, w io.Writer) error
- func MarshalObjectJSON(o runtime.Object, w io.Writer) error
- func MatchesKind(obj runtime.Object, kinds ...runtime.Object) bool
- func Namespaced(dClient discovery.DiscoveryInterface, obj runtime.Object, namespace string) (string, string, error)
- func NewDynamicRESTMapper(cfg *rest.Config) (meta.RESTMapper, error)
- func NewPod(name, namespace string) runtime.Object
- func NewResource(apiVersion, kind, name, namespace string) runtime.Object
- func ObjectKey(obj runtime.Object) client.ObjectKey
- func PatchObject(actual, expected runtime.Object) error
- func PrettyDiff(expected runtime.Object, actual runtime.Object) (string, error)
- func ResourceID(obj runtime.Object) string
- func Retry(ctx context.Context, fn func(context.Context) error, ...) error
- func RunCommand(ctx context.Context, namespace string, command string, cmd kudo.Command, ...) error
- func RunCommands(logger Logger, namespace string, command string, commands []kudo.Command, ...) []error
- func RunKubectlCommands(logger Logger, namespace string, commands []string, workdir string) []error
- func RunTests(testName string, testToRun string, parallelism int, testFunc func(*testing.T))
- func Scheme() *runtime.Scheme
- func SetAnnotation(obj runtime.Object, key, value string) runtime.Object
- func ValidateErrors(err error, errValidationFuncs ...func(error) bool) error
- func WaitForCRDs(dClient discovery.DiscoveryInterface, crds []runtime.Object) error
- func WaitForDelete(c *RetryClient, objs []runtime.Object) error
- func WithAnnotations(obj runtime.Object, annotations map[string]string) runtime.Object
- func WithKeyValue(obj runtime.Object, key string, value map[string]interface{}) (runtime.Object, error)
- func WithLabels(t *testing.T, obj runtime.Object, labels map[string]string) runtime.Object
- func WithNamespace(obj runtime.Object, namespace string) runtime.Object
- func WithSpec(t *testing.T, obj runtime.Object, spec map[string]interface{}) runtime.Object
- func WithStatus(t *testing.T, obj runtime.Object, status map[string]interface{}) runtime.Object
- type Client
- type DockerClient
- type DynamicRESTMapper
- func (drm *DynamicRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
- func (drm *DynamicRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
- func (drm *DynamicRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
- func (drm *DynamicRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
- func (drm *DynamicRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
- func (drm *DynamicRESTMapper) ResourceSingularizer(resource string) (singular string, err error)
- func (drm *DynamicRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
- type Logger
- type RetryClient
- func (r *RetryClient) Create(ctx context.Context, obj runtime.Object, opts ...client.CreateOption) error
- func (r *RetryClient) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error
- func (r *RetryClient) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error
- func (r *RetryClient) Get(ctx context.Context, key client.ObjectKey, obj runtime.Object) error
- func (r *RetryClient) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error
- func (r *RetryClient) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, ...) error
- func (r *RetryClient) Status() client.StatusWriter
- func (r *RetryClient) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error
- func (r *RetryClient) Watch(ctx context.Context, obj runtime.Object) (watch.Interface, error)
- type RetryStatusWriter
- type SubsetError
- type TestEnvironment
- type TestLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanObjectForMarshalling ¶ added in v0.4.0
CleanObjectForMarshalling removes unnecessary object metadata that should not be included in serialization and diffs.
func ConvertUnstructured ¶
ConvertUnstructured converts an unstructured object to the known struct. If the type is not known, then the unstructured object is returned unmodified.
func CreateOrUpdate ¶
func CreateOrUpdate(ctx context.Context, cl client.Client, obj runtime.Object, retryOnError bool) (updated bool, err error)
CreateOrUpdate will create obj if it does not exist and update if it it does. retryonerror indicates whether we retry in case of conflict Returns true if the object was updated and false if it was created.
func FakeDiscoveryClient ¶
func FakeDiscoveryClient() discovery.DiscoveryInterface
FakeDiscoveryClient returns a fake discovery client that is populated with some types for use in unit tests.
func GetAPIResource ¶
func GetAPIResource(dClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (metav1.APIResource, error)
GetAPIResource returns the APIResource object for a specific GroupVersionKind.
func GetArgs ¶ added in v0.7.0
func GetArgs(ctx context.Context, command string, cmd kudo.Command, namespace string) (*exec.Cmd, error)
GetArgs parses a command line string into its arguments and appends a namespace if it is not already set.
func InstallManifests ¶
func InstallManifests(ctx context.Context, client client.Client, dClient discovery.DiscoveryInterface, manifestsDir string, kinds ...runtime.Object) ([]runtime.Object, error)
InstallManifests recurses over ManifestsDir to install all resources defined in YAML manifests.
func IsJSONSyntaxError ¶ added in v0.4.0
IsJSONSyntaxError returns true if the error is a JSON syntax error.
func IsSubset ¶
func IsSubset(expected, actual interface{}) error
IsSubset checks to see if `expected` is a subset of `actual`. A "subset" is an object that is equivalent to the other object, but where map keys found in actual that are not defined in expected are ignored.
func Kubeconfig ¶ added in v0.5.0
Kubeconfig converts a rest.Config into a YAML kubeconfig and writes it to w
func MarshalObject ¶
MarshalObject marshals a Kubernetes object to a YAML string.
func MarshalObjectJSON ¶ added in v0.4.0
MarshalObjectJSON marshals a Kubernetes object to a JSON string.
func MatchesKind ¶ added in v0.4.0
MatchesKind returns true if the Kubernetes kind of obj matches any of kinds.
func Namespaced ¶
func Namespaced(dClient discovery.DiscoveryInterface, obj runtime.Object, namespace string) (string, string, error)
Namespaced sets the namespace on an object to namespace, if it is a namespace scoped resource. If the resource is cluster scoped, then it is ignored and the namespace is not set. If it is a namespaced resource and a namespace is already set, then the namespace is unchanged.
func NewDynamicRESTMapper ¶ added in v0.4.0
func NewDynamicRESTMapper(cfg *rest.Config) (meta.RESTMapper, error)
NewDynamicRESTMapper returns a RESTMapper that dynamically discovers resource types at runtime. This is in contrast to controller-manager's default RESTMapper, which only checks resource types at startup, and so can't handle the case of first creating a CRD and then creating an instance of that CRD.
func NewResource ¶
NewResource generates a Kubernetes object using the provided apiVersion, kind, name, and namespace.
func PatchObject ¶
PatchObject updates expected with the Resource Version from actual. In the future, PatchObject may perform a strategic merge of actual into expected.
func PrettyDiff ¶
PrettyDiff creates a unified diff highlighting the differences between two Kubernetes resources
func ResourceID ¶
ResourceID returns a human readable identifier indicating the object kind, name, and namespace.
func Retry ¶
func Retry(ctx context.Context, fn func(context.Context) error, errValidationFuncs ...func(error) bool) error
Retry retries a method until the context expires or the method returns an unvalidated error.
func RunCommand ¶ added in v0.7.0
func RunCommand(ctx context.Context, namespace string, command string, cmd kudo.Command, cwd string, stdout io.Writer, stderr io.Writer) error
RunCommand runs a command with args. args gets split on spaces (respecting quoted strings).
func RunCommands ¶ added in v0.7.0
func RunCommands(logger Logger, namespace string, command string, commands []kudo.Command, workdir string) []error
RunCommands runs a set of commands, returning any errors. If `command` is set, then `command` will be the command that is invoked (if a command specifies it already, it will not be prepended again).
func RunKubectlCommands ¶ added in v0.5.0
RunKubectlCommands runs a set of kubectl commands, returning any errors.
func RunTests ¶
RunTests runs a Go test method without requiring the Go compiler. This does not currently support test caching. If testToRun is set to a non-empty string, it is passed as a `-run` argument to the go test harness. If paralellism is set, it limits the number of concurrently running tests.
func SetAnnotation ¶
SetAnnotation sets the given key and value in the object's annotations, returning a copy.
func ValidateErrors ¶
ValidateErrors accepts an error as its first argument and passes it to each function in the errValidationFuncs slice, if any of the methods returns true, the method returns nil, otherwise it returns the original error.
func WaitForCRDs ¶
func WaitForCRDs(dClient discovery.DiscoveryInterface, crds []runtime.Object) error
WaitForCRDs waits for the provided CRD types to be available in the Kubernetes API.
func WaitForDelete ¶ added in v0.6.0
func WaitForDelete(c *RetryClient, objs []runtime.Object) error
WaitForDelete waits for the provide runtime objects to be deleted from cluster
func WithAnnotations ¶
WithAnnotations sets the annotations on an object.
func WithKeyValue ¶
func WithKeyValue(obj runtime.Object, key string, value map[string]interface{}) (runtime.Object, error)
WithKeyValue sets key in the provided object to value.
func WithLabels ¶
WithLabels sets the labels on an object.
func WithNamespace ¶
WithNamespace naively applies the namespace to the object. Used mainly in tests, otherwise use Namespaced.
Types ¶
type Client ¶ added in v0.4.0
type Client interface { client.Client // Watch watches a specific object and returns all events for it. Watch(ctx context.Context, obj runtime.Object) (watch.Interface, error) }
Client is the controller-runtime Client interface with an added Watch method.
type DockerClient ¶ added in v0.7.0
type DockerClient interface { NegotiateAPIVersion(context.Context) VolumeCreate(context.Context, volumetypes.VolumeCreateBody) (dockertypes.Volume, error) }
DockerClient is a wrapper interface for the Docker library to support unit testing.
type DynamicRESTMapper ¶ added in v0.4.0
type DynamicRESTMapper struct {
// contains filtered or unexported fields
}
DynamicRESTMapper dynamically discovers resource types at runtime.
func (*DynamicRESTMapper) KindFor ¶ added in v0.4.0
func (drm *DynamicRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
func (*DynamicRESTMapper) KindsFor ¶ added in v0.4.0
func (drm *DynamicRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
KindsFor takes a partial resource and returns the list of potential kinds in priority order
func (*DynamicRESTMapper) RESTMapping ¶ added in v0.4.0
func (drm *DynamicRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
RESTMapping identifies a preferred resource mapping for the provided group kind.
func (*DynamicRESTMapper) RESTMappings ¶ added in v0.4.0
func (drm *DynamicRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
RESTMappings returns all resource mappings for the provided group kind if no version search is provided. Otherwise identifies a preferred resource mapping for the provided version(s).
func (*DynamicRESTMapper) ResourceFor ¶ added in v0.4.0
func (drm *DynamicRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
func (*DynamicRESTMapper) ResourceSingularizer ¶ added in v0.4.0
func (drm *DynamicRESTMapper) ResourceSingularizer(resource string) (singular string, err error)
ResourceSingularizer converts a resource from its plural name to its singular form.
func (*DynamicRESTMapper) ResourcesFor ¶ added in v0.4.0
func (drm *DynamicRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
ResourcesFor takes a partial resource and returns the list of potential resource in priority order
type Logger ¶
type Logger interface { Log(args ...interface{}) Logf(format string, args ...interface{}) WithPrefix(string) Logger }
Logger is an interface used by the KUDO test operator to provide logging of tests.
type RetryClient ¶ added in v0.4.0
RetryClient implements the Client interface, with retries built in.
func NewRetryClient ¶ added in v0.4.0
NewRetryClient initializes a new Kubernetes client that automatically retries on network-related errors.
func (*RetryClient) Create ¶ added in v0.4.0
func (r *RetryClient) Create(ctx context.Context, obj runtime.Object, opts ...client.CreateOption) error
Create saves the object obj in the Kubernetes cluster.
func (*RetryClient) Delete ¶ added in v0.4.0
func (r *RetryClient) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error
Delete deletes the given obj from Kubernetes cluster.
func (*RetryClient) DeleteAllOf ¶ added in v0.6.0
func (r *RetryClient) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error
DeleteAllOf deletes the given obj from Kubernetes cluster.
func (*RetryClient) Get ¶ added in v0.4.0
Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.
func (*RetryClient) List ¶ added in v0.4.0
func (r *RetryClient) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error
List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.
func (*RetryClient) Patch ¶ added in v0.4.0
func (r *RetryClient) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) error
Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
func (*RetryClient) Status ¶ added in v0.4.0
func (r *RetryClient) Status() client.StatusWriter
Status returns a client which can update status subresource for kubernetes objects.
func (*RetryClient) Update ¶ added in v0.4.0
func (r *RetryClient) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error
Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
type RetryStatusWriter ¶ added in v0.4.0
type RetryStatusWriter struct {
StatusWriter client.StatusWriter
}
RetryStatusWriter implements the StatusWriter interface, with retries built in.
func (*RetryStatusWriter) Patch ¶ added in v0.4.0
func (r *RetryStatusWriter) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) error
Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
func (*RetryStatusWriter) Update ¶ added in v0.4.0
func (r *RetryStatusWriter) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error
Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.
type SubsetError ¶
type SubsetError struct {
// contains filtered or unexported fields
}
SubsetError is an error type used by IsSubset for tracking the path in the struct.
func (*SubsetError) AppendPath ¶
func (e *SubsetError) AppendPath(key string)
AppendPath appends key to the existing struct path. For example, in struct member `a.Key1.Key2`, the path would be ["Key1", "Key2"]
func (*SubsetError) Error ¶
func (e *SubsetError) Error() string
Error implements the error interface.
type TestEnvironment ¶ added in v0.4.0
type TestEnvironment struct { Environment *envtest.Environment Config *rest.Config Client Client DiscoveryClient discovery.DiscoveryInterface }
TestEnvironment is a struct containing the envtest environment, Kubernetes config and clients.
func StartTestEnvironment ¶ added in v0.4.0
func StartTestEnvironment() (env TestEnvironment, err error)
StartTestEnvironment is a wrapper for controller-runtime's envtest that creates a Kubernetes API server and etcd suitable for use in tests.
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger implements the Logger interface to be compatible with the go test operator's output buffering (without this, the use of Parallel tests combined with subtests causes test output to be mixed).
func NewTestLogger ¶
func NewTestLogger(test *testing.T, prefix string) *TestLogger
NewTestLogger creates a new test logger.
func (*TestLogger) Log ¶
func (t *TestLogger) Log(args ...interface{})
Log logs the provided arguments with the logger's prefix. See testing.Log for more details.
func (*TestLogger) Logf ¶
func (t *TestLogger) Logf(format string, args ...interface{})
Logf logs the provided arguments with the logger's prefix. See testing.Logf for more details.
func (*TestLogger) WithPrefix ¶
func (t *TestLogger) WithPrefix(prefix string) Logger
WithPrefix returns a new TestLogger with the provided prefix appended to the current prefix.