Skip to content

Commit

Permalink
web: sort custom annotations keys for deterministic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Dec 14, 2022
1 parent b224357 commit 9b1bc05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/pkg/rpaas/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3153,7 +3153,7 @@ func Test_k8sRpaasManager_CreateInstance(t *testing.T) {
name: "with custom annotations and forbidden prefixes",
args: CreateArgs{Name: "r1", Team: "t1", Parameters: map[string]interface{}{"annotations": "{\"my-custom-annotation\": \"my-value\", \"rpaas.extensions.tsuru.io/tags\": \"tag1,tag2\", \"rpaas.extensions.tsuru.io/description\": \"my description\"}"}},
extraConfig: config.RpaasConfig{ForbiddenAnnotationsPrefixes: []string{"rpaas.extensions.tsuru.io"}},
expectedError: `annotation "rpaas.extensions.tsuru.io/tags" is not allowed`,
expectedError: `annotation "rpaas.extensions.tsuru.io/description" is not allowed`,
},
}
for _, tt := range tests {
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/rpaas/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ func getAnnotations(params map[string]interface{}) (map[string]string, error) {
return nil, err
}
forbiddenAnnotationsPrefixes := config.Get().ForbiddenAnnotationsPrefixes
var sortedAnnotationsKeys []string
for k := range annotations {
sortedAnnotationsKeys = append(sortedAnnotationsKeys, k)
}
sort.Strings(sortedAnnotationsKeys)
for _, k := range sortedAnnotationsKeys {
// check if annotation complies with allowed k8s annotations
annotationParts := strings.Split(k, "/")
if len(annotationParts) > 1 {
Expand Down

0 comments on commit 9b1bc05

Please sign in to comment.