Skip to content

Instantly share code, notes, and snippets.

@ethanfrogers
Last active March 5, 2018 23:27
Show Gist options
  • Save ethanfrogers/3c328146d7aee939c40b1d47fa8ea924 to your computer and use it in GitHub Desktop.
Save ethanfrogers/3c328146d7aee939c40b1d47fa8ea924 to your computer and use it in GitHub Desktop.
Kubernete client-go example
package namespaces
import (
"fmt"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
type KubernetesAPI struct {
Suffix string
Client kubernetes.Interface
}
// NewNamespaceWithPostfix creates a new namespace with a stable postfix
func (k KubernetesAPI) NewNamespaceWithSuffix(namespace string) error {
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", namespace, k.Suffix),
},
}
_, err := k.Client.CoreV1().Namespaces().Create(ns)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment