|
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | 7 | "log/slog" |
8 | | - "regexp" |
9 | 8 | "slices" |
10 | 9 | "strings" |
11 | 10 | "time" |
@@ -36,17 +35,15 @@ const ( |
36 | 35 | // EventDeleted indicates that a pod has been deleted. |
37 | 36 | EventDeleted = "DELETED" |
38 | 37 | // 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/" |
42 | 41 | // MaxCustomTags is the maximum number of custom tags per deployment record. |
43 | 42 | MaxCustomTags = 5 |
44 | 43 | // MaxCustomTagLength is the maximum length for a custom tag key or value. |
45 | 44 | MaxCustomTagLength = 100 |
46 | 45 | ) |
47 | 46 |
|
48 | | -var customTagAnnotationKeyRegexp = regexp.MustCompile(CustomTagAnnotationKeyPattern) |
49 | | - |
50 | 47 | type ttlCache interface { |
51 | 48 | Get(k any) (any, bool) |
52 | 49 | Set(k any, v any, ttl time.Duration) |
@@ -760,8 +757,8 @@ func extractMetadataFromObject(obj *metav1.PartialObjectMetadata, aggPodMetadata |
760 | 757 | if RuntimeRiskAnnotationKey == key { |
761 | 758 | continue |
762 | 759 | } |
763 | | - if matches := customTagAnnotationKeyRegexp.FindStringSubmatch(key); matches != nil { |
764 | | - tagKey := matches[1] |
| 760 | + if strings.HasPrefix(key, CustomTagAnnotationKeyPrefix) { |
| 761 | + tagKey := strings.TrimPrefix(key, CustomTagAnnotationKeyPrefix) |
765 | 762 | tagValue := annotations[key] |
766 | 763 | if utf8.RuneCountInString(tagKey) > MaxCustomTagLength || utf8.RuneCountInString(tagValue) > MaxCustomTagLength { |
767 | 764 | slog.Warn("Tag key or value exceeds max length, skipping", |
|
0 commit comments