Documentation
¶
Overview ¶
k8sutil contains test utilities for kubernetes.
Index ¶
- Constants
- func IsolateKubeconfig(t *testing.T) string
- func NewFakeKubeClient(scheme *runtime.Scheme, initObjs ...client.Object) client.WithWatch
- func PrependPatchReactor(f *k8sfake.Clientset, resource string, ...)
- func WriteKubeconfig(t *testing.T, path string, currentContext string, servers map[string]string)
- type DiscoveryClient
- func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error)
- func (d *DiscoveryClient) OpenAPIV3() openapi.Client
- func (d *DiscoveryClient) RESTClient() rest.Interface
- func (d *DiscoveryClient) ServerGroups() (*metav1.APIGroupList, error)
- func (d *DiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
- func (d *DiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
- func (d *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error)
- func (d *DiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
- func (d *DiscoveryClient) ServerVersion() (*version.Info, error)
- func (d *DiscoveryClient) WithLegacy() discovery.DiscoveryInterface
- type ForbiddenAPIServer
Constants ¶
const FakeConfigMapTemplate = `` /* 180-byte string literal not displayed */
FakeConfigMapTemplate is the template for fake config map.
const FakeDeploymentTemplate = `` /* 365-byte string literal not displayed */
FakeDeploymentTemplate is the template for fake deployment.
const FakeSecretTemplate = `
apiVersion: v1
kind: Secret
metadata:
name: %s
type: Opaque
stringData:
username: admin
password: password
`
FakeSecretTemplate is the template for fake secret.
const FakeServiceAccountTemplate = `` /* 141-byte string literal not displayed */
FakeServiceAccountTemplate is the template for fake service account.
const FakeServiceTemplate = `` /* 176-byte string literal not displayed */
FakeServiceTemplate is the template for fake service.
const YAMLSeparator = "\n---\n"
YAMLSeparator is the separator for fake YAML.
Variables ¶
This section is empty.
Functions ¶
func IsolateKubeconfig ¶ added in v0.62.0
IsolateKubeconfig makes kubeconfig loading ignore the user's real kubeconfig files for the rest of the test. It unsets KUBECONFIG, sets HOME to a new temporary directory, and points clientcmd.RecommendedHomeFile into that directory. It returns the new default kubeconfig path, which does not exist until the test writes it.
client-go sets clientcmd.RecommendedHomeFile once, when the package loads, so setting HOME alone does not change the default path. Tests that call IsolateKubeconfig must not call t.Parallel.
func NewFakeKubeClient ¶
NewFakeKubeClient create new fake kube dynamic client with the given scheme and initial objects.
func PrependPatchReactor ¶
func PrependPatchReactor(f *k8sfake.Clientset, resource string, objFunc func(clienttesting.PatchAction) runtime.Object)
PrependPatchReactor prepends patch reactor to fake client. This is workaround because clientset fake doesn't support patch verb. https://github.com/kubernetes/client-go/issues/1184
func WriteKubeconfig ¶ added in v0.62.0
WriteKubeconfig writes a kubeconfig file to path and creates its parent directory. Each key in servers is the name of a context, cluster, and user, and its value is the server URL of that cluster.
Types ¶
type DiscoveryClient ¶
type DiscoveryClient struct {
Groups *metav1.APIGroupList
Resources []*metav1.APIResourceList
APIGroup []*metav1.APIGroup
}
func (*DiscoveryClient) OpenAPISchema ¶ added in v0.43.0
func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error)
OpenAPISchema implements discovery.DiscoveryInterface.
func (*DiscoveryClient) OpenAPIV3 ¶ added in v0.43.0
func (d *DiscoveryClient) OpenAPIV3() openapi.Client
OpenAPIV3 implements discovery.DiscoveryInterface.
func (*DiscoveryClient) RESTClient ¶ added in v0.43.0
func (d *DiscoveryClient) RESTClient() rest.Interface
RESTClient implements discovery.DiscoveryInterface.
func (*DiscoveryClient) ServerGroups ¶
func (d *DiscoveryClient) ServerGroups() (*metav1.APIGroupList, error)
ServerGroups returns a list of API groups supported by the server.
func (*DiscoveryClient) ServerGroupsAndResources ¶
func (d *DiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
ServerGroupsAndResources returns a list of API groups and resources associated with the discovery client.
func (*DiscoveryClient) ServerPreferredNamespacedResources ¶
func (d *DiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
This function returns a slice of API resource lists.
func (*DiscoveryClient) ServerPreferredResources ¶
func (d *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error)
This function returns a slice of API resource lists.
func (*DiscoveryClient) ServerResourcesForGroupVersion ¶
func (d *DiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
ServerResourcesForGroupVersion returns nil for the API resource list.
func (*DiscoveryClient) ServerVersion ¶ added in v0.43.0
func (d *DiscoveryClient) ServerVersion() (*version.Info, error)
ServerVersion implements discovery.DiscoveryInterface.
func (*DiscoveryClient) WithLegacy ¶ added in v0.43.0
func (d *DiscoveryClient) WithLegacy() discovery.DiscoveryInterface
WithLegacy implements discovery.DiscoveryInterface.
type ForbiddenAPIServer ¶ added in v0.62.0
ForbiddenAPIServer is a fake Kubernetes API server that records each request and rejects it with 403 Forbidden. Tests use it to check which cluster a client sends requests to. The client cannot change anything.
func NewForbiddenAPIServer ¶ added in v0.62.0
func NewForbiddenAPIServer(t *testing.T) *ForbiddenAPIServer
NewForbiddenAPIServer starts a ForbiddenAPIServer and closes it when the test ends.
func (*ForbiddenAPIServer) Requests ¶ added in v0.62.0
func (s *ForbiddenAPIServer) Requests() []string
Requests returns the method and path of each request that the server received, in order.