Skip to content

Commit 296bca9

Browse files
committed
Add lifecycle test validation for Config default values
Add checkResourcesInDesiredState() function to verify that the default health probe port (8175) is correctly applied to bpfman and metrics proxy DaemonSets when not explicitly set in the Config spec. This test ensures the default value handling introduced in the API standards compliance changes works correctly at runtime. Signed-off-by: Andreas Karis <[email protected]>
1 parent e606c8e commit 296bca9

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/lifecycle/lifecycle_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ millisec_delay = 10000
6060
allow_unsigned = true
6161
verify_enabled = true`,
6262
Agent: v1alpha1.AgentSpec{
63-
HealthProbePort: 8175,
6463
Image: "quay.io/bpfman/bpfman-agent:latest",
6564
LogLevel: "debug", // Changed from info to debug
6665
},
@@ -127,13 +126,16 @@ func TestLifecycle(t *testing.T) {
127126
}()
128127

129128
// Make sure that all resources are there at the start.
130-
t.Logf("Running: waitForResourceCreation and waitForAvailable")
129+
t.Logf("Running: waitForResourceCreation, waitForAvailable and checkResourcesInDesiredState")
131130
if err := waitForResourceCreation(ctx); err != nil {
132131
t.Fatalf("Failed to ensure resources: %q", err)
133132
}
134133
if err := waitForAvailable(ctx, isOpenShift); err != nil {
135134
t.Fatalf("Config never reported status available: %q", err)
136135
}
136+
if err := checkResourcesInDesiredState(ctx); err != nil {
137+
t.Fatalf("Failed to ensure resources: %q", err)
138+
}
137139

138140
// Test deleting resources.
139141
t.Logf("Running: TestResourceDeletion")
@@ -821,3 +823,25 @@ func waitForAvailable(ctx context.Context, isOpenShift bool) error {
821823
return componentsReady, nil
822824
})
823825
}
826+
827+
// checkResourcesInDesiredState makes sure that all resources are in the desired state.
828+
// Right now, the only implemented validation in this function is a check for the health probe port.
829+
// Returns error if timeout is reached or if context is cancelled.
830+
func checkResourcesInDesiredState(ctx context.Context) error {
831+
// Check DaemonSet is in desired state.
832+
ds := &appsv1.DaemonSet{}
833+
dsKey := types.NamespacedName{Name: internal.BpfmanDsName, Namespace: internal.BpfmanNamespace}
834+
if err := runtimeClient.Get(ctx, dsKey, ds); err != nil && errors.IsNotFound(err) || ds.Status.NumberAvailable == 0 {
835+
return nil
836+
} else if err != nil {
837+
return err
838+
}
839+
840+
arg := "--health-probe-bind-address=:8175"
841+
// Check that the bpfman DaemonSet has the health probe bind address argument.
842+
if !podHasContainerArg(ds, arg) {
843+
return fmt.Errorf("bpfman DaemonSet missing argument %q", arg)
844+
}
845+
846+
return nil
847+
}

0 commit comments

Comments
 (0)