Documentation
¶
Index ¶
- Variables
- func BuildConfigWithContext(kubeconfig, context string) (*rest.Config, error)
- func CreateOrUpdate(ctx context.Context, cl client.Client, obj client.Object, retryOnError bool) (updated bool, err error)
- func GetAPIResource(dClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (metav1.APIResource, error)
- func GetConfig() (*rest.Config, error)
- func InstallManifests(ctx context.Context, c client.Client, dClient discovery.DiscoveryInterface, ...) ([]*apiextv1.CustomResourceDefinition, error)
- func Kubeconfig(cfg *rest.Config, w io.Writer) error
- func LoadYAML(path string, r io.Reader) ([]client.Object, error)
- func LoadYAMLFromFile(path string) ([]client.Object, 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 NewClusterRoleBinding(apiVersion, kind, name, namespace string, serviceAccount string, ...) runtime.Object
- func NewPod(name, namespace string) *unstructured.Unstructured
- func NewResource(apiVersion, kind, name, namespace string) *unstructured.Unstructured
- func NewV1Pod(name, namespace, serviceAccountName string) *corev1.Pod
- func ObjectKey(obj runtime.Object) client.ObjectKey
- func PrettyDiff(expected *unstructured.Unstructured, actual *unstructured.Unstructured) (string, error)
- func ResourceID(obj runtime.Object) string
- func Scheme() *runtime.Scheme
- func SetAnnotation(obj *unstructured.Unstructured, key, value string) *unstructured.Unstructured
- func WaitForDelete(c *RetryClient, objs []runtime.Object) error
- func WaitForSA(config *rest.Config, name, namespace string) error
- func WithAnnotations(obj runtime.Object, annotations map[string]string) runtime.Object
- func WithKeyValue(obj *unstructured.Unstructured, key string, value map[string]interface{}) (*unstructured.Unstructured, error)
- func WithLabels(t *testing.T, obj *unstructured.Unstructured, labels map[string]string) *unstructured.Unstructured
- func WithNamespace(obj *unstructured.Unstructured, namespace string) *unstructured.Unstructured
- func WithSpec(t *testing.T, obj *unstructured.Unstructured, spec map[string]interface{}) *unstructured.Unstructured
- func WithStatus(t *testing.T, obj *unstructured.Unstructured, status map[string]interface{}) *unstructured.Unstructured
- type Client
- type RetryClient
- func (r *RetryClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
- func (r *RetryClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
- func (r *RetryClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
- func (r *RetryClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (r *RetryClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)
- func (r *RetryClient) IsObjectNamespaced(obj runtime.Object) (bool, error)
- func (r *RetryClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (r *RetryClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, ...) error
- func (r *RetryClient) RESTMapper() meta.RESTMapper
- func (r *RetryClient) Scheme() *runtime.Scheme
- func (r *RetryClient) Status() client.StatusWriter
- func (r *RetryClient) SubResource(subResource string) client.SubResourceClient
- func (r *RetryClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
- func (r *RetryClient) Watch(ctx context.Context, obj runtime.Object) (watch.Interface, error)
- type RetryStatusWriter
- func (r *RetryStatusWriter) Create(ctx context.Context, obj client.Object, subResource client.Object, ...) error
- func (r *RetryStatusWriter) Patch(ctx context.Context, obj client.Object, patch client.Patch, ...) error
- func (r *RetryStatusWriter) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error
- type TestEnvironment
Constants ¶
This section is empty.
Variables ¶
var ImpersonateAs = ""
Functions ¶
func BuildConfigWithContext ¶
func CreateOrUpdate ¶
func CreateOrUpdate(ctx context.Context, cl client.Client, obj client.Object, retryOnError bool) (updated bool, err error)
CreateOrUpdate will create obj if it does not exist and update it if 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 GetAPIResource ¶
func GetAPIResource(dClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (metav1.APIResource, error)
GetAPIResource returns the APIResource object for a specific GroupVersionKind.
func InstallManifests ¶
func InstallManifests(ctx context.Context, c client.Client, dClient discovery.DiscoveryInterface, manifestsDir string, kinds ...runtime.Object) ([]*apiextv1.CustomResourceDefinition, error)
InstallManifests recurses over ManifestsDir to install all resources defined in YAML manifests.
func Kubeconfig ¶
Kubeconfig converts a rest.Config into a YAML kubeconfig and writes it to w
func LoadYAMLFromFile ¶
LoadYAMLFromFile loads all objects from a YAML file.
func MarshalObjectJSON ¶
MarshalObjectJSON marshals a Kubernetes object to a JSON string.
func MatchesKind ¶
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 NewClusterRoleBinding ¶
func NewClusterRoleBinding(apiVersion, kind, name, namespace string, serviceAccount string, roleName string) runtime.Object
NewClusterRoleBinding Create a clusterrolebinding for the serviceAccount passed
func NewPod ¶
func NewPod(name, namespace string) *unstructured.Unstructured
NewPod creates a new pod object.
func NewResource ¶
func NewResource(apiVersion, kind, name, namespace string) *unstructured.Unstructured
NewResource generates a Kubernetes object using the provided apiVersion, kind, name, and namespace. The name and namespace are omitted if empty.
func NewV1Pod ¶
NewV1Pod returns a new corev1.Pod object. Each of name, namespace and serviceAccountName are set if non-empty.
func PrettyDiff ¶
func PrettyDiff(expected *unstructured.Unstructured, actual *unstructured.Unstructured) (string, error)
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 SetAnnotation ¶
func SetAnnotation(obj *unstructured.Unstructured, key, value string) *unstructured.Unstructured
SetAnnotation sets the given key and value in the object's annotations, returning a copy.
func WaitForDelete ¶
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 *unstructured.Unstructured, key string, value map[string]interface{}) (*unstructured.Unstructured, error)
WithKeyValue sets key in the provided object to value.
func WithLabels ¶
func WithLabels(t *testing.T, obj *unstructured.Unstructured, labels map[string]string) *unstructured.Unstructured
WithLabels sets the labels on an object.
func WithNamespace ¶
func WithNamespace(obj *unstructured.Unstructured, namespace string) *unstructured.Unstructured
WithNamespace naively applies the namespace to the object. Used mainly in tests, otherwise use Namespaced.
func WithSpec ¶
func WithSpec(t *testing.T, obj *unstructured.Unstructured, spec map[string]interface{}) *unstructured.Unstructured
WithSpec applies the provided spec to the Kubernetes object.
func WithStatus ¶
func WithStatus(t *testing.T, obj *unstructured.Unstructured, status map[string]interface{}) *unstructured.Unstructured
WithStatus applies the provided status to the Kubernetes object.
Types ¶
type Client ¶
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 RetryClient ¶
RetryClient implements the Client interface, with retries built in.
func NewRetryClient ¶
NewRetryClient initializes a new Kubernetes client that automatically retries on network-related errors.
func (*RetryClient) Create ¶
func (r *RetryClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
Create saves the object obj in the Kubernetes cluster.
func (*RetryClient) Delete ¶
func (r *RetryClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
Delete deletes the given obj from Kubernetes cluster.
func (*RetryClient) DeleteAllOf ¶
func (r *RetryClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
DeleteAllOf deletes the given obj from Kubernetes cluster.
func (*RetryClient) Get ¶
func (r *RetryClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
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) GroupVersionKindFor ¶
func (r *RetryClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)
GroupVersionKindFor returns the GroupVersionKind for the provided object.
func (*RetryClient) IsObjectNamespaced ¶
func (r *RetryClient) IsObjectNamespaced(obj runtime.Object) (bool, error)
IsObjectNamespaced returns true if the object is namespaced.
func (*RetryClient) List ¶
func (r *RetryClient) List(ctx context.Context, list client.ObjectList, 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 ¶
func (r *RetryClient) Patch(ctx context.Context, obj client.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) RESTMapper ¶
func (r *RetryClient) RESTMapper() meta.RESTMapper
RESTMapper returns the rest mapper this client is using.
func (*RetryClient) Scheme ¶
func (r *RetryClient) Scheme() *runtime.Scheme
Scheme returns the scheme this client is using.
func (*RetryClient) Status ¶
func (r *RetryClient) Status() client.StatusWriter
Status returns a client which can update status subresource for kubernetes objects.
func (*RetryClient) SubResource ¶
func (r *RetryClient) SubResource(subResource string) client.SubResourceClient
SubResource returns a subresource client for the named subResource.
func (*RetryClient) Update ¶
func (r *RetryClient) Update(ctx context.Context, obj client.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 ¶
type RetryStatusWriter struct {
StatusWriter client.StatusWriter
}
RetryStatusWriter implements the StatusWriter interface, with retries built in.
func (*RetryStatusWriter) Create ¶
func (r *RetryStatusWriter) Create(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceCreateOption) error
Create saves the subResource object 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) Patch ¶
func (r *RetryStatusWriter) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) 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 ¶
func (r *RetryStatusWriter) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) 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 TestEnvironment ¶
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 ¶
func StartTestEnvironment(attachControlPlaneOutput bool) (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.