Skip to content

Commit c66f8b9

Browse files
[chore] configuration switching tests stabilisation (#1737)
* tests stabilisation * moving internal.ResetLogsSink to proper place
1 parent a677255 commit c66f8b9

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

functional_tests/configuration_switching/configuration_switching_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ func testIndexSwitch(t *testing.T) {
206206
"Sourcetype": nonDefaultSourcetype,
207207
}
208208
deployChartsAndApps(t, valuesFileName, replacements)
209+
internal.ResetMetricsSink(t, hecMetricsConsumer)
210+
internal.ResetLogsSink(t, agentLogsConsumer)
209211

210212
internal.WaitForLogs(t, 3, agentLogsConsumer)
211213
logs := agentLogsConsumer.AllLogs()
@@ -221,6 +223,13 @@ func testIndexSwitch(t *testing.T) {
221223
}
222224

223225
func testClusterReceiverEnabledOrDisabled(t *testing.T) {
226+
testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG")
227+
require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set")
228+
config, err := clientcmd.BuildConfigFromFlags("", testKubeConfig)
229+
require.NoError(t, err)
230+
clientset, err := kubernetes.NewForConfig(config)
231+
require.NoError(t, err)
232+
224233
valuesFileName := "values_cluster_receiver_switching.yaml.tmpl"
225234
logsObjectsConsumer := globalSinks.logsObjectsConsumer
226235
hostEp := internal.HostEndpoint(t)
@@ -230,25 +239,26 @@ func testClusterReceiverEnabledOrDisabled(t *testing.T) {
230239
logsObjectsHecEndpoint := fmt.Sprintf("http://%s:%d/services/collector", hostEp, internal.HECObjectsReceiverPort)
231240

232241
t.Run("check cluster receiver disabled", func(t *testing.T) {
233-
internal.ResetLogsSink(t, logsObjectsConsumer)
234242
replacements := map[string]interface{}{
235243
"ClusterReceiverEnabled": false,
236244
"LogObjectsHecEndpoint": logsObjectsHecEndpoint,
237245
}
238246
deployChartsAndApps(t, valuesFileName, replacements)
247+
internal.WaitForTerminatingPods(t, clientset, internal.Namespace)
248+
internal.ResetLogsSink(t, logsObjectsConsumer)
239249
pods := listPodsInNamespace(t, internal.Namespace)
240250
assert.Len(t, pods.Items, 1)
241251
assert.True(t, strings.HasPrefix(pods.Items[0].Name, "sock-splunk-otel-collector-agent"))
242252
internal.CheckNoEventsReceived(t, logsObjectsConsumer)
243253
})
244254

245255
t.Run("check cluster receiver enabled", func(t *testing.T) {
246-
internal.ResetLogsSink(t, logsObjectsConsumer)
247256
replacements := map[string]interface{}{
248257
"ClusterReceiverEnabled": true,
249258
"LogObjectsHecEndpoint": logsObjectsHecEndpoint,
250259
}
251260
deployChartsAndApps(t, valuesFileName, replacements)
261+
internal.WaitForTerminatingPods(t, clientset, internal.Namespace)
252262
internal.ResetLogsSink(t, logsObjectsConsumer)
253263
pods := listPodsInNamespace(t, internal.Namespace)
254264
assert.Len(t, pods.Items, 2)

functional_tests/internal/common.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,23 @@ func AnnotateNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key,
178178
_, err = clientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{})
179179
require.NoError(t, err)
180180
}
181+
182+
func WaitForTerminatingPods(t *testing.T, clientset *kubernetes.Clientset, namespace string) {
183+
require.Eventually(t, func() bool {
184+
pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
185+
require.NoError(t, err)
186+
187+
terminatingPods := 0
188+
for _, pod := range pods.Items {
189+
if pod.Status.Phase == v1.PodRunning || pod.Status.Phase == v1.PodPending {
190+
continue
191+
}
192+
// Check if the pod is terminating
193+
if pod.DeletionTimestamp != nil {
194+
terminatingPods++
195+
}
196+
}
197+
198+
return terminatingPods == 0
199+
}, 2*time.Minute, 5*time.Second, "there are still terminating pods after 2 minutes")
200+
}

0 commit comments

Comments
 (0)