Skip to content

Commit

Permalink
Merge pull request #1509 from buildpacks-community/0-12-builder-tags
Browse files Browse the repository at this point in the history
[v0.12.x] Backport additional tags for builder
  • Loading branch information
chenbh authored Jan 31, 2024
2 parents dcd2660 + 2bf2282 commit 9287da0
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 7 deletions.
25 changes: 22 additions & 3 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5879,6 +5879,13 @@
"kpack.build.v1alpha2.BuilderSpec": {
"type": "object",
"properties": {
"additionalLabels": {
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6108,6 +6115,13 @@
"kpack.build.v1alpha2.ClusterBuilderSpec": {
"type": "object",
"properties": {
"additionalLabels": {
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6782,6 +6796,13 @@
"kpack.build.v1alpha2.NamespacedBuilderSpec": {
"type": "object",
"properties": {
"additionalLabels": {
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -7159,8 +7180,7 @@
"properties": {
"lastTransitionTime": {
"description": "LastTransitionTime is the last time the condition transitioned from one status to another. We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic differences (all other things held constant).",
"type": "string",
"default": {}
"type": "string"
},
"message": {
"description": "A human readable message indicating details about the transition.",
Expand Down Expand Up @@ -7412,7 +7432,6 @@
],
"properties": {
"inner": {
"default": {},
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Time"
}
}
Expand Down
3 changes: 3 additions & 0 deletions docs/builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
kind: ClusterBuildpack
id: paketo-buildpacks/nodejs
version: 1.2.3
additionalLabels:
custom-label: custom-value
```
* `tag`: The tag to save the builder image. You must have access via the referenced service account.
Expand All @@ -60,6 +62,7 @@ spec:
* `store`: If using ClusterStore, then the reference to the ClusterStore. See the [Resolving Buildpack IDs](#resolving-buildpack-ids) section below.
* `name`: The name of the ClusterStore resource in kubernetes.
* `kind`: The type as defined in kubernetes. This will always be ClusterStore.
* `additionalLabels`: The custom labels that are desired to be on the Builder/ClusterBuilder images.

### <a id='cluster-builders'></a>Cluster Builders

Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/build/v1alpha2/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type BuilderSpec struct {
Stack corev1.ObjectReference `json:"stack,omitempty"`
Store corev1.ObjectReference `json:"store,omitempty"`
// +listType
Order []BuilderOrderEntry `json:"order,omitempty"`
Order []BuilderOrderEntry `json:"order,omitempty"`
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
10 changes: 10 additions & 0 deletions pkg/cnb/builder_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type builderBlder struct {
runImage string
mixins []string
os string
additionalLabels map[string]string
}

func newBuilderBldr(kpackVersion string) *builderBlder {
Expand Down Expand Up @@ -93,6 +94,10 @@ func (bb *builderBlder) AddGroup(buildpacks ...RemoteBuildpackRef) {
bb.order = append(bb.order, corev1alpha1.OrderEntry{Group: group})
}

func (bb *builderBlder) AddAdditionalLabels(additionalLabels map[string]string) {
bb.additionalLabels = additionalLabels
}

func (bb *builderBlder) WriteableImage() (v1.Image, error) {
buildpacks := bb.buildpacks()

Expand Down Expand Up @@ -151,6 +156,11 @@ func (bb *builderBlder) WriteableImage() (v1.Image, error) {
return nil, err
}

image, err = imagehelpers.SetStringLabels(image, bb.additionalLabels)
if err != nil {
return nil, err
}

return imagehelpers.SetLabels(image, map[string]interface{}{
buildpackOrderLabel: bb.order,
buildpackLayersLabel: buildpackLayerMetadata,
Expand Down
2 changes: 2 additions & 0 deletions pkg/cnb/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (r *RemoteBuilderCreator) CreateBuilder(ctx context.Context, builderKeychai
builderBldr.AddGroup(buildpacks...)
}

builderBldr.AddAdditionalLabels(spec.AdditionalLabels)

writeableImage, err := builderBldr.WriteableImage()
if err != nil {
return buildapi.BuilderRecord{}, err
Expand Down
11 changes: 11 additions & 0 deletions pkg/cnb/create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func testCreateBuilderOs(os string, t *testing.T, when spec.G, it spec.S) {
},
},
},
AdditionalLabels: map[string]string{
"os": "special",
"importance": "high",
},
}

lifecycleProvider = &fakeLifecycleProvider{}
Expand Down Expand Up @@ -633,6 +637,13 @@ func testCreateBuilderOs(os string, t *testing.T, when spec.G, it spec.S) {
}
}`, buildpackLayers)

// Assure the loose coupling of the number of labels that should be there
assert.Equal(t, len(clusterBuilderSpec.AdditionalLabels), 2)
for key, value := range clusterBuilderSpec.AdditionalLabels {
additionalLabel, err := imagehelpers.GetStringLabel(savedImage, key)
assert.NoError(t, err)
assert.Equal(t, value, additionalLabel)
}
})

it("creates images deterministically ", func() {
Expand Down
49 changes: 46 additions & 3 deletions pkg/openapi/openapi_generated.go

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

0 comments on commit 9287da0

Please sign in to comment.