Skip to content

Add revision label to function images and show in describe#3629

Merged
knative-prow[bot] merged 7 commits intoknative:mainfrom
creydr:add-label-with-commit-to-func-image
Apr 27, 2026
Merged

Add revision label to function images and show in describe#3629
knative-prow[bot] merged 7 commits intoknative:mainfrom
creydr:add-label-with-commit-to-func-image

Conversation

@creydr
Copy link
Copy Markdown
Member

@creydr creydr commented Apr 22, 2026

Changes

  • 🎁 Add a org.opencontainers.image.revision image label containing the short git commit SHA of the function source directory at build time, with a -dirty suffix when the working tree has uncommitted changes
  • 🎁 Show the revision label in func describe output (JSON/YAML)
$ func describe my-func -o yaml
...
revision: 0cf9be2-dirty

/kind enhancement

Release Note

Function images now include a `commit` label with the short git commit SHA of the function source at build time. The commit is also shown in `func describe` JSON/YAML output.

creydr added 2 commits April 22, 2026 15:00
Detect the git commit SHA of the function source directory
using go-git and add it as a "commit" OCI image label.
The short SHA is suffixed with "-dirty" if the working tree
has uncommitted changes. If the function is not in a git
repo, the label is omitted.

Integrated into all three builders (pack, s2i, oci) and
the func-util scaffold/s2i-generate pipeline.
Add ImageCommit() to read the commit label from a deployed
function image. Integrate into all three describers (knative,
k8s, keda) and expose via the Instance struct so it appears
in JSON/YAML output of func describe.
@knative-prow knative-prow Bot added the kind/enhancement Feature additions or improvements to existing label Apr 22, 2026
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos April 22, 2026 13:48
@knative-prow knative-prow Bot added the size/L 🤖 PR changes 100-499 lines, ignoring generated files. label Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 64.78873% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.40%. Comparing base (7247657) to head (7afd4f2).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/functions/git_commit.go 48.00% 9 Missing and 4 partials ⚠️
pkg/functions/function_labels.go 33.33% 8 Missing and 4 partials ⚠️
pkg/oci/builder.go 21.42% 8 Missing and 3 partials ⚠️
pkg/k8s/describer.go 73.33% 3 Missing and 1 partial ⚠️
pkg/keda/describer.go 73.33% 3 Missing and 1 partial ⚠️
pkg/buildpacks/builder.go 76.92% 2 Missing and 1 partial ⚠️
pkg/s2i/builder.go 70.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3629      +/-   ##
==========================================
+ Coverage   56.33%   56.40%   +0.06%     
==========================================
  Files         180      181       +1     
  Lines       20571    20669      +98     
==========================================
+ Hits        11589    11658      +69     
- Misses       7780     7797      +17     
- Partials     1202     1214      +12     
Flag Coverage Δ
e2e 36.27% <56.33%> (+0.06%) ⬆️
e2e go 32.99% <56.41%> (+0.13%) ⬆️
e2e node 28.76% <53.84%> (+0.14%) ⬆️
e2e python 33.36% <56.41%> (+0.13%) ⬆️
e2e quarkus 28.90% <53.84%> (+0.13%) ⬆️
e2e rust 28.30% <48.71%> (+0.11%) ⬆️
e2e springboot 26.76% <51.28%> (+0.11%) ⬆️
e2e typescript 28.86% <53.84%> (+0.13%) ⬆️
e2e-config-ci 18.12% <29.91%> (+0.06%) ⬆️
integration 17.44% <20.51%> (-0.15%) ⬇️
unit macos-14 43.47% <27.35%> (+0.16%) ⬆️
unit macos-latest 43.47% <27.35%> (+0.16%) ⬆️
unit ubuntu-24.04-arm 43.67% <27.46%> (+0.16%) ⬆️
unit ubuntu-latest 44.34% <27.35%> (+0.15%) ⬆️
unit windows-latest 43.50% <27.35%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@creydr
Copy link
Copy Markdown
Member Author

creydr commented Apr 22, 2026

/cc @lkingland @gauron99

@knative-prow knative-prow Bot requested review from gauron99 and lkingland April 22, 2026 18:48
Comment thread pkg/functions/function_labels.go Outdated

