Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ports into pipeline backend step model #2656

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID s
return err
}
log.Trace().Str("pod-name", stepName).Msgf("Creating service: %s", step.Name)
// TODO: support ports setting
// svc, err := Service(e.config.Namespace, step.Name, stepName, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, stepName, []string{})
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
xoxys marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down Expand Up @@ -362,9 +360,7 @@ func (e *kube) DestroyWorkflow(_ context.Context, conf *types.Config, taskUUID s
if stage.Alias == "services" {
for _, step := range stage.Steps {
log.Trace().Msgf("Deleting service: %s", step.Name)
// TODO: support ports setting
// svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, step.Alias, []string{})
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
if err != nil {
return err
}
Expand Down
15 changes: 4 additions & 11 deletions pipeline/backend/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
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 []string) (*v1.Service, error) {
func Service(namespace, name, podName string, ports []int32) (*v1.Service, error) {
6543 marked this conversation as resolved.
Show resolved Hide resolved
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)
}
for _, port := range ports {
svcPorts = append(svcPorts, v1.ServicePort{
Port: int32(i),
TargetPort: intstr.IntOrString{IntVal: int32(i)},
Port: port,
TargetPort: intstr.IntOrString{IntVal: port},
})
}

Expand Down
1 change: 1 addition & 0 deletions pipeline/backend/types/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Step struct {
NetworkMode string `json:"network_mode,omitempty"`
IpcMode string `json:"ipc_mode,omitempty"`
Sysctls map[string]string `json:"sysctls,omitempty"`
Ports []int32 `json:"ports,omitempty"`
6543 marked this conversation as resolved.
Show resolved Hide resolved
BackendOptions BackendOptions `json:"backend_options,omitempty"`
}

Expand Down
6 changes: 6 additions & 0 deletions pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func (c *Compiler) createProcess(name string, container *yaml_types.Container, s
cpuSet = c.reslimit.CPUSet
}

var ports []int32
6543 marked this conversation as resolved.
Show resolved Hide resolved
for _, port := range container.Ports {
ports = append(ports, int32(port))
6543 marked this conversation as resolved.
Show resolved Hide resolved
}

// at least one constraint contain status success, or all constraints have no status set
onSuccess := container.When.IncludesStatusSuccess()
// at least one constraint must include the status failure.
Expand Down Expand Up @@ -207,6 +212,7 @@ func (c *Compiler) createProcess(name string, container *yaml_types.Container, s
Failure: failure,
NetworkMode: networkMode,
IpcMode: ipcMode,
Ports: ports,
BackendOptions: backendOptions,
}
}
Expand Down
1 change: 1 addition & 0 deletions pipeline/frontend/yaml/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type (
Settings map[string]interface{} `yaml:"settings"`
Volumes Volumes `yaml:"volumes,omitempty"`
When constraint.When `yaml:"when,omitempty"`
Ports []base.StringOrInt `yaml:"ports,omitempty"`

// Docker Specific
Privileged bool `yaml:"privileged,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pipeline/frontend/yaml/types/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ when:
settings:
foo: bar
baz: false
ports:
- 8080
`)

func TestUnmarshalContainer(t *testing.T) {
Expand Down Expand Up @@ -126,6 +128,7 @@ func TestUnmarshalContainer(t *testing.T) {
"foo": "bar",
"baz": false,
},
Ports: []base.StringOrInt{8080},
}
got := Container{}
err := yaml.Unmarshal(containerYaml, &got)
Expand Down