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 in the initial configuration to add the image labels #1448

Merged
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
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 @@ -6115,6 +6122,13 @@
"kpack.build.v1alpha2.ClusterBuilderSpec": {
"type": "object",
"properties": {
"additionalLabels": {
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6804,6 +6818,13 @@
"kpack.build.v1alpha2.NamespacedBuilderSpec": {
"type": "object",
"properties": {
"additionalLabels": {
"type": "object",
"additionalProperties": {
"type": "string",
"default": ""
}
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -7181,8 +7202,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 @@ -7440,7 +7460,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 @@ -36,7 +36,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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you regenerate the CRDs as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a new commit.

Please let me know if you think it's not the right place

}

// +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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an error check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

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 @@ -65,6 +65,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 @@ -639,6 +643,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.