Skip to content

Commit ba9d38e

Browse files
fix: label key can be saved without value if saved without propagation (#3190)
* fix: length of key increased in global tag * fix: not validating label value required tag as tags can be supplied without value if saved without propagation * sql file renamed
1 parent c8d3c61 commit ba9d38e

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

api/appbean/AppDetail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type AppMetadata struct {
3333

3434
type AppLabel struct {
3535
Key string `json:"key,notnull" validate:"required"`
36-
Value string `json:"value,notnull" validate:"required"`
36+
Value string `json:"value,notnull"` // intentionally not added required tag as tag can be added without value
3737
Propagate bool `json:"propagate"`
3838
}
3939

pkg/bean/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ type AppLabelDto struct {
649649

650650
type Label struct {
651651
Key string `json:"key" validate:"required"`
652-
Value string `json:"value" validate:"required"`
652+
Value string `json:"value"` // intentionally not added required tag as tag can be added without value
653653
Propagate bool `json:"propagate"`
654654
}
655655

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "public"."global_tag" ALTER COLUMN "key" SET DATA TYPE varchar(100);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "public"."global_tag" ALTER COLUMN "key" SET DATA TYPE varchar(317);

util/K8sUtil.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import (
44
"errors"
55
"fmt"
66
"k8s.io/apimachinery/pkg/util/validation"
7+
"strings"
78
)
89

910
func CheckIfValidLabel(labelKey string, labelValue string) error {
11+
labelKey = strings.TrimSpace(labelKey)
12+
labelValue = strings.TrimSpace(labelValue)
13+
1014
errs := validation.IsQualifiedName(labelKey)
11-
if len(errs) > 0 {
15+
if len(labelKey) == 0 || len(errs) > 0 {
1216
return errors.New(fmt.Sprintf("Validation error - label key - %s is not satisfying the label key criteria", labelKey))
1317
}
1418

1519
errs = validation.IsValidLabelValue(labelValue)
16-
if len(errs) > 0 {
20+
if len(labelValue) == 0 || len(errs) > 0 {
1721
return errors.New(fmt.Sprintf("Validation error - label value - %s is not satisfying the label value criteria for label key - %s", labelValue, labelKey))
1822
}
1923
return nil

0 commit comments

Comments
 (0)