当前位置: 首页>>代码示例>>Golang>>正文


Golang Interface.Tenants方法代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.Interface.Tenants方法的典型用法代码示例。如果您正苦于以下问题:Golang Interface.Tenants方法的具体用法?Golang Interface.Tenants怎么用?Golang Interface.Tenants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在k8s/io/kubernetes/pkg/client/unversioned.Interface的用法示例。


在下文中一共展示了Interface.Tenants方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: deleteNamespaceFromTenant

func deleteNamespaceFromTenant(kubeClient client.Interface, namespace *api.Namespace) error {
	te, err := kubeClient.Tenants().Get(namespace.Tenant)
	if err != nil {
		return err
	}
	for i, n := range te.Spec.Namespaces {
		if n.Name == namespace.Name {
			te.Spec.Namespaces = append(te.Spec.Namespaces[:i], te.Spec.Namespaces[i+1:]...)
			break
		}
	}
	if _, err = kubeClient.Tenants().Update(te); err != nil {
		return err
	}
	return nil
}
开发者ID:kuenzaa,项目名称:hypernetes,代码行数:16,代码来源:namespace_controller.go

示例2: syncTenant

// syncTenant orchestrates deletion of a Tenant and its associated content.
func syncTenant(kubeClient client.Interface, versions *unversioned.APIVersions, tenant *api.Tenant) (err error) {
	if tenant.DeletionTimestamp == nil {
		return nil
	}

	// there may still be content for us to remove
	estimate, err := deleteAllContent(kubeClient, versions, tenant.Name, *tenant.DeletionTimestamp)
	if err != nil {
		return err
	}
	if estimate > 0 {
		return &contentRemainingError{estimate}
	}

	err = kubeClient.Tenants().Delete(tenant.Name)
	if err != nil && !errors.IsNotFound(err) {
		return err
	}

	return nil
}
开发者ID:kuenzaa,项目名称:hypernetes,代码行数:22,代码来源:tenant_controller.go

示例3: syncTenantAndNamespace

func syncTenantAndNamespace(kubeClient client.Interface, namespace *api.Namespace) error {
	if namespace.Tenant == "" {
		namespace.Tenant = api.TenantDefault
	}
	te, err := kubeClient.Tenants().Get(namespace.Tenant)
	if err != nil {
		return err
	}
	for i, n := range te.Spec.Namespaces {
		if n.Name == namespace.Name {
			te.Spec.Namespaces = append(te.Spec.Namespaces[:i], te.Spec.Namespaces[i+1:]...)
			break
		}
	}
	te.Spec.Namespaces = append(te.Spec.Namespaces, *namespace)

	if _, err = kubeClient.Namespaces().Update(namespace); err != nil {
		return err
	}
	if _, err = kubeClient.Tenants().Update(te); err != nil {
		return err
	}
	return nil
}
开发者ID:kuenzaa,项目名称:hypernetes,代码行数:24,代码来源:namespace_controller.go

示例4: NewTenantController

// NewTenantController creates a new TenantController
func NewTenantController(kubeClient client.Interface, versions *unversioned.APIVersions, resyncPeriod time.Duration) *TenantController {
	var controller *framework.Controller
	_, controller = framework.NewInformer(
		&cache.ListWatch{
			ListFunc: func() (runtime.Object, error) {
				return kubeClient.Tenants().List(labels.Everything(), fields.Everything())
			},
			WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
				return kubeClient.Tenants().Watch(labels.Everything(), fields.Everything(), options)
			},
		},
		&api.Tenant{},
		// TODO: Can we have much longer period here?
		resyncPeriod,
		framework.ResourceEventHandlerFuncs{
			AddFunc: func(obj interface{}) {
				tenant := obj.(*api.Tenant)
				if err := syncTenant(kubeClient, versions, tenant); err != nil {
					if estimate, ok := err.(*contentRemainingError); ok {
						go func() {
							// Estimate is the aggregate total of TerminationGracePeriodSeconds, which defaults to 30s
							// for pods.  However, most processes will terminate faster - within a few seconds, probably
							// with a peak within 5-10s.  So this division is a heuristic that avoids waiting the full
							// duration when in many cases things complete more quickly. The extra second added is to
							// ensure we never wait 0 seconds.
							t := estimate.Estimate/2 + 1
							glog.V(4).Infof("Content remaining in tenant %s, waiting %d seconds", tenant.Name, t)
							time.Sleep(time.Duration(t) * time.Second)
							if err := controller.Requeue(tenant); err != nil {
								util.HandleError(err)
							}
						}()
						return
					}
					util.HandleError(err)
				}
			},
			UpdateFunc: func(oldObj, newObj interface{}) {
				tenant := newObj.(*api.Tenant)
				if err := syncTenant(kubeClient, versions, tenant); err != nil {
					if estimate, ok := err.(*contentRemainingError); ok {
						go func() {
							t := estimate.Estimate/2 + 1
							glog.V(4).Infof("Content remaining in tenant %s, waiting %d seconds", tenant.Name, t)
							time.Sleep(time.Duration(t) * time.Second)
							if err := controller.Requeue(tenant); err != nil {
								util.HandleError(err)
							}
						}()
						return
					}
					util.HandleError(err)
				}
			},
		},
	)

	return &TenantController{
		controller: controller,
	}
}
开发者ID:kuenzaa,项目名称:hypernetes,代码行数:62,代码来源:tenant_controller.go


注:本文中的k8s/io/kubernetes/pkg/client/unversioned.Interface.Tenants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。