mirror of https://github.com/linkerd/linkerd2.git
Integration test for k8s events generated during install (#2805)
Integration test for k8s events generated during install Fixes #2713 I did make sure a scenario like the one described in #2964 is caught. Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
This commit is contained in:
parent
87e69bf885
commit
f4ab9d6f9e
|
@ -1,6 +1,7 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/linkerd/linkerd2/pkg/k8s"
|
"github.com/linkerd/linkerd2/pkg/k8s"
|
||||||
"github.com/linkerd/linkerd2/testutil"
|
"github.com/linkerd/linkerd2/testutil"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type deploySpec struct {
|
type deploySpec struct {
|
||||||
|
@ -75,6 +77,12 @@ var (
|
||||||
`.* linkerd-prometheus-.*-.* linkerd-proxy ERR! \[ +\d+.\d+s\] proxy={server=out listen=127\.0\.0\.1:4140 remote=.*} linkerd2_proxy::proxy::http::router service error: an error occurred trying to connect: .*`,
|
`.* linkerd-prometheus-.*-.* linkerd-proxy ERR! \[ +\d+.\d+s\] proxy={server=out listen=127\.0\.0\.1:4140 remote=.*} linkerd2_proxy::proxy::http::router service error: an error occurred trying to connect: .*`,
|
||||||
}, "|"))
|
}, "|"))
|
||||||
|
|
||||||
|
knownEventWarningsRegex = regexp.MustCompile(strings.Join([]string{
|
||||||
|
`MountVolume.SetUp failed for volume .* : couldn't propagate object cache: timed out waiting for the condition`,
|
||||||
|
`Readiness probe failed: HTTP probe failed with statuscode: 50(2|3)`,
|
||||||
|
`(Liveness|Readiness) probe failed: Get http://.*: dial tcp .*: connect: connection refused`,
|
||||||
|
}, "|"))
|
||||||
|
|
||||||
injectionCases = []struct {
|
injectionCases = []struct {
|
||||||
ns string
|
ns string
|
||||||
annotations map[string]string
|
annotations map[string]string
|
||||||
|
@ -473,7 +481,7 @@ func TestLogs(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer outputStream.Stop()
|
defer outputStream.Stop()
|
||||||
// Ignore the error returned, since ReadUntil will return an error if it
|
// Ignore the error returned, since ReadUntil will return an error if it
|
||||||
// does not return 10,000 after 1 second. We don't need 10,000 log lines.
|
// does not return 10,000 after 2 seconds. We don't need 10,000 log lines.
|
||||||
outputLines, _ := outputStream.ReadUntil(10000, 2*time.Second)
|
outputLines, _ := outputStream.ReadUntil(10000, 2*time.Second)
|
||||||
if len(outputLines) == 0 {
|
if len(outputLines) == 0 {
|
||||||
t.Errorf("No logs found for %s", name)
|
t.Errorf("No logs found for %s", name)
|
||||||
|
@ -483,10 +491,10 @@ func TestLogs(t *testing.T) {
|
||||||
if errRegex.MatchString(line) {
|
if errRegex.MatchString(line) {
|
||||||
if knownErrorsRegex.MatchString(line) {
|
if knownErrorsRegex.MatchString(line) {
|
||||||
// report all known logging errors in the output
|
// report all known logging errors in the output
|
||||||
t.Skipf("Found known error in %s log: %s", name, line)
|
t.Logf("Found known error in %s log: %s", name, line)
|
||||||
} else {
|
} else {
|
||||||
if proxy {
|
if proxy {
|
||||||
t.Skipf("Found unexpected proxy error in %s log: %s", name, line)
|
t.Logf("Found unexpected proxy error in %s log: %s", name, line)
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("Found unexpected controller error in %s log: %s", name, line)
|
t.Errorf("Found unexpected controller error in %s log: %s", name, line)
|
||||||
}
|
}
|
||||||
|
@ -498,6 +506,47 @@ func TestLogs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEvents(t *testing.T) {
|
||||||
|
out, err := TestHelper.Kubectl("",
|
||||||
|
"--namespace", TestHelper.GetLinkerdNamespace(),
|
||||||
|
"get", "events", "-ojson",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("kubectl get events command failed with %s\n%s", err, out)
|
||||||
|
}
|
||||||
|
var list corev1.List
|
||||||
|
if err := json.Unmarshal([]byte(out), &list); err != nil {
|
||||||
|
t.Errorf("Error unmarshaling list from `kubectl get events`: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(list.Items) == 0 {
|
||||||
|
t.Error("No events found")
|
||||||
|
}
|
||||||
|
|
||||||
|
var unknownEvents []string
|
||||||
|
for _, i := range list.Items {
|
||||||
|
var e corev1.Event
|
||||||
|
if err := json.Unmarshal(i.Raw, &e); err != nil {
|
||||||
|
t.Errorf("Error unmarshaling list event from `kubectl get events`: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.Type == corev1.EventTypeNormal {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
evtStr := fmt.Sprintf("%s %s %s", e.Reason, e.InvolvedObject.Name, e.Message)
|
||||||
|
if knownEventWarningsRegex.MatchString(e.Message) {
|
||||||
|
t.Logf("Found known warning event: %s", evtStr)
|
||||||
|
} else {
|
||||||
|
unknownEvents = append(unknownEvents, evtStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(unknownEvents) > 0 {
|
||||||
|
t.Errorf("Found unexpected warning events:\n%s", strings.Join(unknownEvents, "\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRestarts(t *testing.T) {
|
func TestRestarts(t *testing.T) {
|
||||||
for deploy, spec := range linkerdDeployReplicas {
|
for deploy, spec := range linkerdDeployReplicas {
|
||||||
if err := TestHelper.CheckPods(TestHelper.GetLinkerdNamespace(), deploy, spec.replicas); err != nil {
|
if err := TestHelper.CheckPods(TestHelper.GetLinkerdNamespace(), deploy, spec.replicas); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue