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

Fix flaky controller test for versioned ConfigMaps #3564

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
18 changes: 10 additions & 8 deletions controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ func TestOpenTelemetryCollectorReconciler_VersionedConfigMaps(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1beta1.OpenTelemetryCollectorSpec{
OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{
PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{},
},
Comment on lines +861 to +863
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to avoid logs about the default being set. We should really get rid of that log line imo.

ConfigVersions: 1,
TargetAllocator: v1beta1.TargetAllocatorEmbedded{
Enabled: true,
Expand Down Expand Up @@ -937,6 +940,8 @@ func TestOpenTelemetryCollectorReconciler_VersionedConfigMaps(t *testing.T) {
}, time.Second*5, time.Millisecond)

// modify the ConfigMap, it should be kept
// wait a second first, as K8s creation timestamps only have second precision
time.Sleep(time.Second)
err = k8sClient.Get(clientCtx, nsn, collector)
require.NoError(t, err)
collector.Spec.Config.Exporters.Object["debug"] = map[string]interface{}{}
Expand All @@ -961,6 +966,8 @@ func TestOpenTelemetryCollectorReconciler_VersionedConfigMaps(t *testing.T) {
}, time.Second*5, time.Millisecond)

// modify the ConfigMap again, the oldest one is still kept, but is dropped after next reconciliation
// wait a second first, as K8s creation timestamps only have second precision
time.Sleep(time.Second)
err = k8sClient.Get(clientCtx, nsn, collector)
require.NoError(t, err)
collector.Spec.Config.Exporters.Object["debug/2"] = map[string]interface{}{}
Expand All @@ -978,8 +985,7 @@ func TestOpenTelemetryCollectorReconciler_VersionedConfigMaps(t *testing.T) {

assert.EventuallyWithT(t, func(collect *assert.CollectT) {
configMaps := &v1.ConfigMapList{}
// use the reconciler client here to ensure it sees the new ConfigMap, before running the next reconciliation
listErr := reconciler.Client.List(clientCtx, configMaps, opts...)
listErr := k8sClient.List(clientCtx, configMaps, opts...)
assert.NoError(collect, listErr)
assert.NotEmpty(collect, configMaps)
assert.Len(collect, configMaps.Items, 4)
Expand All @@ -993,12 +999,8 @@ func TestOpenTelemetryCollectorReconciler_VersionedConfigMaps(t *testing.T) {
listErr := k8sClient.List(clientCtx, configMaps, opts...)
assert.NoError(collect, listErr)
assert.NotEmpty(collect, configMaps)
// actual deletion can happen with a delay in a K8s cluster, check the timestamp instead to speed things up
items := slices.DeleteFunc(configMaps.Items, func(item v1.ConfigMap) bool {
return item.DeletionTimestamp != nil
})
assert.Len(collect, items, 3)
}, time.Second*30, time.Second) // not sure why this can take so long to bubble up
assert.Len(collect, configMaps.Items, 3)
}, time.Second*5, time.Second)
}

func TestOpAMPBridgeReconciler_Reconcile(t *testing.T) {
Expand Down
Loading