You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`validateMetadataLabels` ensures that labels are in a certain format.
This works fine in most cases, except when this is used within appsets,
which allow for labels to be templated. This adds a layer of
indirection allowing for templated labels to be used, but only when an
appset makes use of this feature.
Signed-off-by: Blake Pettersson <[email protected]>
Description: "Upon application creation or update, wait for application health/sync status to be healthy/Synced, upon application deletion, wait for application to be removed, when set to true. Wait timeouts are controlled by Terraform Create, Update and Delete resource timeouts (all default to 5 minutes). **Note**: if ArgoCD decides not to sync an application (e.g. because the project to which the application belongs has a `sync_window` applied) then you will experience an expected timeout event if `wait = true`.",
Description: "Map of string keys and values that can be used to organize and categorize (scope and select) the cluster secret. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels",
Description: fmt.Sprintf("Map of string keys and values that can be used to organize and categorize (scope and select) the %s. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels", objectName),
Copy file name to clipboardExpand all lines: argocd/validators_test.go
+118Lines changed: 118 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,126 @@ import (
4
4
"fmt"
5
5
"reflect"
6
6
"testing"
7
+
8
+
"github.com/stretchr/testify/require"
7
9
)
8
10
11
+
funcTest_validateMetadataLabels(t*testing.T) {
12
+
t.Parallel()
13
+
14
+
tests:= []struct {
15
+
namestring
16
+
isAppSetbool
17
+
valueinterface{}
18
+
keystring
19
+
wantWs []string
20
+
wantEs []error
21
+
}{
22
+
{
23
+
name: "Valid labels",
24
+
isAppSet: false,
25
+
value: map[string]interface{}{
26
+
"valid-key": "valid-value",
27
+
},
28
+
key: "metadata_labels",
29
+
wantWs: nil,
30
+
wantEs: nil,
31
+
},
32
+
{
33
+
name: "Invalid label key",
34
+
isAppSet: false,
35
+
value: map[string]interface{}{
36
+
"Invalid Key!": "valid-value",
37
+
},
38
+
key: "metadata_labels",
39
+
wantWs: nil,
40
+
wantEs: []error{
41
+
fmt.Errorf("metadata_labels (\"Invalid Key!\") name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')"),
42
+
},
43
+
},
44
+
{
45
+
name: "Invalid label value",
46
+
isAppSet: false,
47
+
value: map[string]interface{}{
48
+
"valid-key": "Invalid Value!",
49
+
},
50
+
key: "metadata_labels",
51
+
wantWs: nil,
52
+
wantEs: []error{
53
+
fmt.Errorf("metadata_labels (\"Invalid Value!\") a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')"),
54
+
},
55
+
},
56
+
{
57
+
name: "Non-string label value",
58
+
isAppSet: false,
59
+
value: map[string]interface{}{
60
+
"valid-key": 123,
61
+
},
62
+
key: "metadata_labels",
63
+
wantWs: nil,
64
+
wantEs: []error{
65
+
fmt.Errorf("metadata_labels.valid-key (123): Expected value to be string"),
66
+
},
67
+
},
68
+
{
69
+
name: "Valid templated value for AppSet",
70
+
isAppSet: true,
71
+
value: map[string]interface{}{
72
+
"valid-key": "{{ valid-template }}",
73
+
},
74
+
key: "metadata_labels",
75
+
wantWs: nil,
76
+
wantEs: nil,
77
+
},
78
+
{
79
+
name: "Invalid templated value for non-AppSet",
80
+
isAppSet: false,
81
+
value: map[string]interface{}{
82
+
"valid-key": "{{ invalid-template }}",
83
+
},
84
+
key: "metadata_labels",
85
+
wantWs: nil,
86
+
wantEs: []error{
87
+
fmt.Errorf("metadata_labels (\"{{ invalid-template }}\") a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')"),
88
+
},
89
+
},
90
+
{
91
+
name: "Empty label key",
92
+
isAppSet: false,
93
+
value: map[string]interface{}{
94
+
"": "valid-value",
95
+
},
96
+
key: "metadata_labels",
97
+
wantWs: nil,
98
+
wantEs: []error{
99
+
fmt.Errorf("metadata_labels (\"\") name part must be non-empty"),
100
+
fmt.Errorf("metadata_labels (\"\") name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')"),
0 commit comments