Bug 1383812 - Error setting ports using parameter in template. IANA_SVC_NAME error.
Summary: Error setting ports using parameter in template. IANA_SVC_NAME error.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Build
Version: 3.3.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: ---
Assignee: Ben Parees
QA Contact: Wang Haoran
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-10-11 20:19 UTC by Ryan Howe
Modified: 2019-12-16 07:04 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Feature: Support using parameter references in non-string template fields. Reason: Previously parameter references could not be used in non-string api fields such as replica count or port. This is now supported by using the ${{PARAMETER}} syntax to reference a parameter within the template. Result: Non-string api fields can now contain parameter references when writing a template.
Clone Of:
Environment:
Last Closed: 2017-01-18 12:42:28 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:0066 0 normal SHIPPED_LIVE Red Hat OpenShift Container Platform 3.4 RPM Release Advisory 2017-01-18 17:23:26 UTC

Description Ryan Howe 2016-10-11 20:19:27 UTC
Description of problem:

When creating a template and trying create a parameter for the following:

pod.spec.containers[0].readinessProbe.httpGet.port
service.spec.ports[0].targetPort 

Error is seen. 

“invalid: spec.template.spec.containers[0].readinessProbe.httpGet.port: Invalid value: "3000": must be an IANA_SVC_NAME (at most 15 characters, matching regex [a-z0-9]([a-z0-9-]*[a-z0-9])*”

error: Service "test" is invalid: spec.ports[0].targetPort: Invalid value: "800": must be an IANA_SVC_NAME (at most 15 characters, matching regex [a-z0-9]([a-z0-9-]*[a-z0-9])*, it must contain at least one letter [a-z], and hyphens cannot be adjacent to other hyphens): e.g. "http"


Version-Release number of selected component (if applicable):
OCP 3.1+
OCP 3.3

How reproducible:
100%

Steps to Reproduce:
1. Create template 

$ cat bug1.yaml 

  kind: "Template"
  apiVersion: "v1"
  metadata:
    name: "bug1"
    creationTimestamp: null
    annotations:
      description: "Template for container creation"
      iconClass: "icon-generic"
      tags: "generic"
  objects:
    -
      kind: "Service"
      apiVersion: "v1"
      metadata:
        name: "${NODE_TEMPLATE_NAME}"
      spec:
        ports:
          - name: "web"
            protocol: '${PROTOCOL}'
            port: '${EXT_PORT}'
            targetPort: '${CONTAINER_PORT}'
        selector:
          name: "${NODE_TEMPLATE_NAME}"
        type: "ClusterIP"
        sessionAffinity: "None"
  parameters:
    - name: "PROTOCOL"
      description: "protocol application uses"
    - name: "CONTAINER_PORT"
      description: "Container port number"
    - name: "EXT_PORT"
      description: "external port to be exposed"
    - name: "NODE_TEMPLATE_NAME"
      description: "Template name"


2. $ oc create -f bug1
3. $  oc process bug1 -v PROTOCOL=UDP,CONTAINER_PORT=888,EXT_PORT=999,NODE_TEMPLATE_NAME=bug-param | oc create -f -

Actual results:

ERROR:
The Service "bug-param" is invalid.
spec.ports[0].targetPort: Invalid value: "888": must be an IANA_SVC_NAME (at most 15 characters, matching regex [a-z0-9]([a-z0-9-]*[a-z0-9])*, it must contain at least one letter [a-z], and hyphens cannot be adjacent to other hyphens): e.g. "http"


Expected results:

Create the service. 


Additional info:

https://stackoverflow.com/questions/39281444/how-to-parameterize-ports-in-openshift-json-project-template


https://github.com/kubernetes/kubernetes/blob/release-1.3/pkg/api/types.go#L1790
https://github.com/kubernetes/kubernetes/blob/release-1.3/pkg/api/types.go#L883

This proposal would resolve this i think.
https://github.com/kubernetes/kubernetes/blob/master/docs/proposals/templates.md

Comment 1 Ryan Howe 2016-10-19 15:53:02 UTC
Would this upstream PR fix this issue? 
https://github.com/openshift/origin/pull/11421

Does this add the functionality to use double curly brackets to drop the quotes?

Comment 2 Derek Carr 2016-10-19 21:26:56 UTC
Port and TargetPort need to both be ints in this example.  Moving to Ben's team.

Comment 3 Ben Parees 2016-10-25 17:28:14 UTC
Support for non-string parameter values is coming in this PR:
https://github.com/openshift/origin/pull/11421

in the meantime it's not possible to use parameter substitution to define non-string fields in a template.  (and port, while an intorstring field, only supports integer values when they are unquoted, which isn't compatible w/ the current template parameter capabilities).

Comment 4 Troy Dawson 2016-10-27 16:12:52 UTC
This has been merged into ose and is in OSE v3.4.0.16 or newer.

Comment 6 Wang Haoran 2016-10-28 06:43:36 UTC
verified with: 
openshift v3.4.0.16+cc70b72
kubernetes v1.4.0+776c994
etcd 3.1.0-rc.0

Comment 8 errata-xmlrpc 2017-01-18 12:42:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:0066


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