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

fix(executor): Capture emissary main-logs. Fixes #6145 #6146

Merged
merged 3 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cmd/argoexec/commands/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewEmissaryCommand() *cobra.Command {
command.Stderr = os.Stderr

// this may not be that important an optimisation, except for very long logs we don't want to capture
if includeScriptOutput {
if includeScriptOutput || template.SaveLogsAsArtifact() {
logger.Info("capturing logs")
stdout, err := os.Create(varRunArgo + "/ctr/" + containerName + "/stdout")
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ func (s *ArtifactsSuite) TestOutputResult() {
})
}

func (s *ArtifactsSuite) TestMainLog() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectArtifact("-", "main-logs", func(t *testing.T, data []byte) {
assert.NotEmpty(t, data)
})
}

func TestArtifactsSuite(t *testing.T) {
suite.Run(t, new(ArtifactsSuite))
}
5 changes: 5 additions & 0 deletions test/e2e/fixtures/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (s *E2ESuite) GetServiceAccountToken() (string, error) {
}

func (s *E2ESuite) Given() *Given {
bearerToken, err := s.GetServiceAccountToken()
if err != nil {
s.T().Fatal(err)
}
return &Given{
t: s.T(),
client: s.wfClient,
Expand All @@ -216,5 +220,6 @@ func (s *E2ESuite) Given() *Given {
cronClient: s.cronClient,
hydrator: s.hydrator,
kubeClient: s.KubeClient,
bearerToken: bearerToken,
}
}
2 changes: 2 additions & 0 deletions test/e2e/fixtures/given.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Given struct {
cwfTemplates []*wfv1.ClusterWorkflowTemplate
cronWf *wfv1.CronWorkflow
kubeClient kubernetes.Interface
bearerToken string
}

// creates a workflow based on the parameter, this may be:
Expand Down Expand Up @@ -202,5 +203,6 @@ func (g *Given) When() *When {
cronClient: g.cronClient,
hydrator: g.hydrator,
kubeClient: g.kubeClient,
bearerToken: g.bearerToken,
}
}
63 changes: 50 additions & 13 deletions test/e2e/fixtures/then.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fixtures
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"testing"
"time"
Expand All @@ -19,13 +21,14 @@ import (
)

type Then struct {
t *testing.T
wf *wfv1.Workflow
cronWf *wfv1.CronWorkflow
client v1alpha1.WorkflowInterface
cronClient v1alpha1.CronWorkflowInterface
hydrator hydrator.Interface
kubeClient kubernetes.Interface
t *testing.T
wf *wfv1.Workflow
cronWf *wfv1.CronWorkflow
client v1alpha1.WorkflowInterface
cronClient v1alpha1.CronWorkflowInterface
hydrator hydrator.Interface
kubeClient kubernetes.Interface
bearerToken string
}

func (t *Then) ExpectWorkflow(block func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus)) *Then {
Expand Down Expand Up @@ -173,6 +176,39 @@ func (t *Then) ExpectAuditEvents(filter func(event apiv1.Event) bool, num int, b
return t
}

func (t *Then) ExpectArtifact(nodeName, artifactName string, f func(t *testing.T, data []byte)) {
t.t.Helper()
nodeId := nodeIdForName(nodeName, t.wf)
url := "http://localhost:2746/artifacts/" + Namespace + "/" + t.wf.Name + "/" + nodeId + "/" + artifactName
println(url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.t.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+t.bearerToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.t.Fatal(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.t.Fatal(err)
}
if resp.StatusCode != 200 {
t.t.Fatal(fmt.Errorf("HTTP request not OK: %s: %q", resp.Status, data))
}
f(t.t, data)
}

func nodeIdForName(nodeName string, wf *wfv1.Workflow) string {
if nodeName == "-" {
return wf.NodeID(wf.Name)
} else {
return wf.NodeID(nodeName)
}
}

func (t *Then) RunCli(args []string, block func(t *testing.T, output string, err error)) *Then {
t.t.Helper()
output, err := Exec("../../dist/argo", append([]string{"-n", Namespace}, args...)...)
Expand All @@ -182,11 +218,12 @@ func (t *Then) RunCli(args []string, block func(t *testing.T, output string, err

func (t *Then) When() *When {
return &When{
t: t.t,
client: t.client,
cronClient: t.cronClient,
hydrator: t.hydrator,
wf: t.wf,
kubeClient: t.kubeClient,
t: t.t,
client: t.client,
cronClient: t.cronClient,
hydrator: t.hydrator,
wf: t.wf,
kubeClient: t.kubeClient,
bearerToken: t.bearerToken,
}
}
16 changes: 9 additions & 7 deletions test/e2e/fixtures/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type When struct {
cronClient v1alpha1.CronWorkflowInterface
hydrator hydrator.Interface
kubeClient kubernetes.Interface
bearerToken string
}

func (w *When) SubmitWorkflow() *When {
Expand Down Expand Up @@ -412,13 +413,14 @@ func (w *When) deleteResourceQuota(name string) *When {

func (w *When) Then() *Then {
return &Then{
t: w.t,
wf: w.wf,
cronWf: w.cronWf,
client: w.client,
cronClient: w.cronClient,
hydrator: w.hydrator,
kubeClient: w.kubeClient,
t: w.t,
wf: w.wf,
cronWf: w.cronWf,
client: w.client,
cronClient: w.cronClient,
hydrator: w.hydrator,
kubeClient: w.kubeClient,
bearerToken: w.bearerToken,
}
}

Expand Down