Skip to content

Commit cbdeaa4

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 c8cd368 commit cbdeaa4

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/lifecycle/lifecycle_test.go

Lines changed: 37 additions & 1 deletion
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
},
@@ -134,6 +133,9 @@ func TestLifecycle(t *testing.T) {
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,37 @@ 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+
// Check Metrics Proxy DaemonSet is in desired state.
846+
mds := &appsv1.DaemonSet{}
847+
mdsKey := types.NamespacedName{Name: internal.BpfmanMetricsProxyDsName, Namespace: internal.BpfmanNamespace}
848+
if err := runtimeClient.Get(ctx, mdsKey, mds); err != nil && errors.IsNotFound(err) || mds.Status.NumberAvailable == 0 {
849+
return nil
850+
} else if err != nil {
851+
return err
852+
}
853+
// Check that the metrics proxy DaemonSet has the health probe bind address argument.
854+
if !podHasContainerArg(mds, arg) {
855+
return fmt.Errorf("metrics proxy DaemonSet missing argement %q", arg)
856+
}
857+
858+
return nil
859+
}

0 commit comments

Comments
 (0)