generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for LogPipeline namespace selection
- Loading branch information
Showing
4 changed files
with
233 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"net/http" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" | ||
. "github.com/kyma-project/telemetry-manager/test/testkit/matchers/log" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/loggen" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/periodic" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/verifiers" | ||
) | ||
|
||
var _ = Describe("Logs Exclude Namespace", Label("logs"), Ordered, func() { | ||
const ( | ||
mockNs = "log-exclude-namespace-mocks" | ||
mockBackendName = "log-receiver-exclude-namespace" | ||
logProducerName = "log-producer-exclude-namespace" | ||
pipelineName = "pipeline-exclude-namespace-test" | ||
) | ||
var telemetryExportURL string | ||
|
||
makeResources := func() []client.Object { | ||
var objs []client.Object | ||
objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject()) | ||
|
||
mockBackend := backend.New(mockBackendName, mockNs, backend.SignalTypeLogs) | ||
mockLogProducer := loggen.New(logProducerName, mockNs) | ||
objs = append(objs, mockBackend.K8sObjects()...) | ||
objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-exclude-namespace"))) | ||
telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) | ||
|
||
logPipeline := kitk8s.NewLogPipeline(pipelineName). | ||
WithSecretKeyRef(mockBackend.HostSecretRef()). | ||
WithHTTPOutput(). | ||
WithExcludeNamespaces([]string{"kyma-system"}) | ||
objs = append(objs, logPipeline.K8sObject()) | ||
|
||
return objs | ||
} | ||
|
||
Context("Before deploying a logpipeline", func() { | ||
It("Should have a healthy webhook", func() { | ||
verifiers.WebhookShouldBeHealthy(ctx, k8sClient) | ||
}) | ||
}) | ||
|
||
Context("When a logpipeline that excludes containers exists", Ordered, func() { | ||
BeforeAll(func() { | ||
k8sObjects := makeResources() | ||
DeferCleanup(func() { | ||
Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) | ||
}) | ||
Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) | ||
}) | ||
|
||
It("Should have a running logpipeline", func() { | ||
verifiers.LogPipelineShouldBeRunning(ctx, k8sClient, pipelineName) | ||
}) | ||
|
||
It("Should have a log backend running", func() { | ||
verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: mockBackendName}) | ||
}) | ||
|
||
It("Should have a log producer running", func() { | ||
verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: logProducerName}) | ||
}) | ||
|
||
It("Should have any logs in the backend", func() { | ||
Eventually(func(g Gomega) { | ||
resp, err := proxyClient.Get(telemetryExportURL) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK)) | ||
g.Expect(resp).To(HaveHTTPBody( | ||
ContainLd( | ||
SatisfyAll( | ||
ContainLogRecord(WithNamespace(Equal("kube-system"))), | ||
ContainLogRecord(WithNamespace(Equal(mockNs))), | ||
)), | ||
)) | ||
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed()) | ||
}) | ||
|
||
It("Should have no kyma-system logs in the backend", func() { | ||
Consistently(func(g Gomega) { | ||
resp, err := proxyClient.Get(telemetryExportURL) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK)) | ||
g.Expect(resp).To(HaveHTTPBody(Not(ContainLd(ContainLogRecord( | ||
WithNamespace(Equal("kyma-system"))))), | ||
)) | ||
}, periodic.TelemetryConsistentlyTimeout, periodic.TelemetryInterval).Should(Succeed()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"net/http" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" | ||
. "github.com/kyma-project/telemetry-manager/test/testkit/matchers/log" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/loggen" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/periodic" | ||
"github.com/kyma-project/telemetry-manager/test/testkit/verifiers" | ||
) | ||
|
||
var _ = Describe("Logs Include Namespaces", Label("logs"), Ordered, func() { | ||
const ( | ||
mockNs = "log-include-namespaces-mocks" | ||
systemNamespace = "kyma-system" | ||
mockBackendName = "log-receiver-include-namespaces" | ||
logProducerName = "log-producer-include-namespaces" | ||
pipelineName = "pipeline-include-namespaces-test" | ||
) | ||
var telemetryExportURL string | ||
|
||
makeResources := func() []client.Object { | ||
var objs []client.Object | ||
objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject()) | ||
|
||
mockBackend := backend.New(mockBackendName, mockNs, backend.SignalTypeLogs) | ||
mockLogProducer := loggen.New(logProducerName, mockNs) | ||
objs = append(objs, mockBackend.K8sObjects()...) | ||
objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-include-namespaces"))) | ||
telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) | ||
|
||
logPipeline := kitk8s.NewLogPipeline(pipelineName). | ||
WithSecretKeyRef(mockBackend.HostSecretRef()). | ||
WithHTTPOutput(). | ||
WithIncludeNamespaces([]string{"kyma-system", mockNs}). | ||
WithExcludeContainers([]string{logProducerName}) | ||
objs = append(objs, logPipeline.K8sObject()) | ||
|
||
return objs | ||
} | ||
|
||
Context("Before deploying a logpipeline", func() { | ||
It("Should have a healthy webhook", func() { | ||
verifiers.WebhookShouldBeHealthy(ctx, k8sClient) | ||
}) | ||
}) | ||
|
||
Context("When a logpipeline that includes namespaces exists", Ordered, func() { | ||
BeforeAll(func() { | ||
k8sObjects := makeResources() | ||
DeferCleanup(func() { | ||
Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) | ||
}) | ||
Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) | ||
}) | ||
|
||
It("Should have a running logpipeline", func() { | ||
verifiers.LogPipelineShouldBeRunning(ctx, k8sClient, pipelineName) | ||
}) | ||
|
||
It("Should have a log backend running", func() { | ||
verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: mockBackendName}) | ||
}) | ||
|
||
It("Should have a log producer running", func() { | ||
verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: logProducerName}) | ||
}) | ||
|
||
It("Should have logs from expected namespaces", func() { | ||
Eventually(func(g Gomega) { | ||
resp, err := proxyClient.Get(telemetryExportURL) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK)) | ||
g.Expect(resp).To(HaveHTTPBody( | ||
ContainLd( | ||
SatisfyAll( | ||
ContainLogRecord(WithNamespace(Equal(systemNamespace))), | ||
ContainLogRecord(WithNamespace(Equal(mockNs))), | ||
)), | ||
)) | ||
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed()) | ||
}) | ||
|
||
It("Should have no no logs from kube-system in the backend", func() { | ||
Consistently(func(g Gomega) { | ||
resp, err := proxyClient.Get(telemetryExportURL) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK)) | ||
g.Expect(resp).To(HaveHTTPBody(Not(ContainLd(ContainLogRecord( | ||
WithNamespace(Equal("kube-system"))))), | ||
)) | ||
}, periodic.TelemetryConsistentlyTimeout, periodic.TelemetryInterval).Should(Succeed()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters