Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #455 from cdrage/fix-port-mappings
Browse files Browse the repository at this point in the history
Allow the usage of a string or int as a value in portMappings
  • Loading branch information
concaf authored Nov 22, 2017
2 parents d9e9f70 + 2a1958c commit cb6fa14
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/examples/portMappings/mariadb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ containers:
value: wordpress
services:
- portMappings:
- 3306:3306/TCP
- 3306
type: NodePort
2 changes: 1 addition & 1 deletion pkg/spec/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
func (deployment *DeploymentSpecMod) Unmarshal(data []byte) error {
err := yaml.Unmarshal(data, &deployment)
if err != nil {
return errors.Wrap(err, "could not unmarshal into internal struct")
return errors.Wrap(err, "Deployment could not unmarshal into internal struct")
}
log.Debugf("object unmarshalled: %#v\n", deployment)
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/spec/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (app *ControllerFields) createServices() ([]runtime.Object, error) {
}

for _, portMapping := range s.PortMappings {
servicePort, err := parsePortMapping(portMapping)
servicePort, err := parsePortMapping(portMapping.String())
if err != nil {
return nil, errors.Wrap(err, "unable to parse port mapping")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/spec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
image_v1 "github.com/openshift/origin/pkg/image/apis/image/v1"
os_route_v1 "github.com/openshift/origin/pkg/route/apis/route/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
api_v1 "k8s.io/kubernetes/pkg/api/v1"
batch_v1 "k8s.io/kubernetes/pkg/apis/batch/v1"
ext_v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
Expand Down Expand Up @@ -63,7 +64,7 @@ type ServiceSpecMod struct {
// The list of portMappings, where each portMapping allows specifying port,
// targetPort and protocol in the format '<port>:<targetPort>/<protocol>'
// +optional
PortMappings []string `json:"portMappings,omitempty"`
PortMappings []intstr.IntOrString `json:"portMappings,omitempty"`
// k8s: io.k8s.kubernetes.pkg.apis.meta.v1.ObjectMeta
meta_v1.ObjectMeta `json:",inline"`
}
Expand Down
11 changes: 11 additions & 0 deletions tests/cmd/portmappings/port-mixed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: database

containers:
- image: mariadb:10

services:
- name: database
portMappings:
- 80
- "3306"
- "3307"
9 changes: 9 additions & 0 deletions tests/cmd/portmappings/port-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: database

containers:
- image: mariadb:10

services:
- name: database
portMappings:
- 3306:3306
9 changes: 9 additions & 0 deletions tests/cmd/portmappings/port-string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: database

containers:
- image: mariadb:10

services:
- name: database
portMappings:
- "3306"
9 changes: 9 additions & 0 deletions tests/cmd/portmappings/port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: database

containers:
- image: mariadb:10

services:
- name: database
portMappings:
- 3306

0 comments on commit cb6fa14

Please sign in to comment.