Skip to content

Commit

Permalink
Annotate pod with outputs. Properly handle tar/gz of artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Nov 11, 2017
1 parent cd415c9 commit 736c5ec
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 51 deletions.
13 changes: 13 additions & 0 deletions api/workflow/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ func (in *Inputs) GetParameterByName(name string) *Parameter {
return nil
}

func (out *Outputs) HasOutputs() bool {
if out.Result != nil {
return true
}
if len(out.Artifacts) > 0 {
return true
}
if len(out.Parameters) > 0 {
return true
}
return false
}

func (args *Arguments) GetArtifactByName(name string) *Artifact {
for _, art := range args.Artifacts {
if art.Name == name {
Expand Down
11 changes: 9 additions & 2 deletions cmd/argoexec/commands/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ func saveArtifacts(cmd *cobra.Command, args []string) {
wfExecutor := initExecutor()
err := wfExecutor.SaveArtifacts()
if err != nil {
log.Errorf("Error saving output artifacts, %+v", err)
os.Exit(1)
log.Fatalf("Error saving output artifacts, %+v", err)
}
err = wfExecutor.CaptureScriptResult()
if err != nil {
log.Fatalf("Error capturing script output, %+v", err)
}
err = wfExecutor.AnnotateOutputs()
if err != nil {
log.Fatalf("Error annotating outputs, %+v", err)
}
os.Exit(0)
}
8 changes: 6 additions & 2 deletions cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func initExecutor() *executor.WorkflowExecutor {
// Read template
err := GetTemplateFromPodAnnotations(podAnnotationsPath, &wfTemplate)
if err != nil {
log.Errorf("Error getting template %v", err)
os.Exit(1)
log.Fatalf("Error getting template %v", err)
}

// Initialize in-cluster Kubernetes client
Expand All @@ -76,9 +75,14 @@ func initExecutor() *executor.WorkflowExecutor {
if err != nil {
panic(err.Error())
}
podName, ok := os.LookupEnv(common.EnvVarPodName)
if !ok {
log.Fatalf("Unable to determine pod name from environment variable %s", common.EnvVarPodName)
}

// Initialize workflow executor
wfExecutor := executor.WorkflowExecutor{
PodName: podName,
Template: wfTemplate,
ClientSet: clientset,
}
Expand Down
26 changes: 24 additions & 2 deletions examples/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ metadata:
generateName: ci-example-
spec:
entrypoint: ci-example
# a temporary volume, named workdir, will be used as a working
# directory for this workflow. This volume is passed around
# from step to step.
volumeClaimTemplates:
- metadata:
name: workdir
Expand All @@ -12,13 +15,25 @@ spec:
resources:
requests:
storage: 1Gi

templates:
- name: ci-example
steps:
- - name: build
template: build-golang-example
# the test step expands into three parallel steps running
# different operating system images. each mounts the workdir
# and runs the compiled binary from the build step.
- - name: test
template: run-hello
arguments:
parameters:
- name: os-image
value: "{{item.image}}:{{item.tag}}"
withItems:
- { image: 'debian', tag: '9.1' }
- { image: 'alpine', tag: '3.6' }
- { image: 'ubuntu', tag: '17.10' }

- name: build-golang-example
inputs:
Expand All @@ -39,10 +54,17 @@ spec:
mountPath: /go
- name: run-hello
inputs:
parameters:
- name: os-image
container:
image: debian:9.1
image: "{{inputs.parameters.os-image}}"
command: [sh, -c]
args: ["/go/src/github.com/golang/example/hello/hello"]
args: ["
uname -a ;
cat /etc/os-release ;
/go/src/github.com/golang/example/hello/hello
"]
volumeMounts:
- name: workdir
mountPath: /go
2 changes: 1 addition & 1 deletion examples/input-artifact-s3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
- name: input-artifact-s3-example
inputs:
artifacts:
- name: CODE
- name: code
path: /src
s3:
endpoint: storage.googleapis.com
Expand Down
6 changes: 3 additions & 3 deletions examples/nested-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ spec:
artifacts:
- name: message
steps:
- PRINT:
- - name: print
template: print-message
arguments:
artifacts:
- name: message
- name: message2
from: "{{inputs.artifacts.message}}"

- name: print-message
inputs:
artifacts:
- name: message
- name: message2
path: /tmp/message
container:
image: alpine:latest
Expand Down
4 changes: 2 additions & 2 deletions examples/sidecar-dind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ spec:
privileged: true
# mirrorVolumeMounts will mount the same volumes specified in the main container
# to the sidecar (including artifacts), at the same mountPaths. This enables
# dind daemon to partially see the same filesystem as the main container in
# order to use features such as docker volume binding
# dind daemon to (partially) see the same filesystem as the main container in
# order to use features such as docker volume binding.
mirrorVolumeMounts: true
5 changes: 3 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,12 @@ func (woc *wfOperationCtx) resolveReferences(stepGroup []wfv1.WorkflowStep, scop
if art.From == "" {
continue
}
art, err := scope.resolveArtifact(art.From)
resolvedArt, err := scope.resolveArtifact(art.From)
if err != nil {
return nil, err
}
newStep.Arguments.Artifacts[j] = *art
resolvedArt.Name = art.Name
newStep.Arguments.Artifacts[j] = *resolvedArt
}

newStepGroup[i] = newStep
Expand Down
9 changes: 0 additions & 9 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,6 @@ func addScriptVolume(pod *apiv1.Pod) {
found = true
break
}
if ctr.Name == common.WaitContainerName {
// Also annotate the pod with output result
ctr.Args = []string{ctr.Args[0] + `
output=$(grep stdout /var/lib/docker/containers/$container_id/*.log | jq -r '.log')
outputjson={\"result\":\"$output\"}
kubectl annotate pods $ARGO_POD_NAME --overwrite workflows.argoproj.io/outputs=${outputjson}
`}
pod.Spec.Containers[i] = ctr
}
}
if !found {
panic("Unable to locate main container")
Expand Down
Loading

0 comments on commit 736c5ec

Please sign in to comment.