Documentation
¶
Overview ¶
Package gentest contains tests for the client generator.
Index ¶
- Constants
- Variables
- func ConditionDeleted(_ *v1.Pod, apiErr error) (bool, error)
- func ConditionInitializedTrue(obj *v1.Pod, err error) (bool, error)
- func ConditionReadyTrue(obj *v1.Pod, err error) (bool, error)
- func ExtractConditions(obj *v1.Pod) (extracted []apis.Condition)
- func FormatDiff(w io.Writer, leftName, rightName string, left, right *v1.Pod)
- func ObservedGenerationMatchesGeneration(obj *v1.Pod) bool
- type Client
- type ClientExtension
- type ConditionFuncE
- type CreateOption
- type CreateOptions
- type DeleteOption
- type DeleteOptions
- type GetOption
- type GetOptions
- type List
- type ListOption
- type ListOptions
- type Merger
- type Mutator
- type Predicate
- type UpdateOption
- type UpdateOptions
Examples ¶
Constants ¶
const ( // Kind contains the kind for the backing Kubernetes API. Kind = "Pod" // APIVersion contains the version for the backing Kubernetes API. APIVersion = "v1" )
Variables ¶
var ( ConditionReady = apis.ConditionType("Ready") ConditionInitialized = apis.ConditionType(v1.PodInitialized) )
Functions ¶
func ConditionDeleted ¶
ConditionDeleted is a ConditionFuncE that succeeds if the error returned by the cluster was a not found error.
func ConditionInitializedTrue ¶ added in v0.2.0
ConditionInitializedTrue is a ConditionFuncE that waits for Condition{Initialized v1.PodInitialized } to become true and fails with an error if the condition becomes false.
func ConditionReadyTrue ¶ added in v0.2.0
ConditionReadyTrue is a ConditionFuncE that waits for Condition{Ready Ready} to become true and fails with an error if the condition becomes false.
func ExtractConditions ¶ added in v0.2.0
ExtractConditions converts the native condition types into an apis.Condition array with the Type, Status, Reason, and Message fields intact.
func FormatDiff ¶
FormatDiff creates a diff between two v1.Pods and writes it to the given writer.
func ObservedGenerationMatchesGeneration ¶ added in v0.2.0
ObservedGenerationMatchesGeneration is a predicate that returns true if the object's ObservedGeneration matches the genration of the object.
Types ¶
type Client ¶
type Client interface { Create(namespace string, obj *v1.Pod, opts ...CreateOption) (*v1.Pod, error) Update(namespace string, obj *v1.Pod, opts ...UpdateOption) (*v1.Pod, error) Transform(namespace string, name string, transformer Mutator) (*v1.Pod, error) Get(namespace string, name string, opts ...GetOption) (*v1.Pod, error) Delete(namespace string, name string, opts ...DeleteOption) error List(namespace string, opts ...ListOption) ([]v1.Pod, error) Upsert(namespace string, newObj *v1.Pod, merge Merger) (*v1.Pod, error) WaitFor(ctx context.Context, namespace string, name string, interval time.Duration, condition Predicate) (*v1.Pod, error) WaitForE(ctx context.Context, namespace string, name string, interval time.Duration, condition ConditionFuncE) (*v1.Pod, error) // Utility functions WaitForDeletion(ctx context.Context, namespace string, name string, interval time.Duration) (*v1.Pod, error) WaitForConditionReadyTrue(ctx context.Context, namespace string, name string, interval time.Duration) (*v1.Pod, error) WaitForConditionInitializedTrue(ctx context.Context, namespace string, name string, interval time.Duration) (*v1.Pod, error) // ClientExtension can be used by the developer to extend the client. ClientExtension }
Client is the interface for interacting with v1.Pod types as OperatorConfig CF style objects.
func NewExampleClient ¶
func NewExampleClient(mockK8s v1.PodsGetter) Client
NewExampleClient creates an example client with a mutator and membership validator that filter based on a label.
type ClientExtension ¶
type ClientExtension interface { }
type ConditionFuncE ¶
ConditionFuncE is a callback used by WaitForE. Done should be set to true once the condition succeeds and shouldn't be called anymore. The error will be passed back to the user.
This function MAY retrieve a nil instance and an apiErr. It's up to the function to decide how to handle the apiErr.
type CreateOption ¶
type CreateOption func(*createConfig)
CreateOption is a single option for configuring a createConfig
type CreateOptions ¶
type CreateOptions []CreateOption
CreateOptions is a configuration set defining a createConfig
func CreateOptionDefaults ¶
func CreateOptionDefaults() CreateOptions
CreateOptionDefaults gets the default values for Create.
func (CreateOptions) Extend ¶
func (opts CreateOptions) Extend(other CreateOptions) CreateOptions
Extend creates a new CreateOptions with the contents of other overriding the values set in this CreateOptions.
type DeleteOption ¶
type DeleteOption func(*deleteConfig)
DeleteOption is a single option for configuring a deleteConfig
func WithDeleteForegroundDeletion ¶
func WithDeleteForegroundDeletion(val bool) DeleteOption
WithDeleteForegroundDeletion creates an Option that sets If the resource should be deleted in the foreground.
type DeleteOptions ¶
type DeleteOptions []DeleteOption
DeleteOptions is a configuration set defining a deleteConfig
func DeleteOptionDefaults ¶
func DeleteOptionDefaults() DeleteOptions
DeleteOptionDefaults gets the default values for Delete.
func (DeleteOptions) Extend ¶
func (opts DeleteOptions) Extend(other DeleteOptions) DeleteOptions
Extend creates a new DeleteOptions with the contents of other overriding the values set in this DeleteOptions.
func (DeleteOptions) ForegroundDeletion ¶
func (opts DeleteOptions) ForegroundDeletion() bool
ForegroundDeletion returns the last set value for ForegroundDeletion or the empty value if not set.
type GetOption ¶
type GetOption func(*getConfig)
GetOption is a single option for configuring a getConfig
type GetOptions ¶
type GetOptions []GetOption
GetOptions is a configuration set defining a getConfig
func GetOptionDefaults ¶
func GetOptionDefaults() GetOptions
GetOptionDefaults gets the default values for Get.
func (GetOptions) Extend ¶
func (opts GetOptions) Extend(other GetOptions) GetOptions
Extend creates a new GetOptions with the contents of other overriding the values set in this GetOptions.
type List ¶
List represents a collection of v1.Pod.
func (List) Filter ¶
Filter returns a new list items for which the predicates fails removed.
Example ¶
first := v1.Pod{} first.Name = "ok" second := v1.Pod{} second.Name = "name-too-long-to-pass" list := List{first, second} filtered := list.Filter(func(s *v1.Pod) bool { return len(s.Name) < 8 }) fmt.Println("Results") for _, v := range filtered { fmt.Println("-", v.Name) }
Output: Results - ok
type ListOption ¶
type ListOption func(*listConfig)
ListOption is a single option for configuring a listConfig
func WithListFieldSelector ¶
func WithListFieldSelector(val map[string]string) ListOption
WithListFieldSelector creates an Option that sets A selector on the resource's fields.
func WithListFilter ¶ added in v0.2.0
func WithListFilter(val Predicate) ListOption
WithListFilter creates an Option that sets Filter to apply.
type ListOptions ¶
type ListOptions []ListOption
ListOptions is a configuration set defining a listConfig
func ListOptionDefaults ¶
func ListOptionDefaults() ListOptions
ListOptionDefaults gets the default values for List.
func (ListOptions) Extend ¶
func (opts ListOptions) Extend(other ListOptions) ListOptions
Extend creates a new ListOptions with the contents of other overriding the values set in this ListOptions.
type Mutator ¶
Mutator is a function that changes v1.Pod.
func DiffWrapper ¶
DiffWrapper wraps a mutator and prints out the diff between the original object and the one it returns if there's no error.
Example (Changes) ¶
obj := &v1.Pod{} obj.Spec.Hostname = "opaque" contents := &bytes.Buffer{} wrapper := DiffWrapper(contents, func(obj *v1.Pod) error { obj.Spec.Hostname = "docker-creds" return nil }) fmt.Println("Error:", wrapper(obj)) firstLine := strings.Split(contents.String(), "\n")[0] fmt.Println("First line:", firstLine)
Output: Error: <nil> First line: OperatorConfig Diff (-old +new):
Example (Err) ¶
obj := &v1.Pod{} wrapper := DiffWrapper(os.Stdout, func(_ *v1.Pod) error { return errors.New("some-error") }) fmt.Println(wrapper(obj))
Output: some-error
Example (NoDiff) ¶
obj := &v1.Pod{} wrapper := DiffWrapper(os.Stdout, func(s *v1.Pod) error { // don't mutate the object return nil }) wrapper(obj)
Output: No changes
type UpdateOption ¶
type UpdateOption func(*updateConfig)
UpdateOption is a single option for configuring a updateConfig
type UpdateOptions ¶
type UpdateOptions []UpdateOption
UpdateOptions is a configuration set defining a updateConfig
func UpdateOptionDefaults ¶
func UpdateOptionDefaults() UpdateOptions
UpdateOptionDefaults gets the default values for Update.
func (UpdateOptions) Extend ¶
func (opts UpdateOptions) Extend(other UpdateOptions) UpdateOptions
Extend creates a new UpdateOptions with the contents of other overriding the values set in this UpdateOptions.