Help us shape the future of Go! Take the 2026 Go Developer Survey

k8sutil

package
v0.62.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

k8sutil contains test utilities for kubernetes.

Index

Constants

View Source
const FakeConfigMapTemplate = `` /* 180-byte string literal not displayed */

FakeConfigMapTemplate is the template for fake config map.

View Source
const FakeDeploymentTemplate = `` /* 365-byte string literal not displayed */

FakeDeploymentTemplate is the template for fake deployment.

View Source
const FakeSecretTemplate = `
apiVersion: v1
kind: Secret
metadata:
  name: %s
type: Opaque
stringData:
  username: admin
  password: password
`

FakeSecretTemplate is the template for fake secret.

View Source
const FakeServiceAccountTemplate = `` /* 141-byte string literal not displayed */

FakeServiceAccountTemplate is the template for fake service account.

View Source
const FakeServiceTemplate = `` /* 176-byte string literal not displayed */

FakeServiceTemplate is the template for fake service.

View Source
const YAMLSeparator = "\n---\n"

YAMLSeparator is the separator for fake YAML.

Variables

This section is empty.

Functions

func IsolateKubeconfig added in v0.62.0

func IsolateKubeconfig(t *testing.T) string

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

func NewFakeKubeClient(scheme *runtime.Scheme, initObjs ...client.Object) client.WithWatch

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

func WriteKubeconfig(t *testing.T, path string, currentContext string, servers map[string]string)

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

WithLegacy implements discovery.DiscoveryInterface.

type ForbiddenAPIServer added in v0.62.0

type ForbiddenAPIServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL