@@ -171,97 +171,97 @@ var _ = Describe("Manager", Ordered, func() {
171171 Eventually (verifyControllerUp ).Should (Succeed ())
172172 })
173173
174- // It("should ensure the metrics endpoint is serving metrics", func() {
175- // By("creating a ClusterRoleBinding for the service account to allow access to metrics")
176- //
177- // cmd := exec.Command("kubectl", "create", "clusterrolebinding", metricsRoleBindingName,
178- // "--clusterrole=mapserver-operator-metrics-reader",
179- // fmt.Sprintf("--serviceaccount=%s:%s", namespace, serviceAccountName),
180- // )
181- // _, err := utils.Run(cmd)
182- // Expect(err).NotTo(HaveOccurred(), "Failed to create ClusterRoleBinding")
183- //
184- // By("validating that the metrics service is available")
185- // cmd = exec.Command("kubectl", "get", "service", metricsServiceName, "-n", namespace)
186- // _, err = utils.Run(cmd)
187- // Expect(err).NotTo(HaveOccurred(), "Metrics service should exist")
188- //
189- // By("validating that the ServiceMonitor for Prometheus is applied in the namespace")
190- // cmd = exec.Command("kubectl", "get", "ServiceMonitor", "-n", namespace)
191- // _, err = utils.Run(cmd)
192- // Expect(err).NotTo(HaveOccurred(), "ServiceMonitor should exist")
193- //
194- // By("getting the service account token")
195- // token, err := serviceAccountToken()
196- // Expect(err).NotTo(HaveOccurred())
197- // Expect(token).NotTo(BeEmpty())
198- //
199- // By("waiting for the metrics endpoint to be ready")
200- // verifyMetricsEndpointReady := func(g Gomega) {
201- // cmd := exec.Command("kubectl", "get", "endpoints", metricsServiceName, "-n", namespace)
202- // output, err := utils.Run(cmd)
203- // g.Expect(err).NotTo(HaveOccurred())
204- // g.Expect(output).To(ContainSubstring("8443 "), "Metrics endpoint is not ready")
205- // }
206- // Eventually(verifyMetricsEndpointReady).Should(Succeed())
207- //
208- // By("verifying that the controller manager is serving the metrics server")
209- // verifyMetricsServerStarted := func(g Gomega) {
210- // cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
211- // output, err := utils.Run(cmd)
212- // g.Expect(err).NotTo(HaveOccurred())
213- // g.Expect(output).To(ContainSubstring("Serving metrics server"),
214- // "Metrics server not yet started")
215- // }
216- // Eventually(verifyMetricsServerStarted).Should(Succeed())
217- //
218- // By("creating the curl-metrics pod to access the metrics endpoint")
219- // cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
220- // "--namespace", namespace,
221- // "--image=curlimages/curl:latest",
222- // "--overrides",
223- // fmt.Sprintf(`{
224- // "spec": {
225- // "containers": [{
226- // "name": "curl",
227- // "image": "curlimages/curl:latest",
228- // "command": ["/bin/sh", "-c"],
229- // "args": ["curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics"],
230- // "securityContext": {
231- // "allowPrivilegeEscalation": false,
232- // "capabilities": {
233- // "drop": ["ALL"]
234- // },
235- // "runAsNonRoot": true,
236- // "runAsUser": 1000,
237- // "seccompProfile": {
238- // "type": "RuntimeDefault"
239- // }
240- // }
241- // }],
242- // "serviceAccount": "%s"
243- // }
244- // }`, token, metricsServiceName, namespace, serviceAccountName))
245- // _, err = utils.Run(cmd)
246- // Expect(err).NotTo(HaveOccurred(), "Failed to create curl-metrics pod")
247- //
248- // By("waiting for the curl-metrics pod to complete.")
249- // verifyCurlUp := func(g Gomega) {
250- // cmd := exec.Command("kubectl", "get", "pods", "curl-metrics",
251- // "-o", "jsonpath={.status.phase}",
252- // "-n", namespace)
253- // output, err := utils.Run(cmd)
254- // g.Expect(err).NotTo(HaveOccurred())
255- // g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status")
256- // }
257- // Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
258- //
259- // By("getting the metrics by checking curl-metrics logs")
260- // metricsOutput := getMetricsOutput()
261- // Expect(metricsOutput).To(ContainSubstring(
262- // "controller_runtime_reconcile_total",
263- // ))
264- // })
174+ It ("should ensure the metrics endpoint is serving metrics" , func () {
175+ By ("creating a ClusterRoleBinding for the service account to allow access to metrics" )
176+
177+ cmd := exec .Command ("kubectl" , "create" , "clusterrolebinding" , metricsRoleBindingName ,
178+ "--clusterrole=mapserver-operator-metrics-reader" ,
179+ fmt .Sprintf ("--serviceaccount=%s:%s" , namespace , serviceAccountName ),
180+ )
181+ _ , err := utils .Run (cmd )
182+ Expect (err ).NotTo (HaveOccurred (), "Failed to create ClusterRoleBinding" )
183+
184+ By ("validating that the metrics service is available" )
185+ cmd = exec .Command ("kubectl" , "get" , "service" , metricsServiceName , "-n" , namespace )
186+ _ , err = utils .Run (cmd )
187+ Expect (err ).NotTo (HaveOccurred (), "Metrics service should exist" )
188+
189+ By ("validating that the ServiceMonitor for Prometheus is applied in the namespace" )
190+ cmd = exec .Command ("kubectl" , "get" , "ServiceMonitor" , "-n" , namespace )
191+ _ , err = utils .Run (cmd )
192+ Expect (err ).NotTo (HaveOccurred (), "ServiceMonitor should exist" )
193+
194+ By ("getting the service account token" )
195+ token , err := serviceAccountToken ()
196+ Expect (err ).NotTo (HaveOccurred ())
197+ Expect (token ).NotTo (BeEmpty ())
198+
199+ By ("waiting for the metrics endpoint to be ready" )
200+ verifyMetricsEndpointReady := func (g Gomega ) {
201+ cmd := exec .Command ("kubectl" , "get" , "endpoints" , metricsServiceName , "-n" , namespace )
202+ output , err := utils .Run (cmd )
203+ g .Expect (err ).NotTo (HaveOccurred ())
204+ g .Expect (output ).To (ContainSubstring ("8080 " ), "Metrics endpoint is not ready" )
205+ }
206+ Eventually (verifyMetricsEndpointReady ).Should (Succeed ())
207+
208+ By ("verifying that the controller manager is serving the metrics server" )
209+ verifyMetricsServerStarted := func (g Gomega ) {
210+ cmd := exec .Command ("kubectl" , "logs" , controllerPodName , "-n" , namespace )
211+ output , err := utils .Run (cmd )
212+ g .Expect (err ).NotTo (HaveOccurred ())
213+ g .Expect (output ).To (ContainSubstring ("Serving metrics server" ),
214+ "Metrics server not yet started" )
215+ }
216+ Eventually (verifyMetricsServerStarted ).Should (Succeed ())
217+
218+ By ("creating the curl-metrics pod to access the metrics endpoint" )
219+ cmd = exec .Command ("kubectl" , "run" , "curl-metrics" , "--restart=Never" ,
220+ "--namespace" , namespace ,
221+ "--image=curlimages/curl:latest" ,
222+ "--overrides" ,
223+ fmt .Sprintf (`{
224+ "spec": {
225+ "containers": [{
226+ "name": "curl",
227+ "image": "curlimages/curl:latest",
228+ "command": ["/bin/sh", "-c"],
229+ "args": ["curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics"],
230+ "securityContext": {
231+ "allowPrivilegeEscalation": false,
232+ "capabilities": {
233+ "drop": ["ALL"]
234+ },
235+ "runAsNonRoot": true,
236+ "runAsUser": 1000,
237+ "seccompProfile": {
238+ "type": "RuntimeDefault"
239+ }
240+ }
241+ }],
242+ "serviceAccount": "%s"
243+ }
244+ }` , token , metricsServiceName , namespace , serviceAccountName ))
245+ _ , err = utils .Run (cmd )
246+ Expect (err ).NotTo (HaveOccurred (), "Failed to create curl-metrics pod" )
247+
248+ By ("waiting for the curl-metrics pod to complete." )
249+ verifyCurlUp := func (g Gomega ) {
250+ cmd := exec .Command ("kubectl" , "get" , "pods" , "curl-metrics" ,
251+ "-o" , "jsonpath={.status.phase}" ,
252+ "-n" , namespace )
253+ output , err := utils .Run (cmd )
254+ g .Expect (err ).NotTo (HaveOccurred ())
255+ g .Expect (output ).To (Equal ("Succeeded" ), "curl pod in wrong status" )
256+ }
257+ Eventually (verifyCurlUp , 5 * time .Minute ).Should (Succeed ())
258+
259+ By ("getting the metrics by checking curl-metrics logs" )
260+ metricsOutput := getMetricsOutput ()
261+ Expect (metricsOutput ).To (ContainSubstring (
262+ "controller_runtime_reconcile_total" ,
263+ ))
264+ })
265265
266266 //It("should provisioned cert-manager", func() {
267267 // By("validating that cert-manager has the certificate Secret")
0 commit comments