Skip to content

Commit

Permalink
Replace ExposeMetricsPort by CreateMetricsService
Browse files Browse the repository at this point in the history
Commit to fix breaking change introduced in operator-sdk v0.9.0:
https://github.com/operator-framework/operator-sdk/blob/master/CHANGELOG.md#v090
Breaking change: ExposeMetricsPort is removed and replaced with
CreateMetricsService() function. PrometheusPortName constant is replaced with
OperatorPortName. (operator-sdk PR #1560)
  • Loading branch information
miguelsorianod committed Feb 17, 2020
1 parent 3b3dc5e commit d8f921d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"runtime"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/3scale/apicast-operator/pkg/apis"
Expand All @@ -28,8 +30,9 @@ import (

// Change below variables to serve metrics on different host or port.
var (
metricsHost = "0.0.0.0"
metricsPort int32 = 8383
metricsHost = "0.0.0.0"
metricsPort int32 = 8383
operatorMetricsPort int32 = 8686
)
var log = logf.Log.WithName("cmd")

Expand Down Expand Up @@ -109,8 +112,14 @@ func main() {
os.Exit(1)
}

// Create Service object to expose the metrics port.
_, err = metrics.ExposeMetricsPort(ctx, metricsPort)
// Add to the below struct any other metrics ports you want to expose.
servicePorts := []v1.ServicePort{
{Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}},
{Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}},
}

// Create Service object to expose the metrics port(s).
_, err = metrics.CreateMetricsService(ctx, cfg, servicePorts)
if err != nil {
log.Info(err.Error())
}
Expand Down

0 comments on commit d8f921d

Please sign in to comment.