Documentation ¶
Overview ¶
Package util contains common functions that are used by the rest of the OpenShift build system.
Index ¶
- Constants
- Variables
- func BuildConfigBuilds(c buildlister.BuildLister, namespace, name string, filterFunc buildFilter) ([]*buildv1.Build, error)
- func BuildConfigSelector(name string) labels.Selector
- func BuildNameForConfigVersion(name string, version int) string
- func ConfigNameForBuild(build *buildv1.Build) string
- func FetchServiceAccountSecrets(client ktypedclient.CoreV1Interface, namespace, serviceAccount string) ([]corev1.Secret, error)
- func FindDockerSecretAsReference(secrets []corev1.Secret, image string) *corev1.LocalObjectReference
- func GetBuildEnv(build *buildv1.Build) []corev1.EnvVar
- func GetBuildPodName(build *buildv1.Build) string
- func GetInputReference(strategy buildv1.BuildStrategy) *corev1.ObjectReference
- func IsBuildComplete(build *buildv1.Build) bool
- func IsFatalGeneratorError(err error) bool
- func IsTerminalPhase(phase buildv1.BuildPhase) bool
- func MergeEnvWithoutDuplicates(source []corev1.EnvVar, output *[]corev1.EnvVar, sourcePrecedence bool, ...)
- func MergeTrustedEnvWithoutDuplicates(source []corev1.EnvVar, output *[]corev1.EnvVar, sourcePrecedence bool)
- func ParseProxyURL(proxy string) (*url.URL, error)
- func SetBuildEnv(build *buildv1.Build, env []corev1.EnvVar)
- func UpdateBuildEnv(build *buildv1.Build, env []corev1.EnvVar)
- func UpdateCustomImageEnv(strategy *buildv1.CustomBuildStrategy, newImage string)
- type GeneratorFatalError
Constants ¶
const ( // BuildAnnotation is an annotation that identifies a Pod as being for a Build BuildAnnotation = "openshift.io/build.name" // BuildConfigAnnotation is an annotation that identifies the BuildConfig that a Build was created from BuildConfigAnnotation = "openshift.io/build-config.name" // BuildNumberAnnotation is an annotation whose value is the sequential number for this Build BuildNumberAnnotation = "openshift.io/build.number" // BuildCloneAnnotation is an annotation whose value is the name of the build this build was cloned from BuildCloneAnnotation = "openshift.io/build.clone-of" // BuildPodNameAnnotation is an annotation whose value is the name of the pod running this build BuildPodNameAnnotation = "openshift.io/build.pod-name" // BuildJenkinsStatusJSONAnnotation is an annotation holding the Jenkins status information BuildJenkinsStatusJSONAnnotation = "openshift.io/jenkins-status-json" // BuildJenkinsLogURLAnnotation is an annotation holding a link to the raw Jenkins build console log BuildJenkinsLogURLAnnotation = "openshift.io/jenkins-log-url" // BuildJenkinsConsoleLogURLAnnotation is an annotation holding a link to the Jenkins build console log (including Jenkins chrome wrappering) BuildJenkinsConsoleLogURLAnnotation = "openshift.io/jenkins-console-log-url" // BuildJenkinsBlueOceanLogURLAnnotation is an annotation holding a link to the Jenkins build console log via the Jenkins BlueOcean UI Plugin BuildJenkinsBlueOceanLogURLAnnotation = "openshift.io/jenkins-blueocean-log-url" // BuildJenkinsBuildURIAnnotation is an annotation holding a link to the Jenkins build BuildJenkinsBuildURIAnnotation = "openshift.io/jenkins-build-uri" // BuildSourceSecretMatchURIAnnotationPrefix is a prefix for annotations on a Secret which indicate a source URI against which the Secret can be used BuildSourceSecretMatchURIAnnotationPrefix = "build.openshift.io/source-secret-match-uri-" // BuildLabel is the key of a Pod label whose value is the Name of a Build which is run. // NOTE: The value for this label may not contain the entire Build name because it will be // truncated to maximum label length. BuildLabel = "openshift.io/build.name" // BuildRunPolicyLabel represents the start policy used to to start the build. BuildRunPolicyLabel = "openshift.io/build.start-policy" // AllowedUIDs is an environment variable that contains ranges of UIDs that are allowed in // Source builder images AllowedUIDs = "ALLOWED_UIDS" // DropCapabilities is an environment variable that contains a list of capabilities to drop when // executing a Source build DropCapabilities = "DROP_CAPS" // BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig // on which the Build is based. NOTE: The value for this label may not contain the entire // BuildConfig name because it will be truncated to maximum label length. BuildConfigLabel = "openshift.io/build-config.name" // BuildConfigLabelDeprecated was used as BuildConfigLabel before adding namespaces. // We keep it for backward compatibility. BuildConfigLabelDeprecated = "buildconfig" // BuildConfigPausedAnnotation is an annotation that marks a BuildConfig as paused. // New Builds cannot be instantiated from a paused BuildConfig. BuildConfigPausedAnnotation = "openshift.io/build-config.paused" // BuildStartedEventReason is the reason associated with the event registered when a build is started (pod is created). BuildStartedEventReason = "BuildStarted" // BuildStartedEventMessage is the message associated with the event registered when a build is started (pod is created). BuildStartedEventMessage = "Build %s/%s is now running" // BuildCompletedEventReason is the reason associated with the event registered when build completes successfully. BuildCompletedEventReason = "BuildCompleted" // BuildCompletedEventMessage is the message associated with the event registered when build completes successfully. BuildCompletedEventMessage = "Build %s/%s completed successfully" // BuildFailedEventReason is the reason associated with the event registered when build fails. BuildFailedEventReason = "BuildFailed" // BuildFailedEventMessage is the message associated with the event registered when build fails. BuildFailedEventMessage = "Build %s/%s failed" // BuildCancelledEventReason is the reason associated with the event registered when build is cancelled. BuildCancelledEventReason = "BuildCancelled" // BuildCancelledEventMessage is the message associated with the event registered when build is cancelled. BuildCancelledEventMessage = "Build %s/%s has been cancelled" )
const ( BuildTriggerCauseManualMsg = "Manually triggered" BuildTriggerCauseConfigMsg = "Build configuration change" BuildTriggerCauseImageMsg = "Image change" BuildTriggerCauseGithubMsg = "GitHub WebHook" BuildTriggerCauseGenericMsg = "Generic WebHook" BuildTriggerCauseGitLabMsg = "GitLab WebHook" BuildTriggerCauseBitbucketMsg = "Bitbucket WebHook" )
const ( StatusMessageCannotCreateBuildPodSpec = "Failed to create pod spec." StatusMessageCannotCreateBuildPod = "Failed creating build pod." StatusMessageInvalidOutputRef = "Output image could not be resolved." StatusMessageInvalidImageRef = "Referenced image could not be resolved." StatusMessageBuildPodDeleted = "The pod for this build was deleted before the build completed." StatusMessageMissingPushSecret = "Missing push secret." StatusMessageCancelledBuild = "The build was cancelled by the user." StatusMessageBuildPodExists = "The pod for this build already exists and is older than the build." StatusMessageNoBuildContainerStatus = "The pod for this build has no container statuses indicating success or failure." StatusMessageFailedContainer = "The pod for this build has at least one container with a non-zero exit status." StatusMessageGenericBuildFailed = "Generic Build failure - check logs for details." StatusMessageOutOfMemoryKilled = "The build pod was killed due to an out of memory condition." StatusMessageUnresolvableEnvironmentVariable = "Unable to resolve build environment variable reference." StatusMessageCannotRetrieveServiceAccount = "Unable to look up the service account secrets for this build." )
const ( // WebHookSecretKey is the key used to identify the value containing the webhook invocation // secret within a secret referenced by a webhook trigger. WebHookSecretKey = "WebHookSecretKey" // CustomBuildStrategyBaseImageKey is the environment variable that indicates the base image to be used when // performing a custom build, if needed. CustomBuildStrategyBaseImageKey = "OPENSHIFT_CUSTOM_BUILD_BASE_IMAGE" )
const ( // NoBuildLogsMessage reports that no build logs are available NoBuildLogsMessage = "No logs are available." // WorkDir is the working directory within the build pod, mounted as a volume. BuildWorkDirMount = "/tmp/build" // BuilderServiceAccountName is the name of the account used to run build pods by default. BuilderServiceAccountName = "builder" )
Variables ¶
var ( // InputContentPath is the path at which the build inputs will be available // to all the build containers. InputContentPath = filepath.Join(BuildWorkDirMount, "inputs") )
var (
WhitelistEnvVarNames = []string{"BUILD_LOGLEVEL", "GIT_SSL_NO_VERIFY"}
)
Functions ¶
func BuildConfigBuilds ¶ added in v1.3.0
func BuildConfigBuilds(c buildlister.BuildLister, namespace, name string, filterFunc buildFilter) ([]*buildv1.Build, error)
BuildConfigBuilds return a list of builds for the given build config. Optionally you can specify a filter function to select only builds that matches your criteria.
func BuildConfigSelector ¶ added in v1.1.2
BuildConfigSelector returns a label Selector which can be used to find all builds for a BuildConfig.
func BuildNameForConfigVersion ¶ added in v1.0.8
BuildNameForConfigVersion returns the name of the version-th build for the config that has the provided name.
func ConfigNameForBuild ¶ added in v1.1.2
ConfigNameForBuild returns the name of the build config from a build name.
func FetchServiceAccountSecrets ¶
func FetchServiceAccountSecrets(client ktypedclient.CoreV1Interface, namespace, serviceAccount string) ([]corev1.Secret, error)
FetchServiceAccountSecrets retrieves the Secrets used for pushing and pulling images from private Docker registries.
func FindDockerSecretAsReference ¶
func FindDockerSecretAsReference(secrets []corev1.Secret, image string) *corev1.LocalObjectReference
FindDockerSecretAsReference looks through a set of k8s Secrets to find one that represents Docker credentials and which contains credentials that are associated with the registry identified by the image. It returns a LocalObjectReference to the Secret, or nil if no match was found.
func GetBuildEnv ¶
GetBuildEnv gets the build strategy environment
func GetBuildPodName ¶ added in v0.4.2
GetBuildPodName returns name of the build pod.
func GetInputReference ¶ added in v1.1.4
func GetInputReference(strategy buildv1.BuildStrategy) *corev1.ObjectReference
GetInputReference returns the From ObjectReference associated with the BuildStrategy.
func IsBuildComplete ¶ added in v0.5.3
IsBuildComplete returns whether the provided build is complete or not
func IsFatalGeneratorError ¶
IsFatal returns true if err is a fatal error
func IsTerminalPhase ¶
func IsTerminalPhase(phase buildv1.BuildPhase) bool
IsTerminalPhase returns true if the provided phase is terminal
func MergeEnvWithoutDuplicates ¶
func MergeEnvWithoutDuplicates(source []corev1.EnvVar, output *[]corev1.EnvVar, sourcePrecedence bool, whitelist []string)
MergeEnvWithoutDuplicates merges two environment lists without having duplicate items in the output list. If sourcePrecedence is true, keys in the source list will override keys in the output list.
func MergeTrustedEnvWithoutDuplicates ¶
func MergeTrustedEnvWithoutDuplicates(source []corev1.EnvVar, output *[]corev1.EnvVar, sourcePrecedence bool)
MergeTrustedEnvWithoutDuplicates merges two environment lists without having duplicate items in the output list. The source list will be filtered such that only whitelisted environment variables are merged into the output list. If sourcePrecedence is true, keys in the source list will override keys in the output list.
func ParseProxyURL ¶
ParseProxyURL parses a proxy URL and allows fallback to non-URLs like myproxy:80 (for example) which url.Parse no longer accepts in Go 1.8. The logic is copied from net/http.ProxyFromEnvironment to try to maintain backwards compatibility.
func SetBuildEnv ¶
SetBuildEnv replaces the current build environment
func UpdateBuildEnv ¶
UpdateBuildEnv updates the strategy environment This will replace the existing variable definitions with provided env
func UpdateCustomImageEnv ¶
func UpdateCustomImageEnv(strategy *buildv1.CustomBuildStrategy, newImage string)
UpdateCustomImageEnv updates base image env variable reference with the new image for a custom build strategy. If no env variable reference exists, create a new env variable.
Types ¶
type GeneratorFatalError ¶
type GeneratorFatalError struct { // Reason the fatal error occurred Reason string }
GeneratorFatalError represents a fatal error while generating a build. An operation that fails because of a fatal error should not be retried.
func (*GeneratorFatalError) Error ¶
func (e *GeneratorFatalError) Error() string
Error returns the error string for this fatal error