@@ -17,8 +17,6 @@ package controllers
17
17
18
18
import (
19
19
"context"
20
- "fmt"
21
- "sync"
22
20
23
21
"github.com/go-logr/logr"
24
22
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
@@ -36,8 +34,6 @@ import (
36
34
"github.com/open-telemetry/opentelemetry-operator/internal/config"
37
35
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
38
36
collectorStatus "github.com/open-telemetry/opentelemetry-operator/internal/status/collector"
39
- "github.com/open-telemetry/opentelemetry-operator/pkg/autodetect"
40
- "github.com/open-telemetry/opentelemetry-operator/pkg/collector/reconcile"
41
37
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
42
38
)
43
39
@@ -48,16 +44,6 @@ type OpenTelemetryCollectorReconciler struct {
48
44
scheme * runtime.Scheme
49
45
log logr.Logger
50
46
config config.Config
51
-
52
- tasks []Task
53
- muTasks sync.RWMutex
54
- }
55
-
56
- // Task represents a reconciliation task to be executed by the reconciler.
57
- type Task struct {
58
- Do func (context.Context , manifests.Params ) error
59
- Name string
60
- BailOnError bool
61
47
}
62
48
63
49
// Params is the set of options to build a new OpenTelemetryCollectorReconciler.
@@ -66,55 +52,9 @@ type Params struct {
66
52
Recorder record.EventRecorder
67
53
Scheme * runtime.Scheme
68
54
Log logr.Logger
69
- Tasks []Task
70
55
Config config.Config
71
56
}
72
57
73
- func (r * OpenTelemetryCollectorReconciler ) onOpenShiftRoutesChange () error {
74
- plt := r .config .OpenShiftRoutes ()
75
- var (
76
- routesIdx = - 1
77
- )
78
- r .muTasks .Lock ()
79
- for i , t := range r .tasks {
80
- // search for route reconciler
81
- switch t .Name {
82
- case "routes" :
83
- routesIdx = i
84
- }
85
- }
86
- r .muTasks .Unlock ()
87
-
88
- if err := r .addRouteTask (plt , routesIdx ); err != nil {
89
- return err
90
- }
91
-
92
- return r .removeRouteTask (plt , routesIdx )
93
- }
94
-
95
- func (r * OpenTelemetryCollectorReconciler ) addRouteTask (ora autodetect.OpenShiftRoutesAvailability , routesIdx int ) error {
96
- r .muTasks .Lock ()
97
- defer r .muTasks .Unlock ()
98
- // if exists and openshift routes are available
99
- if routesIdx == - 1 && ora == autodetect .OpenShiftRoutesAvailable {
100
- r .tasks = append ([]Task {{reconcile .Routes , "routes" , true }}, r .tasks ... )
101
- }
102
- return nil
103
- }
104
-
105
- func (r * OpenTelemetryCollectorReconciler ) removeRouteTask (ora autodetect.OpenShiftRoutesAvailability , routesIdx int ) error {
106
- r .muTasks .Lock ()
107
- defer r .muTasks .Unlock ()
108
- if len (r .tasks ) < routesIdx {
109
- return fmt .Errorf ("can not remove route task from reconciler" )
110
- }
111
- // if exists and openshift routes are not available
112
- if routesIdx != - 1 && ora == autodetect .OpenShiftRoutesNotAvailable {
113
- r .tasks = append (r .tasks [:routesIdx ], r .tasks [routesIdx + 1 :]... )
114
- }
115
- return nil
116
- }
117
-
118
58
func (r * OpenTelemetryCollectorReconciler ) getParams (instance v1alpha1.OpenTelemetryCollector ) manifests.Params {
119
59
return manifests.Params {
120
60
Config : r .config ,
@@ -133,15 +73,8 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
133
73
log : p .Log ,
134
74
scheme : p .Scheme ,
135
75
config : p .Config ,
136
- tasks : p .Tasks ,
137
76
recorder : p .Recorder ,
138
77
}
139
-
140
- if len (r .tasks ) == 0 {
141
- // TODO: put this in line with the rest of how we generate manifests
142
- // https://github.com/open-telemetry/opentelemetry-operator/issues/2108
143
- r .config .RegisterOpenShiftRoutesChangeCallback (r .onOpenShiftRoutesChange )
144
- }
145
78
return r
146
79
}
147
80
@@ -185,9 +118,6 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
185
118
}
186
119
187
120
params := r .getParams (instance )
188
- if err := r .RunTasks (ctx , params ); err != nil {
189
- return ctrl.Result {}, err
190
- }
191
121
192
122
desiredObjects , buildErr := BuildCollector (params )
193
123
if buildErr != nil {
@@ -197,32 +127,8 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
197
127
return collectorStatus .HandleReconcileStatus (ctx , log , params , err )
198
128
}
199
129
200
- // RunTasks runs all the tasks associated with this reconciler.
201
- func (r * OpenTelemetryCollectorReconciler ) RunTasks (ctx context.Context , params manifests.Params ) error {
202
- r .muTasks .RLock ()
203
- defer r .muTasks .RUnlock ()
204
- for _ , task := range r .tasks {
205
- if err := task .Do (ctx , params ); err != nil {
206
- // If we get an error that occurs because a pod is being terminated, then exit this loop
207
- if apierrors .IsForbidden (err ) && apierrors .HasStatusCause (err , corev1 .NamespaceTerminatingCause ) {
208
- r .log .V (2 ).Info ("Exiting reconcile loop because namespace is being terminated" , "namespace" , params .OtelCol .Namespace )
209
- return nil
210
- }
211
- r .log .Error (err , fmt .Sprintf ("failed to reconcile %s" , task .Name ))
212
- if task .BailOnError {
213
- return err
214
- }
215
- }
216
- }
217
- return nil
218
- }
219
-
220
130
// SetupWithManager tells the manager what our controller is interested in.
221
131
func (r * OpenTelemetryCollectorReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
222
- err := r .config .AutoDetect () // We need to call this, so we can get the correct autodetect version
223
- if err != nil {
224
- return err
225
- }
226
132
builder := ctrl .NewControllerManagedBy (mgr ).
227
133
For (& v1alpha1.OpenTelemetryCollector {}).
228
134
Owns (& corev1.ConfigMap {}).
0 commit comments