Skip to content

Commit 1d9e7dd

Browse files
qu1queeeHeavyWombat
authored andcommitted
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 b61d0a9 commit 1d9e7dd

File tree

32 files changed

+2
-6015
lines changed

32 files changed

+2
-6015
lines changed

cmd/manager/main.go

+2-75
Original file line numberDiff line numberDiff line change
@@ -6,31 +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.)
1915
"github.com/operator-framework/operator-sdk/pkg/log/zap"
20-
"github.com/operator-framework/operator-sdk/pkg/metrics"
2116
"github.com/operator-framework/operator-sdk/pkg/ready"
2217
sdkVersion "github.com/operator-framework/operator-sdk/version"
2318
"github.com/spf13/pflag"
2419

25-
v1 "k8s.io/api/core/v1"
26-
"k8s.io/apimachinery/pkg/util/intstr"
2720
_ "k8s.io/client-go/plugin/pkg/client/auth"
28-
"k8s.io/client-go/rest"
2921
"sigs.k8s.io/controller-runtime/pkg/client/config"
3022
"sigs.k8s.io/controller-runtime/pkg/manager"
3123
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3224

33-
"github.com/shipwright-io/build/pkg/apis"
3425
buildconfig "github.com/shipwright-io/build/pkg/config"
3526
"github.com/shipwright-io/build/pkg/controller"
3627
"github.com/shipwright-io/build/pkg/ctxlog"
@@ -40,9 +31,8 @@ import (
4031

4132
// Change below variables to serve metrics on different host or port.
4233
var (
43-
metricsHost = "0.0.0.0"
44-
metricsPort int32 = 8383
45-
operatorMetricsPort int32 = 8686
34+
metricsHost = "0.0.0.0"
35+
metricsPort int32 = 8383
4636
)
4737

4838
func printVersion(ctx context.Context) {
@@ -78,12 +68,6 @@ func main() {
7868

7969
printVersion(ctx)
8070

81-
namespace, err := k8sutil.GetWatchNamespace()
82-
if err != nil {
83-
ctxlog.Error(ctx, err, "Failed to get watch namespace")
84-
os.Exit(1)
85-
}
86-
8771
// Get a config to talk to the apiserver
8872
cfg, err := config.GetConfig()
8973
if err != nil {
@@ -120,8 +104,6 @@ func main() {
120104
os.Exit(1)
121105
}
122106

123-
// Add the Metrics Service
124-
addMetrics(ctx, cfg, namespace)
125107
buildMetrics.InitPrometheus(buildCfg)
126108

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

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)