Skip to content

Commit

Permalink
Re-add implicit service prefix if one was not added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sixolet committed Aug 10, 2019
1 parent 2202af4 commit 27b2c65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/serving/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ func GenerateRevisionName(nameTempl string, service *servingv1alpha1.Service) (s
}
buf := new(bytes.Buffer)
err = templ.Execute(buf, context)
return buf.String(), err
if err != nil {
return "", err
}
res := buf.String()
// Empty is ok.
if res == "" {
return res, nil
}
prefix := service.Name + "-"
if !strings.HasPrefix(res, prefix) {
res = prefix + res
}
return res, nil
}

func getConfiguration(service *servingv1alpha1.Service) (*servingv1alpha1.ConfigurationSpec, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/serving/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestGenerateName(t *testing.T) {
{"foo-asdf", "foo-asdf", ""},
{"{{.Bad}}", "", "can't evaluate field Bad"},
{"{{.Service}}-{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
{"", "", ""},
{"andrew", "foo-andrew", ""},
{"{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
}
for _, c := range cases {
rand.Seed(1)
Expand Down

0 comments on commit 27b2c65

Please sign in to comment.