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 journalctl logs to E2E tests #6224

Merged
merged 1 commit into from
Oct 7, 2022
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
39 changes: 39 additions & 0 deletions .github/workflows/build-k3s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build K3s

on:
workflow_call:
inputs:
upload-repo:
type: boolean
required: false
default: false

jobs:
build:
name: Build
runs-on: ubuntu-20.04
timeout-minutes: 20
steps:
- name: Checkout K3s
uses: actions/checkout@v3
- name: Build K3s binary
run: |
DOCKER_BUILDKIT=1 SKIP_AIRGAP=1 SKIP_VALIDATE=1 make

- name: bundle repo
if: inputs.upload-repo == true
run: |
tar -czvf ../k3s-repo.tar.gz .
mv ../k3s-repo.tar.gz .
- name: "Upload K3s directory"
if: inputs.upload-repo == true
uses: actions/upload-artifact@v3
with:
name: k3s-repo.tar.gz
path: k3s-repo.tar.gz
- name: "Upload K3s binary"
if: inputs.upload-repo == false
uses: actions/upload-artifact@v3
with:
name: k3s
path: dist/artifacts/k3s
26 changes: 5 additions & 21 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,23 @@ on:
- "**.md"
- "channel.yaml"
- "install.sh"
- "tests/snapshotter/**"
- "tests/install/**"
- "tests/cgroup/**"
- "tests/**"
- "!tests/integration**"
- ".github/**"
- "!.github/workflows/integration.yaml"
pull_request:
paths-ignore:
- "**.md"
- "channel.yaml"
- "install.sh"
- "tests/snapshotter/**"
- "tests/install/**"
- "tests/cgroup/**"
- "tests/**"
- "!tests/integration**"
- ".github/**"
- "!.github/workflows/integration.yaml"
workflow_dispatch: {}
jobs:
build:
name: Build
runs-on: ubuntu-20.04
timeout-minutes: 20
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: "Make"
run: DOCKER_BUILDKIT=1 SKIP_VALIDATE=1 make
- name: "Upload k3s binary"
uses: actions/upload-artifact@v2
with:
name: k3s
path: dist/artifacts/k3s
uses: ./.github/workflows/build-k3s.yaml
test:
needs: build
name: Integration Tests
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/clusterreset/clusterreset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("Verify Create", Ordered, func() {
} else {
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
}
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("Verify CRI-Dockerd", Ordered, func() {
It("Starts up with no issues", func() {
var err error
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/dualstack/dualstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var _ = Describe("Verify DualStack Configuration", Ordered, func() {
It("Starts up with no issues", func() {
var err error
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/splitserver/splitserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var _ = Describe("Verify Create", Ordered, func() {
It("Starts up with no issues", func() {
var err error
etcdNodeNames, cpNodeNames, agentNodeNames, err = createSplitCluster(*nodeOS, *etcdCount, *controlPlaneCount, *agentCount)
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Etcd Server Nodes:", etcdNodeNames)
Expand Down
44 changes: 38 additions & 6 deletions tests/e2e/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -32,6 +33,28 @@ type Pod struct {
Node string
}

type NodeError struct {
Node string
Cmd string
Err error
}

func (ne *NodeError) Error() string {
return fmt.Sprintf("failed creating cluster: %s: %v", ne.Cmd, ne.Err)
}

func (ne *NodeError) Unwrap() error {
return ne.Err
}

func newNodeError(cmd, node string, err error) *NodeError {
return &NodeError{
Cmd: cmd,
Node: node,
Err: err,
}
}

func CountOfStringInSlice(str string, pods []Pod) int {
count := 0
for _, pod := range pods {
Expand Down Expand Up @@ -79,15 +102,15 @@ func CreateCluster(nodeOS string, serverCount, agentCount int) ([]string, []stri

fmt.Println(cmd)
if _, err := RunCommand(cmd); err != nil {
return nil, nil, fmt.Errorf("failed creating cluster: %s: %v", cmd, err)
return nil, nil, newNodeError(cmd, serverNodeNames[0], err)
}
// Bring up the rest of the nodes in parallel
errg, _ := errgroup.WithContext(context.Background())
for _, node := range append(serverNodeNames[1:], agentNodeNames...) {
cmd := fmt.Sprintf(`%s %s vagrant up %s &>> vagrant.log`, nodeEnvs, testOptions, node)
errg.Go(func() error {
if _, err := RunCommand(cmd); err != nil {
return fmt.Errorf("failed creating cluster: %s: %v", cmd, err)
return newNodeError(cmd, node, err)
}
return nil
})
Expand Down Expand Up @@ -128,7 +151,7 @@ func CreateLocalCluster(nodeOS string, serverCount, agentCount int) ([]string, [
}
errg.Go(func() error {
if _, err := RunCommand(cmd); err != nil {
return fmt.Errorf("failed creating cluster: %s: %v", cmd, err)
return fmt.Errorf("failed initializing nodes: %s: %v", cmd, err)
}
return nil
})
Expand All @@ -154,7 +177,7 @@ func CreateLocalCluster(nodeOS string, serverCount, agentCount int) ([]string, [
cmd = fmt.Sprintf(`%s %s vagrant provision %s &>> vagrant.log`, nodeEnvs, testOptions, node)
errg.Go(func() error {
if _, err := RunCommand(cmd); err != nil {
return fmt.Errorf("failed creating cluster: %s: %v", cmd, err)
return newNodeError(cmd, node, err)
}
return nil
})
Expand Down Expand Up @@ -251,7 +274,16 @@ func GenKubeConfigFile(serverName string) (string, error) {
return kubeConfigFile, nil
}

func GetVagrantLog() string {
// GetVagrantLog returns the logs of on vagrant commands that initialize the nodes and provision K3s on each node.
// It also attempts to fetch the systemctl logs of K3s on nodes where the k3s.service failed.
func GetVagrantLog(cErr error) string {
var nodeErr *NodeError
nodeJournal := ""
if errors.As(cErr, &nodeErr) {
nodeJournal, _ = RunCommand("vagrant ssh " + nodeErr.Node + " -c \"sudo journalctl -u k3s* --no-pager\"")
nodeJournal = "\nNode Journal Logs:\n" + nodeJournal
}

log, err := os.Open("vagrant.log")
if err != nil {
return err.Error()
Expand All @@ -260,7 +292,7 @@ func GetVagrantLog() string {
if err != nil {
return err.Error()
}
return string(bytes)
return string(bytes) + nodeJournal
}

func ParseNodes(kubeConfig string, print bool) ([]Node, error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/upgradecluster/upgradecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Verify Upgrade", Ordered, func() {
It("Starts up with no issues", func() {
var err error
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/validatecluster/validatecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Verify Create", Ordered, func() {
} else {
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
}
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog())
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
Expand Down