generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 23
/
telemetry_test.go
297 lines (257 loc) · 13.4 KB
/
telemetry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//go:build e2e
package e2e
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
operatorv1alpha1 "github.com/kyma-project/telemetry-manager/apis/operator/v1alpha1"
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/testutils"
"github.com/kyma-project/telemetry-manager/test/testkit/assert"
kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s"
kitkyma "github.com/kyma-project/telemetry-manager/test/testkit/kyma"
"github.com/kyma-project/telemetry-manager/test/testkit/periodic"
"github.com/kyma-project/telemetry-manager/test/testkit/suite"
)
var _ = Describe(suite.ID(), Label(suite.LabelTelemetry), Ordered, func() {
Context("When a TracePipeline exists", Ordered, func() {
var (
tracePipelineName = suite.IDWithSuffix("traces-endpoints")
traceGRPCEndpoint = "http://telemetry-otlp-traces.kyma-system:4317"
traceHTTPEndpoint = "http://telemetry-otlp-traces.kyma-system:4318"
)
BeforeAll(func() {
tracePipeline := testutils.NewTracePipelineBuilder().WithName(tracePipelineName).Build()
DeferCleanup(func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, &tracePipeline)).Should(Succeed())
})
Expect(kitk8s.CreateObjects(ctx, k8sClient, &tracePipeline)).Should(Succeed())
})
It("Should have Telemetry with TracePipeline endpoints", func() {
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).Should(Succeed())
g.Expect(telemetry.Status.GatewayEndpoints.Traces).ShouldNot(BeNil())
g.Expect(telemetry.Status.GatewayEndpoints.Traces.GRPC).Should(Equal(traceGRPCEndpoint))
g.Expect(telemetry.Status.GatewayEndpoints.Traces.HTTP).Should(Equal(traceHTTPEndpoint))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
})
Context("When a MetricPipeline exists", Ordered, func() {
var (
metricPipelineName = suite.IDWithSuffix("metrics-endpoints")
metricGRPCEndpoint = "http://telemetry-otlp-metrics.kyma-system:4317"
metricHTTPEndpoint = "http://telemetry-otlp-metrics.kyma-system:4318"
)
BeforeAll(func() {
metricPipeline := testutils.NewMetricPipelineBuilder().WithName(metricPipelineName).Build()
DeferCleanup(func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, &metricPipeline)).Should(Succeed())
})
Expect(kitk8s.CreateObjects(ctx, k8sClient, &metricPipeline)).Should(Succeed())
})
It("Should have Telemetry with MetricPipeline endpoints", func() {
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).Should(Succeed())
g.Expect(telemetry.Status.GatewayEndpoints.Metrics).ShouldNot(BeNil())
g.Expect(telemetry.Status.GatewayEndpoints.Metrics.GRPC).Should(Equal(metricGRPCEndpoint))
g.Expect(telemetry.Status.GatewayEndpoints.Metrics.HTTP).Should(Equal(metricHTTPEndpoint))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
})
Context("When a misconfigured TracePipeline exists", Ordered, func() {
var (
tracePipelineName = suite.IDWithSuffix("missing-secret")
)
BeforeAll(func() {
tracePipeline := testutils.NewTracePipelineBuilder().
WithName(tracePipelineName).
WithOTLPOutput(testutils.OTLPEndpointFromSecret("non-existent-secret", kitkyma.DefaultNamespaceName, "endpoint")).
Build()
DeferCleanup(func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, &tracePipeline)).Should(Succeed())
})
Expect(kitk8s.CreateObjects(ctx, k8sClient, &tracePipeline)).Should(Succeed())
})
It("Should have Telemetry with warning state", func() {
assert.TelemetryHasState(ctx, k8sClient, operatorv1alpha1.StateWarning)
assert.TelemetryHasCondition(ctx, k8sClient, metav1.Condition{
Type: conditions.TypeTraceComponentsHealthy,
Status: metav1.ConditionFalse,
Reason: conditions.ReasonReferencedSecretMissing,
})
})
})
Context("After creating Telemetry resources", Ordered, func() {
It("Should have ValidatingWebhookConfiguration", func() {
Eventually(func(g Gomega) {
var validatingWebhookConfiguration admissionregistrationv1.ValidatingWebhookConfiguration
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: kitkyma.WebhookName}, &validatingWebhookConfiguration)).Should(Succeed())
g.Expect(validatingWebhookConfiguration.Webhooks).Should(HaveLen(2))
logPipelineWebhook := validatingWebhookConfiguration.Webhooks[0]
g.Expect(logPipelineWebhook.Name).Should(Equal("validation.logpipelines.telemetry.kyma-project.io"))
g.Expect(logPipelineWebhook.ClientConfig.CABundle).ShouldNot(BeEmpty())
g.Expect(logPipelineWebhook.ClientConfig.Service.Name).Should(Equal("telemetry-manager-webhook"))
g.Expect(logPipelineWebhook.ClientConfig.Service.Namespace).Should(Equal(kitkyma.SystemNamespaceName))
g.Expect(*logPipelineWebhook.ClientConfig.Service.Port).Should(Equal(int32(443)))
g.Expect(*logPipelineWebhook.ClientConfig.Service.Path).Should(Equal("/validate-logpipeline"))
g.Expect(logPipelineWebhook.Rules).Should(HaveLen(1))
g.Expect(logPipelineWebhook.Rules[0].Resources).Should(ContainElement("logpipelines"))
g.Expect(logPipelineWebhook.Rules[0].Operations).Should(ContainElement(admissionregistrationv1.Create))
g.Expect(logPipelineWebhook.Rules[0].Operations).Should(ContainElement(admissionregistrationv1.Update))
logParserWebhook := validatingWebhookConfiguration.Webhooks[1]
g.Expect(logParserWebhook.Name).Should(Equal("validation.logparsers.telemetry.kyma-project.io"))
g.Expect(logParserWebhook.ClientConfig.CABundle).ShouldNot(BeEmpty())
g.Expect(logParserWebhook.ClientConfig.Service.Name).Should(Equal("telemetry-manager-webhook"))
g.Expect(logParserWebhook.ClientConfig.Service.Namespace).Should(Equal(kitkyma.SystemNamespaceName))
g.Expect(*logParserWebhook.ClientConfig.Service.Port).Should(Equal(int32(443)))
g.Expect(*logParserWebhook.ClientConfig.Service.Path).Should(Equal("/validate-logparser"))
g.Expect(logParserWebhook.Rules).Should(HaveLen(1))
g.Expect(logParserWebhook.Rules[0].Resources).Should(ContainElement("logparsers"))
g.Expect(logParserWebhook.Rules[0].Operations).Should(ContainElement(admissionregistrationv1.Create))
g.Expect(logParserWebhook.Rules[0].Operations).Should(ContainElement(admissionregistrationv1.Update))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should have secret with webhook CA bundle", func() {
Eventually(func(g Gomega) {
var secret corev1.Secret
g.Expect(k8sClient.Get(ctx, kitkyma.WebhookCertSecret, &secret)).Should(Succeed())
g.Expect(secret.OwnerReferences).Should(HaveLen(1))
g.Expect(secret.OwnerReferences[0].Name).Should(Equal("default"))
g.Expect(secret.OwnerReferences[0].Kind).Should(Equal("Telemetry"))
g.Expect(secret.Data).Should(HaveKeyWithValue("ca.crt", Not(BeEmpty())))
g.Expect(secret.Data).Should(HaveKeyWithValue("ca.key", Not(BeEmpty())))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should reconcile ValidatingWebhookConfiguration", func() {
testWebhookReconciliation()
})
It("Should reconcile CA bundle secret", func() {
var oldUID types.UID
By("Deleting secret", func() {
var secret corev1.Secret
Expect(k8sClient.Get(ctx, kitkyma.WebhookCertSecret, &secret)).Should(Succeed())
oldUID = secret.UID
Expect(k8sClient.Delete(ctx, &secret)).Should(Succeed())
})
Eventually(func(g Gomega) {
var secret corev1.Secret
g.Expect(k8sClient.Get(ctx, kitkyma.WebhookCertSecret, &secret)).Should(Succeed())
g.Expect(secret.OwnerReferences).Should(HaveLen(1))
g.Expect(secret.UID).ShouldNot(Equal(oldUID))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
})
Context("Deleting Telemetry resources", Ordered, func() {
var (
logPipelineName = suite.IDWithSuffix("orphaned")
logPipeline = testutils.NewLogPipelineBuilder().
WithName(logPipelineName).
WithCustomOutput("Name stdout").
Build()
)
BeforeAll(func() {
Eventually(func(g Gomega) {
g.Expect(kitk8s.CreateObjects(ctx, k8sClient, &logPipeline)).Should(Succeed())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
AfterAll(func() {
// Re-create Telemetry to have ValidatingWebhookConfiguration for remaining tests
Eventually(func(g Gomega) {
newTelemetry := []client.Object{kitk8s.NewTelemetry("default", "kyma-system").K8sObject()}
g.Expect(kitk8s.CreateObjects(ctx, k8sClient, newTelemetry...)).Should(Succeed())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).Should(Succeed())
g.Expect(telemetry.Status.State).Should(Equal(operatorv1alpha1.StateReady))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should have Telemetry resource", func() {
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).Should(Succeed())
g.Expect(telemetry.Status.State).Should(Equal(operatorv1alpha1.StateReady))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should reconcile ValidatingWebhookConfiguration if LogPipeline exists", func() {
testWebhookReconciliation()
})
It("Should not delete Telemetry when LogPipeline exists", func() {
By("Deleting telemetry", func() {
Expect(kitk8s.ForceDeleteObjects(ctx, k8sClient, telemetryK8sObject)).Should(Succeed())
})
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).Should(Succeed())
g.Expect(telemetry.Finalizers).Should(HaveLen(1))
g.Expect(telemetry.Finalizers[0]).Should(Equal("telemetry.kyma-project.io/finalizer"))
g.Expect(telemetry.Status.State).Should(Equal(operatorv1alpha1.StateWarning))
expectedConditions := map[string]metav1.Condition{
conditions.TypeLogComponentsHealthy: {
Status: "False",
Reason: "ResourceBlocksDeletion",
Message: fmt.Sprintf("The deletion of the module is blocked. To unblock the deletion, delete the following resources: LogPipelines (%s)", logPipelineName),
},
conditions.TypeMetricComponentsHealthy: {
Status: "True",
Reason: "NoPipelineDeployed",
Message: "No pipelines have been deployed",
},
conditions.TypeTraceComponentsHealthy: {
Status: "True",
Reason: "NoPipelineDeployed",
Message: "No pipelines have been deployed",
},
}
g.Expect(telemetry.Status.Conditions).Should(HaveLen(3))
for _, actualCond := range telemetry.Status.Conditions {
expectedCond := expectedConditions[actualCond.Type]
g.Expect(expectedCond.Status).Should(Equal(actualCond.Status), "Condition: %+v", actualCond)
g.Expect(expectedCond.Reason).Should(Equal(actualCond.Reason), "Condition: %+v", actualCond)
g.Expect(expectedCond.Message).Should(Equal(actualCond.Message), "Condition: %+v", actualCond)
g.Expect(actualCond.LastTransitionTime).NotTo(BeZero())
}
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should delete Telemetry", func() {
By("Deleting the orphaned LogPipeline", func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, &logPipeline)).Should(Succeed())
})
Eventually(func(g Gomega) {
var telemetry operatorv1alpha1.Telemetry
g.Expect(k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry)).ShouldNot(Succeed())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})
It("Should not have Webhook and CA bundle", func() {
Eventually(func(g Gomega) {
var validatingWebhookConfiguration admissionregistrationv1.ValidatingWebhookConfiguration
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: kitkyma.WebhookName}, &validatingWebhookConfiguration)).Should(Succeed())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).ShouldNot(Succeed())
Eventually(func(g Gomega) {
var secret corev1.Secret
g.Expect(k8sClient.Get(ctx, kitkyma.WebhookCertSecret, &secret)).Should(Succeed())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).ShouldNot(Succeed())
})
})
})
func testWebhookReconciliation() {
var oldUID types.UID
By("Deleting ValidatingWebhookConfiguration", func() {
var validatingWebhookConfiguration admissionregistrationv1.ValidatingWebhookConfiguration
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: kitkyma.WebhookName}, &validatingWebhookConfiguration)).Should(Succeed())
oldUID = validatingWebhookConfiguration.UID
Expect(k8sClient.Delete(ctx, &validatingWebhookConfiguration)).Should(Succeed())
})
Eventually(func(g Gomega) {
var validatingWebhookConfiguration admissionregistrationv1.ValidatingWebhookConfiguration
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: kitkyma.WebhookName}, &validatingWebhookConfiguration)).Should(Succeed())
g.Expect(validatingWebhookConfiguration.UID).ShouldNot(Equal(oldUID))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
}