@@ -15,6 +15,7 @@ import (
15
15
. "github.com/onsi/gomega"
16
16
io_prometheus_client "github.com/prometheus/client_model/go"
17
17
"github.com/prometheus/common/expfmt"
18
+ appsv1 "k8s.io/api/apps/v1"
18
19
corev1 "k8s.io/api/core/v1"
19
20
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
20
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -112,6 +113,41 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
112
113
})
113
114
})
114
115
})
116
+
117
+ When ("the OLM pod restars" , func () {
118
+ var (
119
+ cleanupCSV cleanupFunc
120
+ csv v1alpha1.ClusterServiceVersion
121
+ )
122
+ BeforeEach (func () {
123
+ packageName := genName ("csv-test-" )
124
+ packageStable := fmt .Sprintf ("%s-stable" , packageName )
125
+ csv = newCSV (packageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), nil , nil , nil )
126
+
127
+ var err error
128
+ _ , err = createCSV (c , crc , csv , testNamespace , false , false )
129
+ Expect (err ).ToNot (HaveOccurred ())
130
+
131
+ _ , err = fetchCSV (crc , csv .Name , testNamespace , csvSucceededChecker )
132
+ Expect (err ).ToNot (HaveOccurred ())
133
+ })
134
+ AfterEach (func () {
135
+ if cleanupCSV != nil {
136
+ cleanupCSV ()
137
+ }
138
+ })
139
+ It ("csv metric is preserved" , func () {
140
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8081" )).To (
141
+ ContainElement (LikeMetric (WithFamily ("csv_succeeded" ), WithName (csv .Name ), WithValue (1 ))),
142
+ )
143
+
144
+ restartDeploymentWithLabel (c , "app=olm-operator" )
145
+
146
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8081" )).To (
147
+ ContainElement (LikeMetric (WithFamily ("csv_succeeded" ), WithName (csv .Name ), WithValue (1 ))),
148
+ )
149
+ })
150
+ })
115
151
})
116
152
117
153
Context ("Metrics emitted by objects during operator installation" , func () {
@@ -392,6 +428,51 @@ func getPodWithLabel(client operatorclient.ClientInterface, label string) *corev
392
428
return & podList .Items [0 ]
393
429
}
394
430
431
+ func getDeploymentWithLabel (client operatorclient.ClientInterface , label string ) * appsv1.Deployment {
432
+ listOptions := metav1.ListOptions {LabelSelector : label }
433
+ var deploymentList * appsv1.DeploymentList
434
+ EventuallyWithOffset (1 , func () (numDeps int , err error ) {
435
+ deploymentList , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).List (context .TODO (), listOptions )
436
+ if deploymentList != nil {
437
+ numDeps = len (deploymentList .Items )
438
+ }
439
+
440
+ return
441
+ }).Should (Equal (1 ), "expected exactly one Deployment" )
442
+
443
+ return & deploymentList .Items [0 ]
444
+ }
445
+
446
+ func restartDeploymentWithLabel (client operatorclient.ClientInterface , l string ) {
447
+ d := getDeploymentWithLabel (client , l )
448
+ z := int32 (0 )
449
+ oldZ := * d .Spec .Replicas
450
+ d .Spec .Replicas = & z
451
+ _ , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .TODO (), d , metav1.UpdateOptions {})
452
+ Expect (err ).ToNot (HaveOccurred ())
453
+
454
+ EventuallyWithOffset (1 , func () (replicas int32 , err error ) {
455
+ deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .TODO (), d .Name , metav1.GetOptions {})
456
+ if deployment != nil {
457
+ replicas = deployment .Status .Replicas
458
+ }
459
+ return
460
+ }).Should (Equal (int32 (0 )), "expected exactly 0 Deployments" )
461
+
462
+ updated := getDeploymentWithLabel (client , l )
463
+ updated .Spec .Replicas = & oldZ
464
+ _ , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .TODO (), updated , metav1.UpdateOptions {})
465
+ Expect (err ).ToNot (HaveOccurred ())
466
+
467
+ EventuallyWithOffset (1 , func () (replicas int32 , err error ) {
468
+ deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .TODO (), d .Name , metav1.GetOptions {})
469
+ if deployment != nil {
470
+ replicas = deployment .Status .Replicas
471
+ }
472
+ return
473
+ }).Should (Equal (oldZ ), "expected exactly 1 Deployment" )
474
+ }
475
+
395
476
func getMetricsFromPod (client operatorclient.ClientInterface , pod * corev1.Pod , port string ) []Metric {
396
477
ctx .Ctx ().Logf ("querying pod %s/%s\n " , pod .GetNamespace (), pod .GetName ())
397
478
0 commit comments