@@ -119,14 +119,8 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
119119 return minInspectionInterval , errors .Wrapf (err , "Calculation of spec failed" )
120120 } else {
121121 condition , exists := status .Conditions .Get (api .ConditionTypeUpToDate )
122- if (checksum != status .AppliedVersion && (! exists || condition .IsTrue ())) ||
123- (checksum == status .AppliedVersion && (! exists || ! condition .IsTrue ())) {
124- if err = d .WithStatusUpdate (func (s * api.DeploymentStatus ) bool {
125- if checksum == status .AppliedVersion {
126- return s .Conditions .Update (api .ConditionTypeUpToDate , true , "Everything is UpToDate" , "Spec applied" )
127- }
128- return s .Conditions .Update (api .ConditionTypeUpToDate , false , "Spec Changed" , "Spec Object changed. Waiting until plan will be applied" )
129- }); err != nil {
122+ if checksum != status .AppliedVersion && (! exists || condition .IsTrue ()) {
123+ if err = d .updateCondition (api .ConditionTypeUpToDate , false , "Spec Changed" , "Spec Object changed. Waiting until plan will be applied" ); err != nil {
130124 return minInspectionInterval , errors .Wrapf (err , "Unable to update UpToDate condition" )
131125 }
132126
@@ -185,8 +179,37 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
185179 }
186180
187181 // Create scale/update plan
188- if err := d .reconciler .CreatePlan (); err != nil {
182+ if err , updated := d .reconciler .CreatePlan (); err != nil {
189183 return minInspectionInterval , errors .Wrapf (err , "Plan creation failed" )
184+ } else if updated {
185+ return minInspectionInterval , nil
186+ }
187+
188+ if d .apiObject .Status .Plan .IsEmpty () && status .AppliedVersion != checksum {
189+ if err := d .WithStatusUpdate (func (s * api.DeploymentStatus ) bool {
190+ s .AppliedVersion = checksum
191+ return true
192+ }); err != nil {
193+ return minInspectionInterval , errors .Wrapf (err , "Unable to update UpToDate condition" )
194+ }
195+
196+ return minInspectionInterval , nil
197+ } else if status .AppliedVersion == checksum {
198+ if ! status .Plan .IsEmpty () && status .Conditions .IsTrue (api .ConditionTypeUpToDate ) {
199+ if err = d .updateCondition (api .ConditionTypeUpToDate , false , "Plan is not empty" , "There are pending operations in plan" ); err != nil {
200+ return minInspectionInterval , errors .Wrapf (err , "Unable to update UpToDate condition" )
201+ }
202+
203+ return minInspectionInterval , nil
204+ }
205+
206+ if status .Plan .IsEmpty () && ! status .Conditions .IsTrue (api .ConditionTypeUpToDate ) {
207+ if err = d .updateCondition (api .ConditionTypeUpToDate , true , "Spec is Up To Date" , "Spec is Up To Date" ); err != nil {
208+ return minInspectionInterval , errors .Wrapf (err , "Unable to update UpToDate condition" )
209+ }
210+
211+ return minInspectionInterval , nil
212+ }
190213 }
191214
192215 // Execute current step of scale/update plan
@@ -196,18 +219,6 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
196219 }
197220 if retrySoon {
198221 nextInterval = minInspectionInterval
199- } else {
200- // Do not retry - so plan is empty
201- if status .AppliedVersion != checksum {
202- if err := d .WithStatusUpdate (func (s * api.DeploymentStatus ) bool {
203- s .AppliedVersion = checksum
204- return true
205- }); err != nil {
206- return minInspectionInterval , errors .Wrapf (err , "Unable to update UpToDate condition" )
207- }
208-
209- return minInspectionInterval , nil
210- }
211222 }
212223
213224 // Create access packages
@@ -279,3 +290,14 @@ func (d *Deployment) triggerInspection() {
279290func (d * Deployment ) triggerCRDInspection () {
280291 d .inspectCRDTrigger .Trigger ()
281292}
293+
294+ func (d * Deployment ) updateCondition (conditionType api.ConditionType , status bool , reason , message string ) error {
295+ d .deps .Log .Info ().Str ("condition" , string (conditionType )).Bool ("status" , status ).Str ("reason" , reason ).Str ("message" , message ).Msg ("Updated condition" )
296+ if err := d .WithStatusUpdate (func (s * api.DeploymentStatus ) bool {
297+ return s .Conditions .Update (conditionType , status , reason , message )
298+ }); err != nil {
299+ return errors .Wrapf (err , "Unable to update condition" )
300+ }
301+
302+ return nil
303+ }
0 commit comments