import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/api/v1" ) func createNamespace(client *unversioned.Client, name string) (*v1.Namespace, error) { namespace := &v1.Namespace{ ObjectMeta: v1.ObjectMeta{ Name: name, }, } return client.Namespaces().Create(namespace) }
import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/api/v1" "fmt" ) func listNamespaces(client *unversioned.Client) (*v1.NamespaceList, error) { return client.Namespaces().List(v1.ListOptions{}) } func main() { client, err := unversioned.NewInCluster() if err != nil { panic(err) } namespaces, err := listNamespaces(client) if err != nil { panic(err) } for _, ns := range namespaces.Items { fmt.Println(ns.ObjectMeta.Name) } }In this example, we list all the namespaces in the cluster by calling the `List` method on the namespace client with no options. We then iterate over the resulting `v1.NamespaceList` and print out the name of each namespace. Both of these examples use the `k8s.io/kubernetes/pkg/client/unversioned` package.