Skip to content

Commit 82d10ac

Browse files
fix: Ignoring propagating invalid labels in app to values.yaml during deployment (#2734)
* ignoring app labels while propagating to kubernetes during deployment * comment added for treating label key as qualified name * fixed - was using labelKey instead of labelValue in logging * log change * trimming space while setting labels in app
1 parent 0164c1b commit 82d10ac

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pkg/app/AppCrudOperationService.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/devtron-labs/devtron/pkg/user/repository"
2727
"github.com/go-pg/pg"
2828
"go.uber.org/zap"
29+
"k8s.io/apimachinery/pkg/util/validation"
30+
"strings"
2931
"time"
3032
)
3133

@@ -296,7 +298,31 @@ func (impl AppCrudOperationServiceImpl) GetLabelsByAppIdForDeployment(appId int)
296298
}
297299
labelsDto := make(map[string]string)
298300
for _, label := range labels {
299-
labelsDto[label.Key] = label.Value
301+
labelKey := strings.TrimSpace(label.Key)
302+
labelValue := strings.TrimSpace(label.Value)
303+
304+
// if labelKey or labelValue is empty then don't add in labels
305+
if len(labelKey) == 0 || len(labelValue) == 0 {
306+
impl.logger.Warnw("Ignoring label to propagate to app level", "labelKey", labelKey, "labelValue", labelValue, "appId", appId)
307+
continue
308+
}
309+
310+
// if labelKey is not satisfying the label key criteria don't add in labels
311+
// label key must be a 'qualified name' (https://github.com/kubernetes/website/issues/17969)
312+
errs := validation.IsQualifiedName(labelKey)
313+
if len(errs) > 0 {
314+
impl.logger.Warnw("Ignoring label to propagate to app level", "message", fmt.Sprintf("Validation error - label key - %s is not satisfying the label key criteria", labelKey), "appId", appId)
315+
continue
316+
}
317+
318+
// if labelValue is not satisfying the label value criteria don't add in labels
319+
errs = validation.IsValidLabelValue(labelValue)
320+
if len(errs) > 0 {
321+
impl.logger.Warnw("Ignoring label to propagate to app level", "message", fmt.Sprintf("Validation error - label value - %s is not satisfying the label value criteria", labelValue), "appId", appId)
322+
continue
323+
}
324+
325+
labelsDto[labelKey] = labelValue
300326
}
301327
appLabelJson.Labels = labelsDto
302328
appLabelByte, err := json.Marshal(appLabelJson)

0 commit comments

Comments
 (0)