@@ -4,12 +4,16 @@ package e2e
4
4
5
5
import (
6
6
"context"
7
+ "fmt"
8
+ "regexp"
9
+
10
+ . "github.com/onsi/ginkgo"
11
+ . "github.com/onsi/gomega"
7
12
log "github.com/sirupsen/logrus"
8
- "github.com/stretchr/testify/require "
13
+ corev1 "k8s.io/api/core/v1 "
9
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
15
"k8s.io/apimachinery/pkg/util/net"
11
16
12
- . "github.com/onsi/ginkgo"
13
17
"github.com/operator-framework/api/pkg/operators/v1alpha1"
14
18
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
15
19
)
@@ -39,64 +43,49 @@ var _ = Describe("Metrics", func() {
39
43
}
40
44
41
45
cleanupCSV , err := createCSV (GinkgoT (), c , crc , failingCSV , testNamespace , false , false )
42
- require . NoError ( GinkgoT (), err )
46
+ Expect ( err ). ToNot ( HaveOccurred () )
43
47
defer cleanupCSV ()
44
48
45
49
_ , err = fetchCSV (GinkgoT (), crc , failingCSV .Name , testNamespace , csvFailedChecker )
46
- require .NoError (GinkgoT (), err )
47
-
48
- rawOutput , err := getMetricsFromPod (GinkgoT (), c , getOLMPodName (GinkgoT (), c ), operatorNamespace , "8081" )
49
- if err != nil {
50
- GinkgoT ().Fatalf ("Metrics test failed: %v\n " , err )
51
- }
50
+ Expect (err ).ToNot (HaveOccurred ())
52
51
53
52
// Verify metrics have been emitted for packageserver csv
54
- require . Contains ( GinkgoT (), rawOutput , "csv_abnormal" )
55
- require . Contains ( GinkgoT (), rawOutput , "name= \" " + failingCSV . Name + " \" " )
56
- require . Contains ( GinkgoT (), rawOutput , "phase =\" Failed \" ")
57
- require . Contains ( GinkgoT (), rawOutput , "reason =\" UnsupportedOperatorGroup \" " )
58
- require . Contains ( GinkgoT (), rawOutput , "version =\" 0.0.0 \" " )
59
-
60
- require . Contains ( GinkgoT (), rawOutput , "csv_succeeded" )
61
- log . Info ( rawOutput )
53
+ Expect ( getMetricsFromPod ( c , getOLMPod ( c ) , "8081" )). To ( And (
54
+ ContainSubstring ( "csv_abnormal" ),
55
+ ContainSubstring ( fmt . Sprintf ( "name =\" %s \" ", failingCSV . Name )),
56
+ ContainSubstring ( "phase =\" Failed \" " ),
57
+ ContainSubstring ( "reason =\" UnsupportedOperatorGroup \" " ),
58
+ ContainSubstring ( "version= \" 0.0.0 \" " ),
59
+ ContainSubstring ( "csv_succeeded" ),
60
+ ) )
62
61
})
63
62
})
64
63
65
- func getOLMPodName ( t GinkgoTInterface , client operatorclient.ClientInterface ) string {
64
+ func getOLMPod ( client operatorclient.ClientInterface ) * corev1. Pod {
66
65
listOptions := metav1.ListOptions {LabelSelector : "app=olm-operator" }
67
- podList , err := client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (context .TODO (), listOptions )
68
- if err != nil {
69
- log .Infof ("Error %v\n " , err )
70
- t .Fatalf ("Listing pods failed: %v\n " , err )
71
- }
72
- if len (podList .Items ) != 1 {
73
- t .Fatalf ("Expected 1 olm-operator pod, got %v" , len (podList .Items ))
74
- }
75
-
76
- podName := podList .Items [0 ].GetName ()
77
- log .Infof ("Looking at pod %v in namespace %v" , podName , operatorNamespace )
78
- return podName
79
-
66
+ var podList * corev1.PodList
67
+ Eventually (func () (err error ) {
68
+ podList , err = client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (context .TODO (), listOptions )
69
+ return
70
+ }).Should (Succeed (), "Failed to list OLM pods" )
71
+ Expect (len (podList .Items )).To (Equal (1 ))
72
+
73
+ return & podList .Items [0 ]
80
74
}
81
75
82
- func getMetricsFromPod (t GinkgoTInterface , client operatorclient.ClientInterface , podName string , namespace string , port string ) (string , error ) {
83
- olmPod , err := client .KubernetesInterface ().CoreV1 ().Pods (namespace ).Get (context .TODO (), podName , metav1.GetOptions {})
84
- if err != nil {
85
- return "" , err
86
- }
87
- if len (olmPod .Spec .Containers ) != 1 {
88
- t .Fatalf ("Expected only 1 container in olm-operator pod, got %v" , len (olmPod .Spec .Containers ))
89
- }
76
+ func getMetricsFromPod (client operatorclient.ClientInterface , pod * corev1.Pod , port string ) string {
77
+ By (fmt .Sprintf ("querying pod %s/%s" , pod .GetNamespace (), pod .GetName ()))
90
78
91
- var foundCert bool
92
- var foundKey bool
93
79
// assuming -tls-cert and -tls-key aren't used anywhere else as a parameter value
94
- for _ , param := range olmPod .Spec .Containers [0 ].Args {
95
- if param == "-tls-cert" {
96
- foundCert = true
97
- } else if param == "-tls-key" {
98
- foundKey = true
99
- }
80
+ var foundCert , foundKey bool
81
+ for _ , arg := range pod .Spec .Containers [0 ].Args {
82
+ matched , err := regexp .MatchString (`^-?-tls-cert` , arg )
83
+ Expect (err ).ToNot (HaveOccurred ())
84
+ foundCert = foundCert || matched
85
+
86
+ matched , err = regexp .MatchString (`^-?-tls-key` , arg )
87
+ Expect (err ).ToNot (HaveOccurred ())
88
+ foundKey = foundKey || matched
100
89
}
101
90
102
91
var scheme string
@@ -107,15 +96,17 @@ func getMetricsFromPod(t GinkgoTInterface, client operatorclient.ClientInterface
107
96
}
108
97
log .Infof ("Retrieving metrics using scheme %v\n " , scheme )
109
98
110
- rawOutput , err := client .KubernetesInterface ().CoreV1 ().RESTClient ().Get ().
111
- Namespace (namespace ).
112
- Resource ("pods" ).
113
- SubResource ("proxy" ).
114
- Name (net .JoinSchemeNamePort (scheme , podName , port )).
115
- Suffix ("metrics" ).
116
- Do (context .TODO ()).Raw ()
117
- if err != nil {
118
- return "" , err
119
- }
120
- return string (rawOutput ), nil
99
+ var raw []byte
100
+ Eventually (func () (err error ) {
101
+ raw , err = client .KubernetesInterface ().CoreV1 ().RESTClient ().Get ().
102
+ Namespace (pod .GetNamespace ()).
103
+ Resource ("pods" ).
104
+ SubResource ("proxy" ).
105
+ Name (net .JoinSchemeNamePort (scheme , pod .GetName (), port )).
106
+ Suffix ("metrics" ).
107
+ Do (context .Background ()).Raw ()
108
+ return
109
+ }).Should (Succeed ())
110
+
111
+ return string (raw )
121
112
}
0 commit comments