Skip to content

Commit 9ab245d

Browse files
committed
increase test coverage
1 parent 31dae4d commit 9ab245d

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

api/datadoghq/v2alpha1/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/datadogagent/controller_v2_test.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"fmt"
1111
"reflect"
12+
"slices"
1213
"sort"
1314
"testing"
1415
"time"
@@ -44,6 +45,7 @@ import (
4445
"github.com/DataDog/datadog-operator/pkg/images"
4546
"github.com/DataDog/datadog-operator/pkg/kubernetes"
4647
"github.com/DataDog/datadog-operator/pkg/testutils"
48+
"github.com/DataDog/datadog-operator/pkg/untaint"
4749
pkgutils "github.com/DataDog/datadog-operator/pkg/utils"
4850
)
4951

@@ -61,6 +63,17 @@ type testCase struct {
6163
introspectionEnabled bool // For introspection tests
6264
}
6365

66+
// ddaiReconcilerOptionsFromDDA mirrors setup.go wiring so DDAI tests behave like production
67+
// for flags shared with the DatadogAgent reconciler (e.g. UntaintControllerEnabled).
68+
func ddaiReconcilerOptionsFromDDA(opts ReconcilerOptions) datadogagentinternal.ReconcilerOptions {
69+
return datadogagentinternal.ReconcilerOptions{
70+
ExtendedDaemonsetOptions: opts.ExtendedDaemonsetOptions,
71+
SupportCilium: opts.SupportCilium,
72+
OperatorMetricsEnabled: opts.OperatorMetricsEnabled,
73+
UntaintControllerEnabled: opts.UntaintControllerEnabled,
74+
}
75+
}
76+
6477
// runTestCases runs test cases
6578
func runTestCases(t *testing.T, tests []testCase, testFunc func(t *testing.T, tt testCase, opts ReconcilerOptions)) {
6679
for _, tt := range tests {
@@ -106,7 +119,7 @@ func runDDAReconcilerTest(t *testing.T, tt testCase, opts ReconcilerOptions) {
106119
r.initializeComponentRegistry()
107120

108121
ri := datadogagentinternal.NewReconciler(
109-
datadogagentinternal.ReconcilerOptions{},
122+
ddaiReconcilerOptionsFromDDA(opts),
110123
c,
111124
kubernetes.PlatformInfo{},
112125
s,
@@ -179,7 +192,7 @@ func runFullReconcilerTest(t *testing.T, tt testCase, opts ReconcilerOptions) {
179192
r.initializeComponentRegistry()
180193

181194
ri := datadogagentinternal.NewReconciler(
182-
datadogagentinternal.ReconcilerOptions{},
195+
ddaiReconcilerOptionsFromDDA(opts),
183196
c,
184197
kubernetes.PlatformInfo{},
185198
s,
@@ -248,6 +261,35 @@ func buildClient(t *testing.T, tt testCase, s *runtime.Scheme) client.Client {
248261
return builder.Build()
249262
}
250263

264+
func TestReconcileDDA_UntaintController_injectsAgentNotReadyToleration(t *testing.T) {
265+
const resourcesName = "foo"
266+
const resourcesNamespace = "bar"
267+
const dsName = "foo-agent"
268+
defaultRequeueDuration := 15 * time.Second
269+
270+
wantTol := untaint.AgentNotReadyEqualToleration()
271+
tt := testCase{
272+
name: "untaint controller enabled injects agent-not-ready toleration on node agent DS",
273+
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
274+
dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
275+
Build()
276+
_ = c.Create(context.TODO(), dda)
277+
return dda
278+
},
279+
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
280+
wantErr: false,
281+
wantFunc: func(t *testing.T, c client.Client) {
282+
ds := &appsv1.DaemonSet{}
283+
err := c.Get(context.TODO(), types.NamespacedName{Namespace: resourcesNamespace, Name: dsName}, ds)
284+
assert.NoError(t, err)
285+
assert.True(t, slices.ContainsFunc(ds.Spec.Template.Spec.Tolerations, func(tol corev1.Toleration) bool {
286+
return reflect.DeepEqual(tol, wantTol)
287+
}), "expected injected toleration %+v in %+v", wantTol, ds.Spec.Template.Spec.Tolerations)
288+
},
289+
}
290+
runDDAReconcilerTest(t, tt, ReconcilerOptions{UntaintControllerEnabled: true})
291+
}
292+
251293
func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) {
252294
const resourcesName = "foo"
253295
const resourcesNamespace = "bar"

0 commit comments

Comments
 (0)