本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/clientset_generated/internalclientset.Clientset.Namespaces方法的典型用法代码示例。如果您正苦于以下问题:Golang Clientset.Namespaces方法的具体用法?Golang Clientset.Namespaces怎么用?Golang Clientset.Namespaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/clientset_generated/internalclientset.Clientset
的用法示例。
在下文中一共展示了Clientset.Namespaces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateNamespace
// CreateNamespace creates namespace based on given specification.
func CreateNamespace(spec *NamespaceSpec, client *client.Clientset) error {
log.Printf("Creating namespace %s", spec.Name)
namespace := &api.Namespace{
ObjectMeta: api.ObjectMeta{
Name: spec.Name,
},
}
_, err := client.Namespaces().Create(namespace)
return err
}
示例2: watchProxyTest
func watchProxyTest(cluster1AdminKubeClient, cluster2AdminKubeClient *kclientset.Clientset, t *testing.T) {
// list namespaces in order to determine correct resourceVersion
namespaces, err := cluster1AdminKubeClient.Namespaces().List(kapi.ListOptions{})
// open a watch on Cluster 2 for namespaces starting with latest resourceVersion
namespaceWatch, err := cluster2AdminKubeClient.Namespaces().Watch(kapi.ListOptions{ResourceVersion: namespaces.ResourceVersion})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer namespaceWatch.Stop()
// add namespace in Cluster 2
namespace := &kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: "test-namespace"},
}
createdNamespace, err := cluster2AdminKubeClient.Namespaces().Create(namespace)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// consume watch output and record it if it's the event we want to see
select {
case e := <-namespaceWatch.ResultChan():
// check that the watch shows the new namespace
if e.Type != watch.Added {
t.Fatalf("expected an Added event but got: %v", e)
}
addedNamespace, ok := e.Object.(*kapi.Namespace)
if !ok {
t.Fatalf("unexpected cast error from event Object to Namespace")
}
if addedNamespace.ObjectMeta.Name != createdNamespace.Name {
t.Fatalf("namespace returned from Watch is not the same ast that created: got %v, wanted %v", createdNamespace, addedNamespace)
}
case <-time.After(10 * time.Second):
t.Fatal("Timed out waiting for watch")
}
}