Skip to content

Commit 1f5328b

Browse files
YCShen1010qpdpQ
andauthored
Decouple common service operator from OLM (#2353)
* disable cs controller Signed-off-by: YuChen <[email protected]> * enable non-olm env veriable Signed-off-by: Allen Li <[email protected]> * create ODLM cr if crd exist Signed-off-by: Allen Li <[email protected]> --------- Signed-off-by: YuChen <[email protected]> Signed-off-by: Allen Li <[email protected]> Co-authored-by: Allen Li <[email protected]>
1 parent 8d2ffb3 commit 1f5328b

File tree

3 files changed

+176
-50
lines changed

3 files changed

+176
-50
lines changed

controllers/bootstrap/init.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,39 @@ type Resource struct {
9797
Scope string
9898
}
9999

100+
func NewNonOLMBootstrap(mgr manager.Manager) (bs *Bootstrap, err error) {
101+
cpfsNs := util.GetCPFSNamespace(mgr.GetAPIReader())
102+
servicesNs := util.GetServicesNamespace(mgr.GetAPIReader())
103+
operatorNs, err := util.GetOperatorNamespace()
104+
if err != nil {
105+
return
106+
}
107+
csData := apiv3.CSData{
108+
CPFSNs: cpfsNs,
109+
ServicesNs: servicesNs,
110+
OperatorNs: operatorNs,
111+
CatalogSourceName: "",
112+
CatalogSourceNs: "",
113+
ApprovalMode: "",
114+
WatchNamespaces: util.GetWatchNamespace(),
115+
OnPremMultiEnable: strconv.FormatBool(util.CheckMultiInstances(mgr.GetAPIReader())),
116+
ExcludedCatalog: constant.ExcludedCatalog,
117+
StatusMonitoredServices: constant.StatusMonitoredServices,
118+
}
119+
120+
bs = &Bootstrap{
121+
Client: mgr.GetClient(),
122+
Reader: mgr.GetAPIReader(),
123+
Config: mgr.GetConfig(),
124+
EventRecorder: mgr.GetEventRecorderFor("ibm-common-service-operator"),
125+
Manager: deploy.NewDeployManager(mgr),
126+
SaasEnable: util.CheckSaas(mgr.GetAPIReader()),
127+
MultiInstancesEnable: util.CheckMultiInstances(mgr.GetAPIReader()),
128+
CSData: csData,
129+
}
130+
return
131+
}
132+
100133
// NewBootstrap is the way to create a NewBootstrap struct
101134
func NewBootstrap(mgr manager.Manager) (bs *Bootstrap, err error) {
102135
cpfsNs := util.GetCPFSNamespace(mgr.GetAPIReader())

controllers/commonservice_controller.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,35 @@ const (
6363

6464
func (r *CommonServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6565

66+
if os.Getenv("NO_OLM") == "true" {
67+
klog.Infof("Reconciling CommonService: %s in non OLM environment", req.NamespacedName)
68+
69+
klog.Infof("Start to Create ODLM CR in the namespace %s", r.Bootstrap.CSData.OperatorNs)
70+
// Check if ODLM OperandRegistry and OperandConfig are created
71+
klog.Info("Checking if OperandRegistry and OperandConfig CRD already exist")
72+
existOpreg, _ := r.Bootstrap.CheckCRD(constant.OpregAPIGroupVersion, constant.OpregKind)
73+
existOpcon, _ := r.Bootstrap.CheckCRD(constant.OpregAPIGroupVersion, constant.OpconKind)
74+
// Install/update Opreg and Opcon resources before installing ODLM if CRDs exist
75+
if existOpreg && existOpcon {
76+
77+
klog.Info("Installing/Updating OperandRegistry")
78+
if err := r.Bootstrap.InstallOrUpdateOpreg(true, ""); err != nil {
79+
klog.Errorf("Fail to Installing/Updating OperandConfig: %v", err)
80+
return ctrl.Result{}, err
81+
}
82+
83+
klog.Info("Installing/Updating OperandConfig")
84+
if err := r.Bootstrap.InstallOrUpdateOpcon(true); err != nil {
85+
klog.Errorf("Fail to Installing/Updating OperandConfig: %v", err)
86+
return ctrl.Result{}, err
87+
}
88+
} else {
89+
klog.Error("ODLM CRD not ready, waiting for it to be ready")
90+
}
91+
92+
return ctrl.Result{}, nil
93+
}
94+
6695
klog.Infof("Reconciling CommonService: %s", req.NamespacedName)
6796

6897
// Fetch the CommonService instance

main.go

Lines changed: 114 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -143,67 +143,131 @@ func main() {
143143
// this Common Service Operator is not in the operatorNamespace(cpfsNs) under this tenant, and goes dormant.
144144
if operatorNs == cpfsNs {
145145

146-
// New bootstrap Object
147-
bs, err := bootstrap.NewBootstrap(mgr)
148-
if err != nil {
149-
klog.Errorf("Bootstrap failed: %v", err)
150-
os.Exit(1)
151-
}
146+
// Bootstrap for non-olm deploy
147+
if os.Getenv("NO_OLM") == "true" {
148+
bs, err := bootstrap.NewNonOLMBootstrap(mgr)
149+
if err != nil {
150+
klog.Errorf("Bootstrap failed: %v", err)
151+
os.Exit(1)
152+
}
152153

153-
if err := bs.CleanupWebhookResources(); err != nil {
154-
klog.Errorf("Cleanup Webhook Resources failed: %v", err)
155-
os.Exit(1)
156-
}
154+
if err := bs.CleanupWebhookResources(); err != nil {
155+
klog.Errorf("Cleanup Webhook Resources failed: %v", err)
156+
os.Exit(1)
157+
}
157158

158-
klog.Infof("Setup commonservice manager")
159-
if err = (&controllers.CommonServiceReconciler{
160-
Bootstrap: bs,
161-
Scheme: mgr.GetScheme(),
162-
Recorder: mgr.GetEventRecorderFor("commonservice-controller"),
163-
}).SetupWithManager(mgr); err != nil {
164-
klog.Errorf("Unable to create controller CommonService: %v", err)
165-
os.Exit(1)
166-
}
159+
klog.Infof("Setup commonservice manager")
160+
if err = (&controllers.CommonServiceReconciler{
161+
Bootstrap: bs,
162+
Scheme: mgr.GetScheme(),
163+
Recorder: mgr.GetEventRecorderFor("commonservice-controller"),
164+
}).SetupWithManager(mgr); err != nil {
165+
klog.Errorf("Unable to create controller CommonService: %v", err)
166+
os.Exit(1)
167+
}
167168

168-
klog.Infof("Start go routines")
169-
// Update CS CR Status
170-
go goroutines.UpdateCsCrStatus(bs)
171-
// Create CS CR
172-
go goroutines.WaitToCreateCsCR(bs)
173-
// Delete Keycloak Cert
174-
go goroutines.CleanupResources(bs)
175-
176-
// check if cert-manager CRD does not exist, then skip cert-manager related controllers initialization
177-
exist, err := bs.CheckCRD(constant.CertManagerAPIGroupVersionV1, "Certificate")
178-
if err != nil {
179-
klog.Errorf("Failed to check if cert-manager CRD exists: %v", err)
180-
os.Exit(1)
181-
}
182-
if !exist && err == nil {
183-
klog.Infof("cert-manager CRD does not exist, skip cert-manager related controllers initialization")
184-
} else if exist && err == nil {
169+
klog.Infof("Start go routines")
170+
// Create CS CR
171+
go goroutines.WaitToCreateCsCR(bs)
172+
// Delete Keycloak Cert
173+
go goroutines.CleanupResources(bs)
185174

186-
if err = (&certmanagerv1controllers.CertificateRefreshReconciler{
187-
Client: mgr.GetClient(),
188-
Scheme: mgr.GetScheme(),
189-
}).SetupWithManager(mgr); err != nil {
190-
klog.Error(err, "unable to create controller", "controller", "CertificateRefresh")
175+
// check if cert-manager CRD does not exist, then skip cert-manager related controllers initialization
176+
exist, err := bs.CheckCRD(constant.CertManagerAPIGroupVersionV1, "Certificate")
177+
if err != nil {
178+
klog.Errorf("Failed to check if cert-manager CRD exists: %v", err)
191179
os.Exit(1)
192180
}
193-
if err = (&certmanagerv1controllers.PodRefreshReconciler{
194-
Client: mgr.GetClient(),
195-
Scheme: mgr.GetScheme(),
196-
}).SetupWithManager(mgr); err != nil {
197-
klog.Error(err, "unable to create controller", "controller", "PodRefresh")
181+
if !exist && err == nil {
182+
klog.Infof("cert-manager CRD does not exist, skip cert-manager related controllers initialization")
183+
} else if exist && err == nil {
184+
185+
if err = (&certmanagerv1controllers.CertificateRefreshReconciler{
186+
Client: mgr.GetClient(),
187+
Scheme: mgr.GetScheme(),
188+
}).SetupWithManager(mgr); err != nil {
189+
klog.Error(err, "unable to create controller", "controller", "CertificateRefresh")
190+
os.Exit(1)
191+
}
192+
if err = (&certmanagerv1controllers.PodRefreshReconciler{
193+
Client: mgr.GetClient(),
194+
Scheme: mgr.GetScheme(),
195+
}).SetupWithManager(mgr); err != nil {
196+
klog.Error(err, "unable to create controller", "controller", "PodRefresh")
197+
os.Exit(1)
198+
}
199+
if err = (&certmanagerv1controllers.V1AddLabelReconciler{
200+
Client: mgr.GetClient(),
201+
Scheme: mgr.GetScheme(),
202+
}).SetupWithManager(mgr); err != nil {
203+
klog.Error(err, "unable to create controller", "controller", "V1AddLabel")
204+
os.Exit(1)
205+
}
206+
}
207+
} else {
208+
209+
// New bootstrap Object
210+
bs, err := bootstrap.NewBootstrap(mgr)
211+
if err != nil {
212+
klog.Errorf("Bootstrap failed: %v", err)
213+
os.Exit(1)
214+
}
215+
216+
if err := bs.CleanupWebhookResources(); err != nil {
217+
klog.Errorf("Cleanup Webhook Resources failed: %v", err)
198218
os.Exit(1)
199219
}
200-
if err = (&certmanagerv1controllers.V1AddLabelReconciler{
201-
Client: mgr.GetClient(),
202-
Scheme: mgr.GetScheme(),
220+
221+
klog.Infof("Setup commonservice manager")
222+
if err = (&controllers.CommonServiceReconciler{
223+
Bootstrap: bs,
224+
Scheme: mgr.GetScheme(),
225+
Recorder: mgr.GetEventRecorderFor("commonservice-controller"),
203226
}).SetupWithManager(mgr); err != nil {
204-
klog.Error(err, "unable to create controller", "controller", "V1AddLabel")
227+
klog.Errorf("Unable to create controller CommonService: %v", err)
205228
os.Exit(1)
206229
}
230+
231+
klog.Infof("Start go routines")
232+
// Update CS CR Status
233+
go goroutines.UpdateCsCrStatus(bs)
234+
// Create CS CR
235+
go goroutines.WaitToCreateCsCR(bs)
236+
// Delete Keycloak Cert
237+
go goroutines.CleanupResources(bs)
238+
239+
// check if cert-manager CRD does not exist, then skip cert-manager related controllers initialization
240+
exist, err := bs.CheckCRD(constant.CertManagerAPIGroupVersionV1, "Certificate")
241+
if err != nil {
242+
klog.Errorf("Failed to check if cert-manager CRD exists: %v", err)
243+
os.Exit(1)
244+
}
245+
if !exist && err == nil {
246+
klog.Infof("cert-manager CRD does not exist, skip cert-manager related controllers initialization")
247+
} else if exist && err == nil {
248+
249+
if err = (&certmanagerv1controllers.CertificateRefreshReconciler{
250+
Client: mgr.GetClient(),
251+
Scheme: mgr.GetScheme(),
252+
}).SetupWithManager(mgr); err != nil {
253+
klog.Error(err, "unable to create controller", "controller", "CertificateRefresh")
254+
os.Exit(1)
255+
}
256+
if err = (&certmanagerv1controllers.PodRefreshReconciler{
257+
Client: mgr.GetClient(),
258+
Scheme: mgr.GetScheme(),
259+
}).SetupWithManager(mgr); err != nil {
260+
klog.Error(err, "unable to create controller", "controller", "PodRefresh")
261+
os.Exit(1)
262+
}
263+
if err = (&certmanagerv1controllers.V1AddLabelReconciler{
264+
Client: mgr.GetClient(),
265+
Scheme: mgr.GetScheme(),
266+
}).SetupWithManager(mgr); err != nil {
267+
klog.Error(err, "unable to create controller", "controller", "V1AddLabel")
268+
os.Exit(1)
269+
}
270+
}
207271
}
208272
} else {
209273
klog.Infof("Common Service Operator goes dormant in the namespace %s", operatorNs)

0 commit comments

Comments
 (0)