Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arbitrary labels to docker images #11209

Merged
merged 2 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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