@@ -6,34 +6,72 @@ import (
6
6
"testing"
7
7
8
8
log "github.com/sirupsen/logrus"
9
+ "github.com/stretchr/testify/require"
9
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
11
"k8s.io/apimachinery/pkg/util/net"
11
12
13
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
14
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
12
15
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
13
16
)
14
17
15
18
// TestMetrics tests the metrics endpoint of the OLM pod.
16
19
func TestMetricsEndpoint (t * testing.T ) {
17
20
c := newKubeClient (t )
21
+ crc := newCRClient (t )
18
22
23
+ failingCSV := v1alpha1.ClusterServiceVersion {
24
+ TypeMeta : metav1.TypeMeta {
25
+ Kind : v1alpha1 .ClusterServiceVersionKind ,
26
+ APIVersion : v1alpha1 .ClusterServiceVersionAPIVersion ,
27
+ },
28
+ ObjectMeta : metav1.ObjectMeta {
29
+ Name : genName ("failing-csv-test-" ),
30
+ },
31
+ Spec : v1alpha1.ClusterServiceVersionSpec {
32
+ InstallStrategy : v1alpha1.NamedInstallStrategy {
33
+ StrategyName : install .InstallStrategyNameDeployment ,
34
+ StrategySpecRaw : strategyRaw ,
35
+ },
36
+ },
37
+ }
38
+
39
+ cleanupCSV , err := createCSV (t , c , crc , failingCSV , testNamespace , false , false )
40
+ require .NoError (t , err )
41
+ defer cleanupCSV ()
42
+
43
+ _ , err = fetchCSV (t , crc , failingCSV .Name , testNamespace , csvFailedChecker )
44
+ require .NoError (t , err )
45
+
46
+ rawOutput , err := getMetricsFromPod (t , c , getOLMPodName (t , c ), operatorNamespace , "8081" )
47
+ if err != nil {
48
+ t .Fatalf ("Metrics test failed: %v\n " , err )
49
+ }
50
+
51
+ // Verify metrics have been emitted for packageserver csv
52
+ require .Contains (t , rawOutput , "csv_sync_total" )
53
+ require .Contains (t , rawOutput , "name=\" " + failingCSV .Name + "\" " )
54
+ require .Contains (t , rawOutput , "phase=\" Failed\" " )
55
+ require .Contains (t , rawOutput , "reason=\" UnsupportedOperatorGroup\" " )
56
+ require .Contains (t , rawOutput , "version=\" 0.0.0\" " )
57
+ log .Info (rawOutput )
58
+ }
59
+
60
+ func getOLMPodName (t * testing.T , client operatorclient.ClientInterface ) string {
19
61
listOptions := metav1.ListOptions {LabelSelector : "app=olm-operator" }
20
- podList , err := c .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (listOptions )
62
+ podList , err := client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (listOptions )
21
63
if err != nil {
22
64
log .Infof ("Error %v\n " , err )
23
65
t .Fatalf ("Listing pods failed: %v\n " , err )
24
66
}
25
- if len (podList .Items ) > 1 {
26
- t .Fatalf ("Expected only 1 olm-operator pod, got %v" , len (podList .Items ))
67
+ if len (podList .Items ) != 1 {
68
+ t .Fatalf ("Expected 1 olm-operator pod, got %v" , len (podList .Items ))
27
69
}
28
70
29
71
podName := podList .Items [0 ].GetName ()
30
72
log .Infof ("Looking at pod %v in namespace %v" , podName , operatorNamespace )
73
+ return podName
31
74
32
- rawOutput , err := getMetricsFromPod (t , c , podName , operatorNamespace , "8081" )
33
- if err != nil {
34
- t .Fatalf ("Metrics test failed: %v\n " , err )
35
- }
36
- log .Info (rawOutput )
37
75
}
38
76
39
77
func getMetricsFromPod (t * testing.T , client operatorclient.ClientInterface , podName string , namespace string , port string ) (string , error ) {
0 commit comments