Skip to content

Commit

Permalink
Fixed: Support hostAliases in WorkflowSpec #1265 (#1365)
Browse files Browse the repository at this point in the history
* Fixed : Support hostAliases in WorkflowSpec #1265
  • Loading branch information
sarabala1979 authored May 30, 2019
1 parent abb1747 commit 163f4a5
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 2 deletions.
14 changes: 14 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@
"description": "DAG template subtype which runs a DAG",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.DAGTemplate"
},
"hostAliases": {
"description": "HostAliases is an optional list of hosts and IPs that will be injected into the pod spec",
"type": "array",
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.HostAlias"
}
},
"initContainers": {
"description": "InitContainers is a list of containers which run before the main container.",
"type": "array",
Expand Down Expand Up @@ -1153,6 +1160,13 @@
"description": "Entrypoint is a template reference to the starting point of the workflow",
"type": "string"
},
"hostAliases": {
"description": "HostAliases is an optional list of hosts and IPs that will be injected into the pod spec",
"type": "array",
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.HostAlias"
}
},
"hostNetwork": {
"description": "Host networking requested for this workflow pod. Default to false.",
"type": "boolean"
Expand Down
30 changes: 28 additions & 2 deletions pkg/apis/workflow/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/apis/workflow/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ type WorkflowSpec struct {

// Priority to apply to workflow pods.
PodPriority *int32 `json:"podPriority,omitempty"`

// HostAliases is an optional list of hosts and IPs that will be injected into the pod spec
HostAliases []apiv1.HostAlias `json:"hostAliases,omitempty"`
}

// Template is a reusable and composable unit of execution in a workflow
Expand Down Expand Up @@ -252,6 +255,9 @@ type Template struct {

// Priority to apply to workflow pods.
Priority *int32 `json:"priority,omitempty"`

// HostAliases is an optional list of hosts and IPs that will be injected into the pod spec
HostAliases []apiv1.HostAlias `json:"hostAliases,omitempty"`
}

// Inputs are the mechanism for passing parameters, artifacts, volumes from one template to another
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions test/e2e/functional/template_level_host_aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: template-level-host-aliases-
spec:
entrypoint: nslookup

templates:
- name: nslookup
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "argo.io"
container:
image: alpine:latest
command: [sh, -c]
args: [" nslookup argo.io"]
16 changes: 16 additions & 0 deletions test/e2e/functional/workflow_level_host_aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow_level_host_aliases-
spec:
entrypoint: nslookup
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "argo.io"
templates:
- name: nslookup
container:
image: alpine:latest
command: [sh, -c]
args: ["nslookup argo.io"]
21 changes: 21 additions & 0 deletions test/e2e/functional/workflow_teemplate_level_host_aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-level-host-aliases-
spec:
entrypoint: nslookup
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "argo.io"

templates:
- name: nslookup
hostAliases:
- ip: "124.0.0.1"
hostnames:
- "argo1.io"
container:
image: alpine:latest
command: [sh, -c]
args: ["nslookup argo.io argo1.io "]
5 changes: 5 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ func addSchedulingConstraints(pod *apiv1.Pod, wfSpec *wfv1.WorkflowSpec, tmpl *w
} else if wfSpec.SchedulerName != "" {
pod.Spec.SchedulerName = wfSpec.SchedulerName
}

// set hostaliases
pod.Spec.HostAliases = append(pod.Spec.HostAliases, wfSpec.HostAliases...)
pod.Spec.HostAliases = append(pod.Spec.HostAliases, tmpl.HostAliases...)

}

// addVolumeReferences adds any volumeMounts that a container/sidecar is referencing, to the pod.spec.volumes
Expand Down
30 changes: 30 additions & 0 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,33 @@ func TestTemplateLocalVolumes(t *testing.T) {
assert.Contains(t, pod.Spec.Volumes, v)
}
}

// TestWFLevelHostAliases verifies the ability to carry forward workflow level HostAliases to Podspec
func TestWFLevelHostAliases(t *testing.T) {
woc := newWoc()
woc.wf.Spec.HostAliases = []apiv1.HostAlias{
{IP: "127.0.0.1"},
{IP: "127.0.0.1"},
}
woc.executeContainer(woc.wf.Spec.Entrypoint, &woc.wf.Spec.Templates[0], "")
podName := getPodName(woc.wf)
pod, err := woc.controller.kubeclientset.CoreV1().Pods("").Get(podName, metav1.GetOptions{})
assert.Nil(t, err)
assert.NotNil(t, pod.Spec.HostAliases)

}

// TestTmplLevelHostAliases verifies the ability to carry forward template level HostAliases to Podspec
func TestTmplLevelHostAliases(t *testing.T) {
woc := newWoc()
woc.wf.Spec.Templates[0].HostAliases = []apiv1.HostAlias{
{IP: "127.0.0.1"},
{IP: "127.0.0.1"},
}
woc.executeContainer(woc.wf.Spec.Entrypoint, &woc.wf.Spec.Templates[0], "")
podName := getPodName(woc.wf)
pod, err := woc.controller.kubeclientset.CoreV1().Pods("").Get(podName, metav1.GetOptions{})
assert.Nil(t, err)
assert.NotNil(t, pod.Spec.HostAliases)

}

0 comments on commit 163f4a5

Please sign in to comment.