Skip to content

Commit 7af3336

Browse files
feat: add metadata.annotations to package schema (#3319)
Signed-off-by: Austin Abro <[email protected]>
1 parent 53f26a6 commit 7af3336

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

src/api/v1alpha1/package.go

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ type ZarfMetadata struct {
170170
Vendor string `json:"vendor,omitempty"`
171171
// Checksum of a checksums.txt file that contains checksums all the layers within the package.
172172
AggregateChecksum string `json:"aggregateChecksum,omitempty"`
173+
// Annotations contains arbitrary metadata about the package.
174+
// Users are encouraged to follow OCI image-spec https://github.com/opencontainers/image-spec/blob/main/annotations.md
175+
Annotations map[string]string `json:"annotations,omitempty"`
173176
}
174177

175178
// ZarfBuildData is written during the packager.Create() operation to track details of the created package.

src/internal/packager2/layout/oci.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"log/slog"
11+
"maps"
1112
"strings"
1213

1314
"github.com/defenseunicorns/pkg/helpers/v2"
@@ -144,5 +145,7 @@ func annotationsFromMetadata(metadata v1alpha1.ZarfMetadata) map[string]string {
144145
if vendor := metadata.Vendor; vendor != "" {
145146
annotations[ocispec.AnnotationVendor] = vendor
146147
}
148+
// annotations explicitly defined in `metadata.annotations` take precedence over legacy fields
149+
maps.Copy(annotations, metadata.Annotations)
147150
return annotations
148151
}

src/internal/packager2/layout/oci_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ func TestAnnotationsFromMetadata(t *testing.T) {
2121
Documentation: "documentation",
2222
Source: "source",
2323
Vendor: "vendor",
24+
Annotations: map[string]string{
25+
"org.opencontainers.image.title": "overridden",
26+
"org.opencontainers.image.new": "new-field",
27+
},
2428
}
2529
annotations := annotationsFromMetadata(metadata)
2630
expectedAnnotations := map[string]string{
27-
"org.opencontainers.image.title": "foo",
31+
"org.opencontainers.image.title": "overridden",
2832
"org.opencontainers.image.description": "bar",
2933
"org.opencontainers.image.url": "https://example.com",
3034
"org.opencontainers.image.authors": "Zarf",
3135
"org.opencontainers.image.documentation": "documentation",
3236
"org.opencontainers.image.source": "source",
3337
"org.opencontainers.image.vendor": "vendor",
38+
"org.opencontainers.image.new": "new-field",
3439
}
3540
require.Equal(t, expectedAnnotations, annotations)
3641
}

src/pkg/zoci/push.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"errors"
1010
"fmt"
11+
"maps"
1112

1213
"github.com/defenseunicorns/pkg/helpers/v2"
1314
"github.com/defenseunicorns/pkg/oci"
@@ -116,6 +117,7 @@ func annotationsFromMetadata(metadata *v1alpha1.ZarfMetadata) map[string]string
116117
if vendor := metadata.Vendor; vendor != "" {
117118
annotations[ocispec.AnnotationVendor] = vendor
118119
}
119-
120+
// annotations explicitly defined in `metadata.annotations` take precedence over legacy fields
121+
maps.Copy(annotations, metadata.Annotations)
120122
return annotations
121123
}

zarf.schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,13 @@
10761076
"aggregateChecksum": {
10771077
"type": "string",
10781078
"description": "Checksum of a checksums.txt file that contains checksums all the layers within the package."
1079+
},
1080+
"annotations": {
1081+
"additionalProperties": {
1082+
"type": "string"
1083+
},
1084+
"type": "object",
1085+
"description": "Annotations contains arbitrary metadata about the package.\nUsers are encouraged to follow OCI image-spec https://github.com/opencontainers/image-spec/blob/main/annotations.md"
10791086
}
10801087
},
10811088
"additionalProperties": false,

0 commit comments

Comments
 (0)