//setBuildAnnotationAndLabel set annotations and label info of this build func setBuildAnnotationAndLabel(bcCopy *buildapi.BuildConfig, build *buildapi.Build) { if build.Annotations == nil { build.Annotations = make(map[string]string) } //bcCopy.Status.LastVersion has been increased build.Annotations[buildapi.BuildNumberAnnotation] = strconv.FormatInt(bcCopy.Status.LastVersion, 10) build.Annotations[buildapi.BuildConfigAnnotation] = bcCopy.Name if build.Labels == nil { build.Labels = make(map[string]string) } build.Labels[buildapi.BuildConfigLabelDeprecated] = buildapi.LabelValue(bcCopy.Name) build.Labels[buildapi.BuildConfigLabel] = buildapi.LabelValue(bcCopy.Name) build.Labels[buildapi.BuildRunPolicyLabel] = string(bcCopy.Spec.RunPolicy) }
// nextBuildPhase updates build with any appropriate changes, or returns an error if // the change cannot occur. When returning nil, be sure to set build.Status and optionally // build.Message. func (bc *BuildController) nextBuildPhase(build *buildapi.Build) error { // If a cancelling event was triggered for the build, update build status. if build.Status.Cancelled { glog.V(4).Infof("Cancelling build %s/%s.", build.Namespace, build.Name) build.Status.Phase = buildapi.BuildPhaseCancelled build.Status.Reason = "" build.Status.Message = "" return nil } // these builds are processed/updated/etc by the jenkins sync plugin if build.Spec.Strategy.JenkinsPipelineStrategy != nil { glog.V(4).Infof("Ignoring build with jenkins pipeline strategy") return nil } // Set the output Docker image reference. ref, err := bc.resolveOutputDockerImageReference(build) if err != nil { build.Status.Reason = buildapi.StatusReasonInvalidOutputReference return err } build.Status.OutputDockerImageReference = ref // Make a copy to avoid mutating the build from this point on. copy, err := kapi.Scheme.Copy(build) if err != nil { return fmt.Errorf("unable to copy build: %v", err) } buildCopy := copy.(*buildapi.Build) // TODO(rhcarvalho) // The S2I and Docker builders expect build.Spec.Output.To to contain a // resolved reference to a Docker image. Since build.Spec is immutable, we // change a copy (that is never persisted) and pass it to // bc.BuildStrategy.CreateBuildPod. We should make the builders use // build.Status.OutputDockerImageReference, what will make copying the build // unnecessary. if build.Spec.Output.To != nil && len(build.Spec.Output.To.Name) != 0 { buildCopy.Spec.Output.To = &kapi.ObjectReference{ Kind: "DockerImage", Name: ref, } } // Invoke the strategy to get a build pod. podSpec, err := bc.BuildStrategy.CreateBuildPod(buildCopy) if err != nil { build.Status.Reason = buildapi.StatusReasonCannotCreateBuildPodSpec if strategy.IsFatal(err) { return strategy.FatalError(fmt.Sprintf("failed to create a build pod spec for build %s/%s: %v", build.Namespace, build.Name, err)) } return fmt.Errorf("failed to create a build pod spec for build %s/%s: %v", build.Namespace, build.Name, err) } glog.V(4).Infof("Pod %s for build %s/%s is about to be created", podSpec.Name, build.Namespace, build.Name) if _, err := bc.PodManager.CreatePod(build.Namespace, podSpec); err != nil { if errors.IsAlreadyExists(err) { bc.Recorder.Eventf(build, kapi.EventTypeWarning, "failedCreate", "Pod already exists: %s/%s", podSpec.Namespace, podSpec.Name) glog.V(4).Infof("Build pod already existed: %#v", podSpec) return nil } // Log an event if the pod is not created (most likely due to quota denial). bc.Recorder.Eventf(build, kapi.EventTypeWarning, "FailedCreate", "Error creating: %v", err) build.Status.Reason = buildapi.StatusReasonCannotCreateBuildPod return fmt.Errorf("failed to create build pod: %v", err) } if build.Annotations == nil { build.Annotations = make(map[string]string) } build.Annotations[buildapi.BuildPodNameAnnotation] = podSpec.Name glog.V(4).Infof("Created pod for build: %#v", podSpec) // Set the build phase, which will be persisted. build.Status.Phase = buildapi.BuildPhasePending build.Status.Reason = "" build.Status.Message = "" return nil }
func setBuildPodNameAnnotation(build *buildapi.Build, podName string) { if build.Annotations == nil { build.Annotations = map[string]string{} } build.Annotations[buildapi.BuildPodNameAnnotation] = podName }