const (
MiddlewareVersionLabelKey = "middleware-version"
CommitLabelKey = "commit"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would name this revision to be more VCS agnostic. Or even org.opencontainers.image.revision.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Let me update it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the label key to org.opencontainers.image.revision and the key for the "func describe" output to revision

TlsVerify string

// Git commit SHA of the function source
Commit string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why we need to parameterize? Cannot the task read current commit on its own?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we upload source as is including .git so the task could read it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had it initially in the task itself, but I wasn't able to get the commit hash there. This would also have involved to write it to a file and then read it during the prepare step. So I thought it'd be cleaner to have it simply as a parameter for the task.

Comment thread pkg/functions/image_commit.go Outdated
Copy link
Copy Markdown
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold for the good suggestions from others

Comment thread pkg/functions/image_inspector.go Outdated
"github.com/google/go-containerregistry/pkg/v1/remote"
)

type ImageInspector struct {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could use a comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the struct as part of the refactoring

Comment thread pkg/functions/image_inspector.go Outdated
transport http.RoundTripper
}

func NewImageInspector(transport http.RoundTripper) *ImageInspector {
Copy link
Copy Markdown
Member

@lkingland lkingland Apr 27, 2026

Choose a reason for hiding this comment

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

This is just a nit, but I'm not seeing any reason this needs to be a pointer, and nils as args begs the question.

Is that just to enable the nil in method signatures, like NewDeployer(x, nil)? This could be accomplished with an fn.ImageInspector interface (which is perhaps a good idea for other reasons too). The simplest option to get rid of the ponters/nils would then be to have a singleton fn.DefaultImageInspector which is a noop and can be passed in place of the nil.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The struct got removed during the refactoring. I am using the http.transport directly now (passed via our Options pattern)

@knative-prow knative-prow Bot added the do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. label Apr 27, 2026
@knative-prow knative-prow Bot added lgtm 🤖 PR is ready to be merged. approved 🤖 PR has been approved by an approver from all required OWNERS files. labels Apr 27, 2026
Comment thread cmd/client.go Outdated
c = newCredentialsProvider(config.Dir(), t, "") // for accessing registries
d = newKnativeDeployer(cfg.Verbose) // default deployer (can be overridden via options)
pp = newTektonPipelinesProvider(c, cfg.Verbose)
ii = fn.NewImageInspector(t)
Copy link
Copy Markdown
Member

@lkingland lkingland Apr 27, 2026

Choose a reason for hiding this comment

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

Is the transport the reason for having the ImageInspector exposed outside the core into the cli (or anyone using the core api)? If so, it might be possible to just pass the transport to the describers/pipeline provider. Then they can use that internally to inspect using a helper method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I updated it. I am passing the http.Transport now to the describers only (via a WithDescriberTransport(t) option func). I hope this makes sense :)

Replace ImageInspector struct with ImageLabels helper in function_labels.go.
Describers now accept transport via WithDescriberTransport option,
keeping the transport internal and removing nil arguments from callers.
@creydr creydr changed the title Add commit label to function images and show in describe [WIP] Add commit label to function images and show in describe Apr 27, 2026
@knative-prow knative-prow Bot added do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. and removed lgtm 🤖 PR is ready to be merged. labels Apr 27, 2026
@creydr creydr changed the title [WIP] Add commit label to function images and show in describe Add revision label to function images and show in describe Apr 27, 2026
@knative-prow knative-prow Bot removed the do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. label Apr 27, 2026
@creydr creydr requested a review from matejvasek April 27, 2026 08:56
@creydr creydr requested a review from lkingland April 27, 2026 08:56
@matejvasek
Copy link
Copy Markdown
Contributor

/approve
/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Apr 27, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Apr 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: creydr, lkingland, matejvasek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [lkingland,matejvasek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@creydr
Copy link
Copy Markdown
Member Author

creydr commented Apr 27, 2026

/unhold

@knative-prow knative-prow Bot removed the do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. label Apr 27, 2026
@knative-prow knative-prow Bot merged commit 77707d1 into knative:main Apr 27, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. kind/enhancement Feature additions or improvements to existing lgtm 🤖 PR is ready to be merged. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants