@@ -19,6 +19,7 @@ package controllers
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "time"
22
23
23
24
configv1 "github.com/openshift/api/config/v1"
24
25
"k8s.io/apimachinery/pkg/api/errors"
@@ -37,8 +38,9 @@ import (
37
38
// ClusterVersionReconciler reconciles a ClusterVersion object
38
39
type ClusterVersionReconciler struct {
39
40
client.Client
40
- Scheme * runtime.Scheme
41
- ConsolePort int
41
+ Scheme * runtime.Scheme
42
+ ConsolePort int
43
+ OperatorNamespace string
42
44
}
43
45
44
46
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch;create;update;patch;delete
@@ -58,7 +60,28 @@ func (r *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
58
60
if err := r .Client .Get (context .TODO (), req .NamespacedName , & instance ); err != nil {
59
61
return ctrl.Result {}, err
60
62
}
61
- if err := r .ensureConsolePlugin (instance .Status .Desired .Version ); err != nil {
63
+
64
+ if err := r .ensureOdfConsoleConfigMapAndService (); err != nil {
65
+ logger .Error (err , "Could not ensure configmap and service for odf-console deployment" )
66
+ return ctrl.Result {}, err
67
+ }
68
+
69
+ csvList , err := util .GetNamespaceCSVs (ctx , r .Client , r .OperatorNamespace )
70
+ if err != nil {
71
+ return ctrl.Result {}, err
72
+ }
73
+
74
+ // Check if it is upgrade from 4.17 to 4.18
75
+ // The new CSVs won't exists while upgrading
76
+ // They will exists only after new operator has created a new subscription
77
+ if ! util .AreMultipleOdfOperatorCsvsPresent (csvList ) {
78
+ if err := util .ValidateCSVsPresent (csvList , EssentialCSVs ... ); err != nil {
79
+ logger .Error (err , "Could not ensure CSVs presence" )
80
+ return ctrl.Result {Requeue : true , RequeueAfter : time .Second * 2 }, nil
81
+ }
82
+ }
83
+
84
+ if err := r .ensureConsolePluginAndCLIDownload (instance .Status .Desired .Version ); err != nil {
62
85
logger .Error (err , "Could not ensure compatibility for ODF consolePlugin" )
63
86
return ctrl.Result {}, err
64
87
}
@@ -69,12 +92,7 @@ func (r *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
69
92
// SetupWithManager sets up the controller with the Manager.
70
93
func (r * ClusterVersionReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
71
94
err := mgr .Add (manager .RunnableFunc (func (context.Context ) error {
72
- clusterVersion , err := util .DetermineOpenShiftVersion (r .Client )
73
- if err != nil {
74
- return err
75
- }
76
-
77
- return r .ensureConsolePlugin (clusterVersion )
95
+ return r .ensureOdfConsoleConfigMapAndService ()
78
96
}))
79
97
if err != nil {
80
98
return err
@@ -85,15 +103,10 @@ func (r *ClusterVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
85
103
Complete (r )
86
104
}
87
105
88
- func (r * ClusterVersionReconciler ) ensureConsolePlugin ( clusterVersion string ) error {
106
+ func (r * ClusterVersionReconciler ) ensureOdfConsoleConfigMapAndService ( ) error {
89
107
logger := log .FromContext (context .TODO ())
90
- // The base path to where the request are sent
91
- basePath := console .GetBasePath (clusterVersion )
92
108
nginxConf := console .NginxConf
93
109
94
- // Customer portal link (CLI Tool download)
95
- portalLink := console .CUSTOMER_PORTAL_LINK
96
-
97
110
// Get ODF console Deployment
98
111
odfConsoleDeployment := console .GetDeployment (OperatorNamespace )
99
112
err := r .Client .Get (context .TODO (), types.NamespacedName {
@@ -126,9 +139,19 @@ func (r *ClusterVersionReconciler) ensureConsolePlugin(clusterVersion string) er
126
139
return err
127
140
}
128
141
142
+ return nil
143
+ }
144
+
145
+ func (r * ClusterVersionReconciler ) ensureConsolePluginAndCLIDownload (clusterVersion string ) error {
146
+ logger := log .FromContext (context .TODO ())
147
+ // The base path to where the request are sent
148
+ basePath := console .GetBasePath (clusterVersion )
149
+ // Customer portal link (CLI Tool download)
150
+ portalLink := console .CUSTOMER_PORTAL_LINK
151
+
129
152
// Create/Update ODF console ConsolePlugin
130
153
odfConsolePlugin := console .GetConsolePluginCR (r .ConsolePort , OperatorNamespace )
131
- _ , err = controllerutil .CreateOrUpdate (context .TODO (), r .Client , odfConsolePlugin , func () error {
154
+ _ , err : = controllerutil .CreateOrUpdate (context .TODO (), r .Client , odfConsolePlugin , func () error {
132
155
if odfConsolePlugin .Spec .Backend .Service != nil {
133
156
if currentBasePath := odfConsolePlugin .Spec .Backend .Service .BasePath ; currentBasePath != basePath {
134
157
logger .Info (fmt .Sprintf ("Set the BasePath for odf-console plugin as '%s'" , basePath ))
0 commit comments