@@ -72,6 +72,10 @@ import (
72
72
//
73
73
// All other feature gate combinations should be invalid.
74
74
75
+ const (
76
+ controllerSELinuxMetricName = "selinux_warning_controller_selinux_volume_conflict"
77
+ )
78
+
75
79
var (
76
80
defaultSELinuxLabels = map [string ]struct { defaultProcessLabel , defaultFileLabel string }{
77
81
"debian" : {"svirt_lxc_net_t" , "svirt_lxc_file_t" },
@@ -713,13 +717,13 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics and SELinuxWarningC
713
717
// We don't need to compare the initial and final KCM metrics,
714
718
// KCM metrics report exact pod namespaces+names as labels and the metric value is always "1".
715
719
err = waitForControllerMetric (ctx , grabber , f .Namespace .Name , pod .Name , pod2 .Name , t .expectControllerConflictProperty , framework .PodStartShortTimeout )
716
- framework .ExpectNoError (err , "failed to get metrics from KCM" )
720
+ framework .ExpectNoError (err , "while waiting for metrics from KCM" )
717
721
// Check the controler generated a conflict event on the first pod
718
722
err = waitForConflictEvent (ctx , m .cs , pod , pod2 , t .expectControllerConflictProperty , f .Timeouts .PodStart )
719
- framework .ExpectNoError (err , "failed to receive event on the first pod" )
723
+ framework .ExpectNoError (err , "while waiting for an event on the first pod" )
720
724
// Check the controler generated event on the second pod
721
725
err = waitForConflictEvent (ctx , m .cs , pod2 , pod , t .expectControllerConflictProperty , f .Timeouts .PodStart )
722
- framework .ExpectNoError (err , "failed to receive event on the second pod" )
726
+ framework .ExpectNoError (err , "while waiting for an event on the second pod" )
723
727
}
724
728
}
725
729
// t.testTags is array and it's not possible to use It("name", func(){xxx}, t.testTags...)
@@ -778,7 +782,7 @@ func grabKCMSELinuxMetrics(ctx context.Context, grabber *e2emetrics.Grabber, nam
778
782
for i := range samples {
779
783
// E.g. "selinux_warning_controller_selinux_volume_conflict"
780
784
metricName := samples [i ].Metric [testutil .MetricNameLabel ]
781
- if metricName != "selinux_warning_controller_selinux_volume_conflict" {
785
+ if metricName != controllerSELinuxMetricName {
782
786
continue
783
787
}
784
788
@@ -836,7 +840,6 @@ func waitForNodeMetricIncrease(ctx context.Context, grabber *e2emetrics.Grabber,
836
840
}
837
841
838
842
func waitForControllerMetric (ctx context.Context , grabber * e2emetrics.Grabber , namespace , pod1Name , pod2Name , propertyName string , timeout time.Duration ) error {
839
- var noIncreaseMetrics sets.Set [string ]
840
843
var metrics map [string ]float64
841
844
842
845
expectLabels := []string {
@@ -846,6 +849,8 @@ func waitForControllerMetric(ctx context.Context, grabber *e2emetrics.Grabber, n
846
849
fmt .Sprintf ("pod2_namespace=%q" , namespace ),
847
850
fmt .Sprintf ("property=%q" , propertyName ),
848
851
}
852
+ framework .Logf ("Waiting for KCM metric %s{%+v}" , controllerSELinuxMetricName , expectLabels )
853
+
849
854
err := wait .PollUntilContextTimeout (ctx , time .Second , timeout , true , func (ctx context.Context ) (bool , error ) {
850
855
var err error
851
856
metrics , err = grabKCMSELinuxMetrics (ctx , grabber , namespace )
@@ -876,8 +881,8 @@ func waitForControllerMetric(ctx context.Context, grabber *e2emetrics.Grabber, n
876
881
ginkgo .By ("Dumping final KCM metrics" )
877
882
dumpMetrics (metrics )
878
883
879
- if err == context . DeadlineExceeded {
880
- return fmt .Errorf ("timed out waiting for KCM metrics %v " , noIncreaseMetrics . UnsortedList () )
884
+ if err != nil {
885
+ return fmt .Errorf ("error waiting for KCM metrics %s{%+v}: %w " , controllerSELinuxMetricName , expectLabels , err )
881
886
}
882
887
return err
883
888
}
0 commit comments