Skip to content

Commit 0db30a6

Browse files
Replace ExposeMetricsPort by CreateMetricsService
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)
1 parent 7be6754 commit 0db30a6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cmd/manager/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"runtime"
99

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

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

2931
// Change below variables to serve metrics on different host or port.
3032
var (
31-
metricsHost = "0.0.0.0"
32-
metricsPort int32 = 8383
33+
metricsHost = "0.0.0.0"
34+
metricsPort int32 = 8383
35+
operatorMetricsPort int32 = 8686
3336
)
3437
var log = logf.Log.WithName("cmd")
3538

@@ -109,8 +112,14 @@ func main() {
109112
os.Exit(1)
110113
}
111114

112-
// Create Service object to expose the metrics port.
113-
_, err = metrics.ExposeMetricsPort(ctx, metricsPort)
115+
// Add to the below struct any other metrics ports you want to expose.
116+
servicePorts := []v1.ServicePort{
117+
{Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}},
118+
{Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}},
119+
}
120+
121+
// Create Service object to expose the metrics port(s).
122+
_, err = metrics.CreateMetricsService(ctx, cfg, servicePorts)
114123
if err != nil {
115124
log.Info(err.Error())
116125
}

0 commit comments

Comments
 (0)