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


Golang Build.PodID方法代码示例

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


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

示例1: synchronize

// Determine the next status of a build given its current state and the state
// of its associated pod.
// TODO: improve handling of illegal state transitions
func (bc *BuildController) synchronize(build *api.Build) (api.BuildStatus, error) {
	glog.Infof("Syncing build %s", build.ID)

	switch build.Status {
	case api.BuildNew:
		build.PodID = "build-" + string(build.Input.Type) + "-" + build.ID // TODO: better naming
		return api.BuildPending, nil
	case api.BuildPending:
		buildStrategy, ok := bc.buildStrategies[build.Input.Type]
		if !ok {
			return api.BuildError, fmt.Errorf("No build type for %s", build.Input.Type)
		}

		podSpec := buildStrategy.CreateBuildPod(build, bc.dockerRegistry)

		glog.Infof("Attempting to create pod: %#v", podSpec)
		_, err := bc.kubeClient.CreatePod(*podSpec)

		// TODO: strongly typed error checking
		if err != nil {
			if strings.Index(err.Error(), "already exists") != -1 {
				return build.Status, err // no transition, already handled by someone else
			}

			return api.BuildFailed, err
		}

		return api.BuildRunning, nil
	case api.BuildRunning:
		if timedOut := hasTimeoutElapsed(build, bc.timeout); timedOut {
			return api.BuildFailed, fmt.Errorf("Build timed out")
		}

		pod, err := bc.kubeClient.GetPod(build.PodID)
		if err != nil {
			return build.Status, fmt.Errorf("Error retrieving pod for build ID %v: %#v", build.ID, err)
		}

		// pod is still running
		if pod.CurrentState.Status != kubeapi.PodTerminated {
			return build.Status, nil
		}

		var nextStatus = api.BuildComplete

		// check the exit codes of all the containers in the pod
		for _, info := range pod.CurrentState.Info {
			if info.State.ExitCode != 0 {
				nextStatus = api.BuildFailed
			}
		}
		return nextStatus, nil
	case api.BuildComplete, api.BuildFailed, api.BuildError:
		return build.Status, nil
	default:
		return api.BuildError, fmt.Errorf("Invalid build status: %s", build.Status)
	}
}
开发者ID:rajdavies,项目名称:origin,代码行数:61,代码来源:controller.go


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