Skip to content

Commit

Permalink
Validate labels before creating flyte CRD (#5671)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Aug 20, 2024
1 parent 5042404 commit ff12f36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/execution_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func ValidateExecutionRequest(ctx context.Context, request admin.ExecutionCreate
return err
}
}
if err := validateLabels(request.Spec.Labels); err != nil {
return err
}
return nil
}

Expand Down
19 changes: 19 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/execution_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ func TestValidateExecInvalidProjectAndDomain(t *testing.T) {
assert.EqualError(t, err, "failed to validate that project [project] and domain [domain] are registered, err: [foo]")
}

func TestValidateExecInvalidLabels(t *testing.T) {
request := testutils.GetExecutionRequest()
request.Spec.Labels = &admin.Labels{
Values: map[string]string{
"foo": "#bar",
},
}
err := ValidateExecutionRequest(context.Background(), request, testutils.GetRepoWithDefaultProject(), execConfig)
assert.ErrorContains(t, err, "invalid label value [#bar]:")

request.Spec.Labels = &admin.Labels{
Values: map[string]string{
"#foo": "bar",
},
}
err = ValidateExecutionRequest(context.Background(), request, testutils.GetRepoWithDefaultProject(), execConfig)
assert.ErrorContains(t, err, "invalid label key [#foo]:")
}

func TestGetExecutionInputs(t *testing.T) {
executionRequest := testutils.GetExecutionRequest()
lpRequest := testutils.GetLaunchPlanRequest()
Expand Down

0 comments on commit ff12f36

Please sign in to comment.