From 5c61e4e0d9c82687613cc08c6fde8b2274a6d36e Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Tue, 28 May 2019 17:03:53 +0200 Subject: [PATCH] Create metrics service only when running in k8s cluster (#444) * Create metrics service only when running in k8s cluster Signed-off-by: Pavol Loffay * use if style Signed-off-by: Pavol Loffay --- pkg/cmd/start/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/start/main.go b/pkg/cmd/start/main.go index bb9a4ca23..ccd5d84d2 100644 --- a/pkg/cmd/start/main.go +++ b/pkg/cmd/start/main.go @@ -182,11 +182,13 @@ func start(cmd *cobra.Command, args []string) { } // Create Service object to expose the metrics port. - var operatorService *corev1.Service - if operatorService, err = metrics.ExposeMetricsPort(ctx, viper.GetInt32("metrics-port")); err != nil { - log.Fatal(err) - } else if err = setOwnerReference(operatorService); err != nil { + operatorService, err := metrics.ExposeMetricsPort(ctx, viper.GetInt32("metrics-port")) + if err != nil { log.Fatal(err) + } else if operatorService != nil { + if err := setOwnerReference(operatorService); err != nil { + log.Fatal(err) + } } // Start the Cmd