1
1
package main
2
2
3
3
import (
4
+ "context"
4
5
"flag"
5
6
"fmt"
6
7
"net/http"
@@ -16,7 +17,6 @@ import (
16
17
"k8s.io/client-go/tools/clientcmd"
17
18
18
19
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
19
- "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
20
20
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
21
21
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
22
22
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
@@ -63,7 +63,9 @@ func init() {
63
63
64
64
// main function - entrypoint to OLM operator
65
65
func main () {
66
- stopCh := signals .SetupSignalHandler ()
66
+ // Get exit signal context
67
+ ctx , cancel := context .WithCancel (signals .Context ())
68
+ defer cancel ()
67
69
68
70
// Parse the command-line flags.
69
71
flag .Parse ()
@@ -86,39 +88,14 @@ func main() {
86
88
}
87
89
}
88
90
89
- // Create a client for OLM
90
- crClient , err := client .NewClient (* kubeConfigPath )
91
- if err != nil {
92
- log .Fatalf ("error configuring client: %s" , err .Error ())
93
- }
94
-
95
- logger := log .New ()
96
-
97
91
// Set log level to debug if `debug` flag set
92
+ logger := log .New ()
98
93
if * debug {
99
- logger .SetLevel (log .DebugLevel )
94
+ // TODO: Switch back to debug level
95
+ logger .SetLevel (log .TraceLevel )
100
96
}
101
97
logger .Infof ("log level %s" , logger .Level )
102
98
103
- opClient := operatorclient .NewClientFromConfig (* kubeConfigPath , logger )
104
-
105
- // create a config client for operator status
106
- config , err := clientcmd .BuildConfigFromFlags ("" , * kubeConfigPath )
107
- if err != nil {
108
- log .Fatalf ("error configuring client: %s" , err .Error ())
109
- }
110
- configClient , err := configv1client .NewForConfig (config )
111
- if err != nil {
112
- log .Fatalf ("error configuring client: %s" , err .Error ())
113
- }
114
-
115
- // Create a new instance of the operator.
116
- operator , err := olm .NewOperator (logger , crClient , opClient , & install.StrategyResolver {}, * wakeupInterval , namespaces )
117
-
118
- if err != nil {
119
- log .Fatalf ("error configuring operator: %s" , err .Error ())
120
- }
121
-
122
99
var useTLS bool
123
100
if * tlsCertPath != "" && * tlsKeyPath == "" || * tlsCertPath == "" && * tlsKeyPath != "" {
124
101
logger .Warn ("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https" )
@@ -159,12 +136,40 @@ func main() {
159
136
}()
160
137
}
161
138
162
- ready , done , sync := operator .Run (stopCh )
163
- <- ready
139
+ // create a config client for operator status
140
+ config , err := clientcmd .BuildConfigFromFlags ("" , * kubeConfigPath )
141
+ if err != nil {
142
+ log .Fatalf ("error configuring client: %s" , err .Error ())
143
+ }
144
+ configClient , err := configv1client .NewForConfig (config )
145
+ if err != nil {
146
+ log .Fatalf ("error configuring client: %s" , err .Error ())
147
+ }
148
+ opClient := operatorclient .NewClientFromConfig (* kubeConfigPath , logger )
149
+ crClient , err := client .NewClient (* kubeConfigPath )
150
+ if err != nil {
151
+ log .Fatalf ("error configuring client: %s" , err .Error ())
152
+ }
153
+
154
+ // Create a new instance of the operator.
155
+ op , err := olm .NewOperator (
156
+ ctx ,
157
+ olm .WithLogger (logger ),
158
+ olm .WithWatchedNamespaces (namespaces ... ),
159
+ olm .WithResyncPeriod (* wakeupInterval ),
160
+ olm .WithExternalClient (crClient ),
161
+ olm .WithOperatorClient (opClient ),
162
+ )
163
+ if err != nil {
164
+ log .Fatalf ("error configuring operator: %s" , err .Error ())
165
+ }
166
+
167
+ op .Run (ctx )
168
+ <- op .Ready ()
164
169
165
170
if * writeStatusName != "" {
166
- operatorstatus .MonitorClusterStatus (* writeStatusName , sync , stopCh , opClient , configClient )
171
+ operatorstatus .MonitorClusterStatus (* writeStatusName , op . AtLevel (), ctx . Done () , opClient , configClient )
167
172
}
168
173
169
- <- done
174
+ <- op . Done ()
170
175
}
0 commit comments