Skip to content

Commit 0dc196b

Browse files
authored
fix: Correct validation rules for v1 labels and annotations (#10)
Our README.md states that: ![image](https://github.com/user-attachments/assets/66efc286-7837-4ff3-8c86-770a017869a1) while our current rules do not allow uppercase letters.
1 parent fd98de1 commit 0dc196b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/openslo/v1/objects.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ func validationRulesMetadata[T any](getter func(T) Metadata) govy.PropertyRules[
122122
}
123123

124124
var (
125-
labelKeyRegexp = regexp.MustCompile(`^[a-z0-9]([-._a-z0-9]{0,61}[a-z0-9])?$`)
125+
labelKeyRegexp = regexp.MustCompile(`^[a-zA-Z0-9]([-._a-zA-Z0-9]{0,61}[a-zA-Z0-9])?$`)
126126
annotationKeyLengthRegexp = regexp.MustCompile(`^(.{0,253}/)?.{0,63}$`)
127127
// nolint: lll
128128
annotationKeyRegexp = regexp.MustCompile(
129-
`^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*/)?[a-z0-9]([-._a-z0-9]{0,61}[a-z0-9])?$`,
129+
`^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*/)?[a-zA-Z0-9]([-._a-zA-Z0-9]{0,61}[a-zA-Z0-9])?$`,
130130
)
131131
)
132132

pkg/openslo/v1/objects_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func getLabelsTestCases(t *testing.T, propertyPath string) map[string]labelsTest
8787
{"net_.-this": {}},
8888
{"9net": {}},
8989
{"net9": {}},
90+
{"nEt": {}},
9091
}
9192
invalidLabels := []Labels{
9293
{strings.Repeat("l", 64): {}},
@@ -96,7 +97,6 @@ func getLabelsTestCases(t *testing.T, propertyPath string) map[string]labelsTest
9697
{"_net": {}},
9798
{"-net": {}},
9899
{".net": {}},
99-
{"nEt": {}},
100100
}
101101
testCases := make(map[string]labelsTestCase, len(validLabels)+len(invalidLabels))
102102
for _, labels := range validLabels {
@@ -144,10 +144,13 @@ func getAnnotationsTestCases(t *testing.T, propertyPath string) map[string]annot
144144
{"net": ""},
145145
{"9net": ""},
146146
{"net9": ""},
147+
{"nEt": ""},
147148
{"openslo.com/service": ""},
148149
{"domain/service": ""},
149150
{"domain.org/service": ""},
150151
{"domain.this.org/service": ""},
152+
{"domain.this.org/service.foo": ""},
153+
{"my-org.com/spec.indicator.metricSource": ""},
151154
}
152155
invalidAnnotations := []Annotations{
153156
{strings.Repeat("l", 64): ""},
@@ -160,7 +163,6 @@ func getAnnotationsTestCases(t *testing.T, propertyPath string) map[string]annot
160163
{"_net": ""},
161164
{"-net": ""},
162165
{".net": ""},
163-
{"nEt": ""},
164166
{"openslo.com/": ""},
165167
{"openslo.com!/service": ""},
166168
{"-openslo.com/service": ""},

0 commit comments

Comments
 (0)