Skip to content

Commit e5988c5

Browse files
committed
fix the bad stuff
1 parent 33c0864 commit e5988c5

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: resolves a problem for trying to use a scheme that isn't present.
9+
10+
# One or more tracking issues related to the change
11+
issues: [2180]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

controllers/opentelemetrycollector_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
4040
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
4141
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
42+
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
4243
"github.com/open-telemetry/opentelemetry-operator/internal/config"
4344
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
4445
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
@@ -80,7 +81,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont
8081
for i := range hpaList.Items {
8182
ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i]
8283
}
83-
if featuregate.PrometheusOperatorIsAvailable.IsEnabled() {
84+
if featuregate.PrometheusOperatorIsAvailable.IsEnabled() && r.config.PrometheusCRAvailability() == prometheus.Available {
8485
servicemonitorList := &monitoringv1.ServiceMonitorList{}
8586
err = r.List(ctx, servicemonitorList, listOps)
8687
if err != nil {
@@ -249,7 +250,7 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er
249250
builder.Owns(&rbacv1.ClusterRole{})
250251
}
251252

252-
if featuregate.PrometheusOperatorIsAvailable.IsEnabled() {
253+
if featuregate.PrometheusOperatorIsAvailable.IsEnabled() && r.config.PrometheusCRAvailability() == prometheus.Available {
253254
builder.Owns(&monitoringv1.ServiceMonitor{})
254255
builder.Owns(&monitoringv1.PodMonitor{})
255256
}

internal/autodetect/prometheus/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package prometheus
1616

17-
// Availability represents what CRDs are available from the prometheus operator
17+
// Availability represents what CRDs are available from the prometheus operator.
1818
type Availability int
1919

2020
const (

main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import (
4848
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
4949
"github.com/open-telemetry/opentelemetry-operator/controllers"
5050
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
51+
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
52+
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
5153
"github.com/open-telemetry/opentelemetry-operator/internal/config"
5254
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
5355
"github.com/open-telemetry/opentelemetry-operator/internal/version"
@@ -76,15 +78,6 @@ func init() {
7678
utilruntime.Must(otelv1alpha1.AddToScheme(scheme))
7779
utilruntime.Must(networkingv1.AddToScheme(scheme))
7880
// +kubebuilder:scaffold:scheme
79-
// accept errors for the following custom resources:
80-
err := monitoringv1.AddToScheme(scheme)
81-
if err != nil {
82-
setupLog.Error(err, "failed to add prometheus CRDs")
83-
}
84-
err = routev1.Install(scheme)
85-
if err != nil {
86-
setupLog.Error(err, "failed to add openshift CRDs")
87-
}
8881
}
8982

9083
// stringFlagOrEnv defines a string flag which can be set by an environment variable.
@@ -229,6 +222,13 @@ func main() {
229222
if err != nil {
230223
setupLog.Error(err, "failed to autodetect config variables")
231224
}
225+
// Only add these to the scheme if they are available
226+
if cfg.PrometheusCRAvailability() == prometheus.Available {
227+
utilruntime.Must(monitoringv1.AddToScheme(scheme))
228+
}
229+
if cfg.OpenShiftRoutesAvailability() == openshift.RoutesAvailable {
230+
utilruntime.Must(routev1.Install(scheme))
231+
}
232232

233233
var namespaces map[string]cache.Config
234234
watchNamespace, found := os.LookupEnv("WATCH_NAMESPACE")

0 commit comments

Comments
 (0)