Skip to content

Commit 238ca1d

Browse files
committed
change prefix to metadata.github.com
1 parent b7b5fef commit 238ca1d

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ Runtime risks and custom tags can be added to deployment records using annotatio
9090

9191
Runtime risks are risks associated with the deployment of an artifact. These risks can be used to filter GitHub Advanced Security (GHAS) alerts and add context to alert prioritization.
9292

93-
Add the annotation `artifact-metadata.github.com/runtime-risks`, with a comma-separated list of supported runtime risk values. Annotations are aggregated from the pod and its owner reference objects.
93+
Add the annotation `metadata.github.com/runtime-risks`, with a comma-separated list of supported runtime risk values. Annotations are aggregated from the pod and its owner reference objects.
9494

9595
Currently supported runtime risks can be found in the [Create Deployment Record API docs](https://docs.github.com/en/rest/orgs/artifact-metadata?apiVersion=2022-11-28#create-an-artifact-deployment-record). Invalid runtime risk values will be ignored.
9696

9797
### Custom Tags
9898
You can add custom tags to your deployment records to help filter and organize them in GitHub.
9999

100-
Add annotations with the prefix `artifact-metadata.github.com/<key>` (e.g. `artifact-metadata.github.com/team: payments`) to add a custom tag. Annotations are aggregated from the pod and its owner reference objects.
100+
Add annotations with the prefix `metadata.github.com/<key>` (e.g. `metadata.github.com/team: payments`) to add a custom tag. Annotations are aggregated from the pod and its owner reference objects.
101101

102102
If a key is seen at multiple levels of the ownership hierarchy, the value from the lowest level (closest to the pod) will take precedence. For example, if a tag key is present on both the pod and its owning deployment, the value from the pod will be used.
103103

internal/controller/controller.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"log/slog"
8-
"regexp"
98
"slices"
109
"strings"
1110
"time"
@@ -36,17 +35,15 @@ const (
3635
// EventDeleted indicates that a pod has been deleted.
3736
EventDeleted = "DELETED"
3837
// RuntimeRiskAnnotationKey represents the annotation key for runtime risks.
39-
RuntimeRiskAnnotationKey = "artifact-metadata.github.com/runtime-risks"
40-
// CustomTagAnnotationKeyPattern is a regex to find custom tag annotations and extract the key.
41-
CustomTagAnnotationKeyPattern = `artifact-metadata\.github\.com/([^\s]+)`
38+
RuntimeRiskAnnotationKey = "metadata.github.com/runtime-risks"
39+
// CustomTagAnnotationKeyPrefix is the annotation key prefix for custom tags.
40+
CustomTagAnnotationKeyPrefix = "metadata.github.com/"
4241
// MaxCustomTags is the maximum number of custom tags per deployment record.
4342
MaxCustomTags = 5
4443
// MaxCustomTagLength is the maximum length for a custom tag key or value.
4544
MaxCustomTagLength = 100
4645
)
4746

48-
var customTagAnnotationKeyRegexp = regexp.MustCompile(CustomTagAnnotationKeyPattern)
49-
5047
type ttlCache interface {
5148
Get(k any) (any, bool)
5249
Set(k any, v any, ttl time.Duration)
@@ -760,8 +757,8 @@ func extractMetadataFromObject(obj *metav1.PartialObjectMetadata, aggPodMetadata
760757
if RuntimeRiskAnnotationKey == key {
761758
continue
762759
}
763-
if matches := customTagAnnotationKeyRegexp.FindStringSubmatch(key); matches != nil {
764-
tagKey := matches[1]
760+
if strings.HasPrefix(key, CustomTagAnnotationKeyPrefix) {
761+
tagKey := strings.TrimPrefix(key, CustomTagAnnotationKeyPrefix)
765762
tagValue := annotations[key]
766763
if utf8.RuneCountInString(tagKey) > MaxCustomTagLength || utf8.RuneCountInString(tagValue) > MaxCustomTagLength {
767764
slog.Warn("Tag key or value exceeds max length, skipping",

0 commit comments

Comments
 (0)