Utility functions for work with the Kubernetes Go-Client


This repository contains utils for the work with Kubernetes, in specific with the go-client library.


This package contains utils which are useful for testing (e.g. with the fake-client).


Having the ReactionFunc signature, the following helper exist:

  • GenerateNameReactor: setting the ObjectMeta.Name field, based on ObjectMeta.GenerateName (as ObjectMeta.Name is not set automatically by the fake-client, if only ObjectMeta.GenerateName is set).
  • SecretDataReactor: setting the Secret.Data field based on Secret.StringData (as Secret.Data is not set automatically by the fake-client, if only Secret.StringData is set).


clientset := fake.NewSimpleClientset()
clientset.PrependReactor("create", "pods", GenerateNameReactor)
pod := &v1.Pod{
	ObjectMeta: metav1.ObjectMeta{
		Namespace:    "default",
		GenerateName: "testpod-",
	Spec: v1.PodSpec{
		Containers: []v1.Container{
				Name:  "nginx",
				Image: "nginx",
createdPod, _ := clientset.CoreV1().Pods(pod.Namespace).Create(ctx, pod, metav1.CreateOptions{})
fmt.Printf("Name: %s", createdPod.Name) //remember: the pods Name field was not set, only GenerateName
clientset := fake.NewSimpleClientset()
clientset.PrependReactor("create", "secrets", SecretDataReactor)

secret := &v1.Secret{
	ObjectMeta: metav1.ObjectMeta{
		Namespace: "default",
		Name:      "my-secret",
	StringData: map[string]string{
		"my-key": "my-value",
	Type: v1.SecretTypeOpaque,

createdSecret, _ := clientset.CoreV1().Secrets(secret.Namespace).Create(ctx, secret, metav1.CreateOptions{})

fmt.Printf("Secrets data: %+v", createdSecret.Data) //remember: the secrets StringData field was set, not the Data field


Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Understanding how API routes work in Next.js

What Does the Future Hold for Java?