Skip to content

Commit b71075e

Browse files
committed
Remove scaffold code from operator-sdk init
This code was generated as part of the scaffold when using the sdk. This code was intended to mitigate a user error observed when using "operator-sdk up local" cmd. See operator-framework/operator-sdk#2190 for more information. We do not longer need this code. The metrics endpoint for prometheus is initialized by controller-runtime in the background. Signed-off-by: Matthias Diester <matthias.diester@de.ibm.com>
1 parent 4827ba7 commit b71075e

File tree

32 files changed

+7
-6013
lines changed

32 files changed

+7
-6013
lines changed

cmd/manager/main.go

+3-75
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@ package main
66

77
import (
88
"context"
9-
"errors"
109
"flag"
1110
"fmt"
1211
"os"
1312
"runtime"
1413

15-
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
16-
kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics"
17-
1814
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
19-
"github.com/operator-framework/operator-sdk/pkg/metrics"
15+
2016
"github.com/operator-framework/operator-sdk/pkg/ready"
2117
sdkVersion "github.com/operator-framework/operator-sdk/version"
2218
"github.com/spf13/pflag"
2319

24-
v1 "k8s.io/api/core/v1"
25-
"k8s.io/apimachinery/pkg/util/intstr"
2620
_ "k8s.io/client-go/plugin/pkg/client/auth"
27-
"k8s.io/client-go/rest"
2821
"sigs.k8s.io/controller-runtime/pkg/client/config"
2922
"sigs.k8s.io/controller-runtime/pkg/manager"
3023
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3124

32-
"github.com/shipwright-io/build/pkg/apis"
3325
buildconfig "github.com/shipwright-io/build/pkg/config"
3426
"github.com/shipwright-io/build/pkg/controller"
3527
"github.com/shipwright-io/build/pkg/ctxlog"
@@ -39,9 +31,8 @@ import (
3931

4032
// Change below variables to serve metrics on different host or port.
4133
var (
42-
metricsHost = "0.0.0.0"
43-
metricsPort int32 = 8383
44-
operatorMetricsPort int32 = 8686
34+
metricsHost = "0.0.0.0"
35+
metricsPort int32 = 8383
4536
)
4637

4738
func printVersion(ctx context.Context) {
@@ -77,12 +68,6 @@ func main() {
7768

7869
printVersion(ctx)
7970

80-
namespace, err := k8sutil.GetWatchNamespace()
81-
if err != nil {
82-
ctxlog.Error(ctx, err, "Failed to get watch namespace")
83-
os.Exit(1)
84-
}
85-
8671
// Get a config to talk to the apiserver
8772
cfg, err := config.GetConfig()
8873
if err != nil {
@@ -119,8 +104,6 @@ func main() {
119104
os.Exit(1)
120105
}
121106

122-
// Add the Metrics Service
123-
addMetrics(ctx, cfg, namespace)
124107
buildMetrics.InitPrometheus(buildCfg)
125108

126109
// Add optionally configured extra handlers to metrics endpoint
@@ -139,58 +122,3 @@ func main() {
139122
os.Exit(1)
140123
}
141124
}
142-
143-
// addMetrics will create the Services and Service Monitors to allow the operator export the metrics by using
144-
// the Prometheus operator
145-
func addMetrics(ctx context.Context, cfg *rest.Config, namespace string) {
146-
if err := serveCRMetrics(cfg); err != nil {
147-
if errors.Is(err, k8sutil.ErrRunLocal) {
148-
ctxlog.Info(ctx, "Skipping CR metrics server creation; not running in a cluster.")
149-
return
150-
}
151-
ctxlog.Info(ctx, "Could not generate and serve custom resource metrics", "error", err.Error())
152-
}
153-
154-
// Add to the below struct any other metrics ports you want to expose.
155-
servicePorts := []v1.ServicePort{
156-
{Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}},
157-
{Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}},
158-
}
159-
160-
// Create Service object to expose the metrics port(s).
161-
service, err := metrics.CreateMetricsService(ctx, cfg, servicePorts)
162-
if err != nil {
163-
ctxlog.Info(ctx, "Could not create metrics Service", "error", err.Error())
164-
}
165-
166-
// CreateServiceMonitors will automatically create the prometheus-operator ServiceMonitor resources
167-
// necessary to configure Prometheus to scrape metrics from this operator.
168-
services := []*v1.Service{service}
169-
_, err = metrics.CreateServiceMonitors(cfg, namespace, services)
170-
if err != nil {
171-
ctxlog.Info(ctx, "Could not create ServiceMonitor object", "error", err.Error())
172-
// If this operator is deployed to a cluster without the prometheus-operator running, it will return
173-
// ErrServiceMonitorNotPresent, which can be used to safely skip ServiceMonitor creation.
174-
if err == metrics.ErrServiceMonitorNotPresent {
175-
ctxlog.Info(ctx, "Install prometheus-operator in your cluster to create ServiceMonitor objects", "error", err.Error())
176-
}
177-
}
178-
}
179-
180-
// serveCRMetrics gets the Operator/CustomResource GVKs and generates metrics based on those types.
181-
// It serves those metrics on "http://metricsHost:operatorMetricsPort".
182-
func serveCRMetrics(cfg *rest.Config) error {
183-
// Below function returns filtered operator/CustomResource specific GVKs.
184-
// For more control override the below GVK list with your own custom logic.
185-
filteredGVK, err := k8sutil.GetGVKsFromAddToScheme(apis.AddToScheme)
186-
if err != nil {
187-
return err
188-
}
189-
ns := []string{""}
190-
// Generate and serve custom resource specific metrics.
191-
err = kubemetrics.GenerateAndServeCRMetrics(cfg, ns, filteredGVK, metricsHost, operatorMetricsPort)
192-
if err != nil {
193-
return err
194-
}
195-
return nil
196-
}

vendor/github.com/coreos/prometheus-operator/LICENSE

-202
This file was deleted.

vendor/github.com/coreos/prometheus-operator/NOTICE

-5
This file was deleted.

vendor/github.com/coreos/prometheus-operator/pkg/apis/monitoring/register.go

-19
This file was deleted.

vendor/github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1/doc.go

-18
This file was deleted.

0 commit comments

Comments
 (0)