Skip to content

Commit

Permalink
Merge pull request #11209 from mmilata/arbitrary-image-labels
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Oct 13, 2016
2 parents c728fe9 + d2c807f commit bc0a4dc
Show file tree
Hide file tree
Showing 39 changed files with 1,343 additions and 349 deletions.
66 changes: 22 additions & 44 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions api/swagger-spec/oapi-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22071,6 +22071,30 @@
"pushSecret": {
"$ref": "v1.LocalObjectReference",
"description": "PushSecret is the name of a Secret that would be used for setting up the authentication for executing the Docker push to authentication enabled Docker Registry (or Docker Hub)."
},
"imageLabels": {
"type": "array",
"items": {
"$ref": "v1.ImageLabel"
},
"description": "imageLabels define a list of labels that are applied to the resulting image. If there are multiple labels with the same name then the last one in the list is used."
}
}
},
"v1.ImageLabel": {
"id": "v1.ImageLabel",
"description": "ImageLabel represents a label applied to the resulting image.",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"description": "name defines the name of the label. It must have non-zero length."
},
"value": {
"type": "string",
"description": "value defines the literal value of the label."
}
}
},
Expand Down
23 changes: 23 additions & 0 deletions api/swagger-spec/openshift-openapi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -44770,6 +44770,13 @@
"v1.BuildOutput": {
"description": "BuildOutput is input to a build strategy and describes the Docker image that the strategy should produce.",
"properties": {
"imageLabels": {
"description": "imageLabels define a list of labels that are applied to the resulting image. If there are multiple labels with the same name then the last one in the list is used.",
"type": "array",
"items": {
"$ref": "#/definitions/v1.ImageLabel"
}
},
"pushSecret": {
"$ref": "#/definitions/v1.LocalObjectReference"
},
Expand Down Expand Up @@ -47742,6 +47749,22 @@
}
}
},
"v1.ImageLabel": {
"description": "ImageLabel represents a label applied to the resulting image.",
"required": [
"name"
],
"properties": {
"name": {
"description": "name defines the name of the label. It must have non-zero length.",
"type": "string"
},
"value": {
"description": "value defines the literal value of the label.",
"type": "string"
}
}
},
"v1.ImageLayer": {
"description": "ImageLayer represents a single layer of the image. Some images may have multiple layers. Some may have none.",
"required": [
Expand Down
18 changes: 18 additions & 0 deletions pkg/build/admission/defaults/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (a *buildDefaults) applyBuildDefaults(build *buildapi.Build) {
addDefaultEnvVar(envVar, buildEnv)
}

// Apply default labels
for _, lbl := range a.defaultsConfig.ImageLabels {
glog.V(5).Infof("Adding default image label %s=%s to build %s/%s", lbl.Name, lbl.Value, build.Namespace, build.Name)
addDefaultLabel(lbl, &build.Spec.Output.ImageLabels)
}

sourceDefaults := a.defaultsConfig.SourceStrategyDefaults
sourceStrategy := build.Spec.Strategy.SourceStrategy
if sourceDefaults != nil && sourceDefaults.Incremental != nil && *sourceDefaults.Incremental &&
Expand Down Expand Up @@ -153,3 +159,15 @@ func addDefaultEnvVar(v kapi.EnvVar, envVars *[]kapi.EnvVar) {
*envVars = append(*envVars, v)
}
}

func addDefaultLabel(defaultLabel buildapi.ImageLabel, buildLabels *[]buildapi.ImageLabel) {
found := false
for _, lbl := range *buildLabels {
if lbl.Name == defaultLabel.Name {
found = true
}
}
if !found {
*buildLabels = append(*buildLabels, defaultLabel)
}
}
Loading

0 comments on commit bc0a4dc

Please sign in to comment.