Bug 1247680 - service name silently truncated to 24 characters
service name silently truncated to 24 characters
Status: CLOSED CURRENTRELEASE
Product: OpenShift Origin
Classification: Red Hat
Component: Command Line Interface (Show other bugs)
3.x
Unspecified Unspecified
medium Severity medium
: ---
: ---
Assigned To: Fabiano Franz
Yan Du
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-07-28 11:28 EDT by Aleksandar Kostadinov
Modified: 2015-09-08 16:13 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-09-08 16:13:53 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Aleksandar Kostadinov 2015-07-28 11:28:46 EDT
Description of problem:
> $ oc new-app --docker-image=openshift/ruby-20-centos7~https://github.com/openshift/ruby-hello-world --name='lcle4tabxqshsonow8yhrv6mc'
> imagestreams/ruby-20-centos7
> imagestreams/lcle4tabxqshsonow8yhrv6mc
> buildconfigs/lcle4tabxqshsonow8yhrv6mc
> deploymentconfigs/lcle4tabxqshsonow8yhrv6mc
> services/lcle4tabxqshsonow8yhrv6m
> A build was created - you can run `oc start-build lcle4tabxqshsonow8yhrv6mc` to start it.
> Service "lcle4tabxqshsonow8yhrv6m" created at 172.30.5.134 with port mappings 8080.

As you can see, user requested a 25 char long name but a service with only 24 chars name was created. As a user I'd like to know upfront if something would go wrong to consider how do I continue instead of expecting that everything is ok and suddenly am confused that some things do not appear as expected or the name I use to access them is not what expect.

Especially bad for scripting in my opinion.
Comment 1 Abhishek Gupta 2015-08-04 17:13:49 EDT
Derek: Is there a 24 char limit on the service name? On account of DNS name length restrictions?
Comment 2 Derek Carr 2015-08-06 11:36:45 EDT
The 24 char limit on the service name is to make service names conform to https://tools.ietf.org/html/rfc952
Comment 3 Abhishek Gupta 2015-08-06 12:44:06 EDT
Shouldn't we add explicit validations and block service names longer than 24 characters from being created, instead of silently truncating them?
Comment 4 Jordan Liggitt 2015-08-16 17:22:28 EDT
The API does that validation. Is the CLI truncating?
Comment 5 Jordan Liggitt 2015-08-17 00:03:23 EDT
Submitting a name longer than 24 characters to the API results in a validation error:

$ echo '{"kind":"Service","apiVersion":"v1","metadata": {"name":"aaaaabbbbbcccccdddddeeeee"}}' | oc create -f -

The Service "aaaaabbbbbcccccdddddeeeee" is invalid.

* metadata.name: invalid value 'aaaaabbbbbcccccdddddeeeee', Details: must be a DNS 952 label (at most 24 characters, matching regex [a-z]([-a-z0-9]*[a-z0-9])?): e.g. "my-name"
* spec.ports: required value

Moving back to CLI, since that's where the truncation happens (app/pipeline.go):

func makeValidServiceName(name string) (string, string) {
	if ok, _ := validation.ValidateServiceName(name, false); ok {
		return name, ""
	}
	name = strings.ToLower(name)
	name = invalidServiceChars.ReplaceAllString(name, "")
	name = strings.TrimFunc(name, func(r rune) bool { return r == '-' })
	switch {
	case len(name) == 0:
		return "", "service-"
	case len(name) > maxServiceNameLength:
		name = name[:maxServiceNameLength]
	}
	return name, ""
}
Comment 6 Fabiano Franz 2015-08-17 16:35:59 EDT
Fixed in https://github.com/openshift/origin/pull/4220
Comment 7 openshift-github-bot 2015-08-17 19:56:11 EDT
Commit pushed to master at https://github.com/openshift/origin

https://github.com/openshift/origin/commit/f94c655af0ed321582ab81bb3ec39a002b159816
Bug 1247680 - must not truncate svc names in the cli, rely on API validation
Comment 8 Yan Du 2015-08-18 03:01:40 EDT
Test on latest origin env

oc v1.0.4-330-gcca4a42
kubernetes v1.1.0-alpha.0-1605-g44c91b1

# oc new-app --docker-image=openshift/ruby-20-centos7~https://github.com/openshift/ruby-hello-world --name='lcle4tabxqshsonow8yhrv6mc'
imagestreams/ruby-20-centos7
imagestreams/lcle4tabxqshsonow8yhrv6mc
buildconfigs/lcle4tabxqshsonow8yhrv6mc
deploymentconfigs/lcle4tabxqshsonow8yhrv6mc
Error: Service "lcle4tabxqshsonow8yhrv6mc" is invalid: metadata.name: invalid value 'lcle4tabxqshsonow8yhrv6mc', Details: must be a DNS 952 label (at most 24 characters, matching regex [a-z]([-a-z0-9]*[a-z0-9])?): e.g. "my-name"

Move bug to verified.
Comment 9 openshift-github-bot 2015-08-19 17:00:38 EDT
Commits pushed to master at https://github.com/openshift/origin

https://github.com/openshift/origin/commit/8a257c1d2537266ddef2bbcf55d51b51bcea1c38
Revert "Bug 1247680 - must not truncate svc names in the cli, rely on API validation"

This reverts commit f94c655af0ed321582ab81bb3ec39a002b159816.

https://github.com/openshift/origin/commit/680ec91a39d0d7e9e5a759e3f334b445e3ce0e1d
Bug 1247680 and 1251601 - new-app must validate --name instead of silently truncating and changing case
Comment 10 Fabiano Franz 2015-08-19 17:05:34 EDT
Please test again with https://github.com/openshift/origin/pull/4251
Comment 11 Yan Du 2015-08-20 02:18:20 EDT
Test on fedora_2176, issue have been fixed, move to verified.

oc v1.0.4-392-g9fa9246
kubernetes v1.1.0-alpha.0-1605-g44c91b1


# oc new-app --docker-image=openshift/ruby-20-centos7~https://github.com/openshift/ruby-hello-world --name='lcle4tabxqshsonow8yhrv6mc'
error: invalid name: lcle4tabxqshsonow8yhrv6mc. Must be an a lower case alphanumeric (a-z, and 0-9) string with a maximum length of 24 characters, where the first character is a letter (a-z), and the '-' character is allowed anywhere except the first or last character.

Note You need to log in before you can comment on or make changes to this bug.