Last active
March 5, 2018 23:27
-
-
Save ethanfrogers/3c328146d7aee939c40b1d47fa8ea924 to your computer and use it in GitHub Desktop.
Kubernete client-go example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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