@@ -108,40 +108,75 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
108108 }
109109
110110 // reconcile dashboard component
111- enabled := r .isComponentEnabled (instance , dashboard . ComponentName , & (instance .Spec .Components .Dashboard ), ctx )
111+ enabled := r .isComponentEnabled (& (instance .Spec .Components .Dashboard ))
112112 if val , err := r .reconcileSubComponent (instance , dashboard .ComponentName , enabled , & (instance .Spec .Components .Dashboard ), ctx ); err != nil {
113+ // Update immediately only when error occurs, else skip to end
114+ err := r .Client .Update (ctx , instance )
115+ if err != nil {
116+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , dashboard .ComponentName ), "error" , err )
117+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
118+ }
113119 // no need to log any errors as this is done in the reconcileSubComponent method
114120 return val , err
115121 }
116122
117123 // reconcile DataSciencePipelines component
118- enabled = r .isComponentEnabled (instance , datasciencepipelines . ComponentName , & (instance .Spec .Components .DataSciencePipelines ), ctx )
124+ enabled = r .isComponentEnabled (& (instance .Spec .Components .DataSciencePipelines ))
119125 if val , err := r .reconcileSubComponent (instance , datasciencepipelines .ComponentName , enabled , & (instance .Spec .Components .DataSciencePipelines ), ctx ); err != nil {
126+ // Update immediately only when error occurs, else skip to end
127+ err := r .Client .Update (ctx , instance )
128+ if err != nil {
129+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , datasciencepipelines .ComponentName ), "error" , err )
130+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
131+ }
120132 // no need to log any errors as this is done in the reconcileSubComponent method
121133 return val , err
122134 }
123135
124136 // reconcile ModelMesh component
125- enabled = r .isComponentEnabled (instance , modelmeshserving . ComponentName , & (instance .Spec .Components .ModelMeshServing ), ctx )
137+ enabled = r .isComponentEnabled (& (instance .Spec .Components .ModelMeshServing ))
126138 if val , err := r .reconcileSubComponent (instance , modelmeshserving .ComponentName , enabled , & (instance .Spec .Components .ModelMeshServing ), ctx ); err != nil {
139+ // Update immediately only when error occurs, else skip to end
140+ err := r .Client .Update (ctx , instance )
141+ if err != nil {
142+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , modelmeshserving .ComponentName ), "error" , err )
143+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
144+ }
127145 // no need to log any errors as this is done in the reconcileSubComponent method
128146 return val , err
129147 }
130148
131149 // reconcile Workbench component
132- enabled = r .isComponentEnabled (instance , workbenches . ComponentName , & (instance .Spec .Components .Workbenches ), ctx )
150+ enabled = r .isComponentEnabled (& (instance .Spec .Components .Workbenches ))
133151 if val , err := r .reconcileSubComponent (instance , workbenches .ComponentName , enabled , & (instance .Spec .Components .Workbenches ), ctx ); err != nil {
152+ // Update immediately only when error occurs, else skip to end
153+ err := r .Client .Update (ctx , instance )
154+ if err != nil {
155+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , workbenches .ComponentName ), "error" , err )
156+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
157+ }
134158 // no need to log any errors as this is done in the reconcileSubComponent method
135159 return val , err
136160 }
137161
138162 // reconcile Kserve component
139- enabled = r .isComponentEnabled (instance , kserve . ComponentName , & (instance .Spec .Components .Kserve ), ctx )
163+ enabled = r .isComponentEnabled (& (instance .Spec .Components .Kserve ))
140164 if val , err := r .reconcileSubComponent (instance , kserve .ComponentName , enabled , & (instance .Spec .Components .Kserve ), ctx ); err != nil {
165+ err := r .Client .Update (ctx , instance )
166+ if err != nil {
167+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , kserve .ComponentName ), "error" , err )
168+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
169+ }
141170 // no need to log any errors as this is done in the reconcileSubComponent method
142171 return val , err
143172 }
144173
174+ // Update final state of spec
175+ err = r .Client .Update (ctx , instance )
176+ if err != nil {
177+ r .Log .Info (fmt .Sprintf ("failed to set DataScienceCluster CR :%v" , instance .Name ), "error" , err )
178+ // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
179+ }
145180 // finalize reconciliation
146181 status .SetCompleteCondition (& instance .Status .Conditions , status .ReconcileCompleted , "DataScienceCluster resource reconciled successfully." )
147182 err = r .Client .Status ().Update (ctx , instance )
@@ -162,14 +197,9 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
162197 return ctrl.Result {}, nil
163198}
164199
165- func (r * DataScienceClusterReconciler ) isComponentEnabled (instance * dsc. DataScienceCluster , componentName string , component components.ComponentInterface , ctx context. Context ) bool {
200+ func (r * DataScienceClusterReconciler ) isComponentEnabled (component components.ComponentInterface ) bool {
166201 if component .IsEnabled () == nil {
167202 component .SetEnabled (false )
168- err := r .Client .Update (ctx , instance )
169- if err != nil {
170- r .reportError (err , instance , ctx , fmt .Sprintf ("failed to set DataScienceCluster component %s to enabled: false" , componentName ))
171- // no need to return error as this is not critical and will be reconciled in the next update or reconcile loop
172- }
173203 }
174204 return * component .IsEnabled ()
175205}
0 commit comments