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


Golang Interface.UpdateReplicationController方法代码示例

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


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

示例1: ResizeController

// ResizeController resizes a controller named 'name' by setting replicas to 'replicas'
func ResizeController(name string, replicas int, client client.Interface) error {
	controller, err := client.GetReplicationController(name)
	if err != nil {
		return err
	}
	controller.DesiredState.Replicas = replicas
	controllerOut, err := client.UpdateReplicationController(controller)
	if err != nil {
		return err
	}
	data, err := yaml.Marshal(controllerOut)
	if err != nil {
		return err
	}
	fmt.Print(string(data))
	return nil
}
开发者ID:Barba-studio,项目名称:kubernetes,代码行数:18,代码来源:kubecfg.go

示例2: Update

// Update performs a rolling update of a collection of pods.
// 'name' points to a replication controller.
// 'client' is used for updating pods.
// 'updatePeriod' is the time between pod updates.
// 'imageName' is the new image to update for the template.  This will work
//     with the first container in the pod.  There is no support yet for
//     updating more complex replication controllers.  If this is blank then no
//     update of the image is performed.
func Update(name string, client client.Interface, updatePeriod time.Duration, imageName string) error {
	controller, err := client.GetReplicationController(name)
	if err != nil {
		return err
	}

	if len(imageName) != 0 {
		controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image = imageName
		controller, err = client.UpdateReplicationController(controller)
		if err != nil {
			return err
		}
	}

	s := labels.Set(controller.DesiredState.ReplicaSelector).AsSelector()

	podList, err := client.ListPods(s)
	if err != nil {
		return err
	}
	expected := len(podList.Items)
	if expected == 0 {
		return nil
	}
	for _, pod := range podList.Items {
		// We delete the pod here, the controller will recreate it.  This will result in pulling
		// a new Docker image.  This isn't a full "update" but it's what we support for now.
		err = client.DeletePod(pod.ID)
		if err != nil {
			return err
		}
		time.Sleep(updatePeriod)
	}
	return wait.Poll(time.Second*5, time.Second*300, func() (bool, error) {
		podList, err := client.ListPods(s)
		if err != nil {
			return false, err
		}
		return len(podList.Items) == expected, nil
	})
}
开发者ID:asim,项目名称:kubernetes,代码行数:49,代码来源:kubecfg.go


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