diff --git a/cncd/pipeline/pipec/pipec b/cncd/pipeline/pipec/pipec index 181f9f55bb1..c05e3c54331 100755 Binary files a/cncd/pipeline/pipec/pipec and b/cncd/pipeline/pipec/pipec differ diff --git a/cncd/pipeline/pipeline/backend/kubernetes/kubernetes.go b/cncd/pipeline/pipeline/backend/kubernetes/kubernetes.go index 549801ec3c6..cd0bef96005 100644 --- a/cncd/pipeline/pipeline/backend/kubernetes/kubernetes.go +++ b/cncd/pipeline/pipeline/backend/kubernetes/kubernetes.go @@ -73,9 +73,13 @@ func (e *engine) Setup(ctx context.Context, conf *backend.Config) error { for _, step := range stage.Steps { e.logs.WriteString("Creating service\n") var svc *v1.Service + var err error for _, n := range step.Networks { if len(n.Aliases) > 0 { - svc = Service(e.namespace, n.Aliases[0], podName(step), step.Ports) + svc, err = Service(e.namespace, n.Aliases[0], podName(step), step.Ports) + if err != nil { + return err + } } } @@ -247,7 +251,10 @@ func (e *engine) Destroy(ctx context.Context, conf *backend.Config) error { for _, step := range stage.Steps { e.logs.WriteString("Deleting service\n") for _, n := range step.Networks { - svc := Service(e.namespace, n.Aliases[0], step.Alias, step.Ports) + svc, err := Service(e.namespace, n.Aliases[0], step.Alias, step.Ports) + if err != nil { + return err + } if err := e.kubeClient.CoreV1().Services(e.namespace).Delete(svc.Name, deleteOpts); err != nil { return err } diff --git a/cncd/pipeline/pipeline/backend/kubernetes/services.go b/cncd/pipeline/pipeline/backend/kubernetes/services.go index 3a2237e18c8..49cc31dc3c7 100644 --- a/cncd/pipeline/pipeline/backend/kubernetes/services.go +++ b/cncd/pipeline/pipeline/backend/kubernetes/services.go @@ -1,17 +1,24 @@ package kubernetes import ( + "fmt" + "strconv" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) -func Service(namespace, name, podName string, ports []int) *v1.Service { +func Service(namespace, name, podName string, ports []string) (*v1.Service, error) { var svcPorts []v1.ServicePort for _, p := range ports { + i, err := strconv.Atoi(p) + if err != nil { + return nil, fmt.Errorf("Could not parse service port %s as integer", p) + } svcPorts = append(svcPorts, v1.ServicePort{ - Port: int32(p), - TargetPort: intstr.IntOrString{IntVal: int32(p)}, + Port: int32(i), + TargetPort: intstr.IntOrString{IntVal: int32(i)}, }) } @@ -27,5 +34,5 @@ func Service(namespace, name, podName string, ports []int) *v1.Service { }, Ports: svcPorts, }, - } + }, nil } diff --git a/cncd/pipeline/pipeline/backend/kubernetes/services_test.go b/cncd/pipeline/pipeline/backend/kubernetes/services_test.go index ded87252393..82a952c83cb 100644 --- a/cncd/pipeline/pipeline/backend/kubernetes/services_test.go +++ b/cncd/pipeline/pipeline/backend/kubernetes/services_test.go @@ -40,7 +40,7 @@ func TestService(t *testing.T) { } }` - s := Service("foo", "bar", "baz", []int{1, 2, 3}) + s, _ := Service("foo", "bar", "baz", []string{"1", "2", "3"}) j, err := json.Marshal(s) assert.Nil(t, err) assert.JSONEq(t, expected, string(j)) diff --git a/cncd/pipeline/pipeline/backend/types.go b/cncd/pipeline/pipeline/backend/types.go index 63972dbd84a..1b346ce6f05 100644 --- a/cncd/pipeline/pipeline/backend/types.go +++ b/cncd/pipeline/pipeline/backend/types.go @@ -48,7 +48,7 @@ type ( NetworkMode string `json:"network_mode,omitempty"` IpcMode string `json:"ipc_mode,omitempty"` Sysctls map[string]string `json:"sysctls,omitempty"` - Ports []int `json:"ports,omitempty"` + Ports []string `json:"ports,omitempty"` } // Auth defines registry authentication credentials. diff --git a/cncd/pipeline/pipeline/fixtures/02_services/pipeline.json b/cncd/pipeline/pipeline/fixtures/02_services/pipeline.json index 36579cacd34..9727c78b9c9 100644 --- a/cncd/pipeline/pipeline/fixtures/02_services/pipeline.json +++ b/cncd/pipeline/pipeline/fixtures/02_services/pipeline.json @@ -137,7 +137,10 @@ } ], "on_success": true, - "auth_config": {} + "auth_config": {}, + "ports": [ + "6379" + ] }, { "name": "pipeline_services_1", @@ -201,7 +204,10 @@ } ], "on_success": true, - "auth_config": {} + "auth_config": {}, + "ports": [ + "6379" + ] } ] }, diff --git a/cncd/pipeline/pipeline/fixtures/02_services/pipeline.yml b/cncd/pipeline/pipeline/fixtures/02_services/pipeline.yml index ae8b73bd0ad..f1b326f332c 100644 --- a/cncd/pipeline/pipeline/fixtures/02_services/pipeline.yml +++ b/cncd/pipeline/pipeline/fixtures/02_services/pipeline.yml @@ -13,5 +13,7 @@ pipeline: services: redis1: image: redis:3.0 + ports: ["6379"] redis2: image: redis:3.0 + ports: ["6379"] diff --git a/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go b/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go index ca3e98e75ec..afa3d453e23 100644 --- a/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go +++ b/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go @@ -142,6 +142,7 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section if c.reslimit.CPUSet != "" { cpuSet = c.reslimit.CPUSet } + ports := container.Ports return &backend.Step{ Name: name, @@ -176,5 +177,6 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section container.Constraints.Status.Match("failure"), NetworkMode: network_mode, IpcMode: ipc_mode, + Ports: ports, } } diff --git a/cncd/pipeline/pipeline/frontend/yaml/container.go b/cncd/pipeline/pipeline/frontend/yaml/container.go index e5975e8c02b..aeeef7b0738 100644 --- a/cncd/pipeline/pipeline/frontend/yaml/container.go +++ b/cncd/pipeline/pipeline/frontend/yaml/container.go @@ -58,6 +58,7 @@ type ( Sysctls libcompose.SliceorMap `yaml:"sysctls,omitempty"` Constraints Constraints `yaml:"when,omitempty"` Vargs map[string]interface{} `yaml:",inline"` + Ports []string `yaml:"ports,omitempty"` } )