@@ -573,6 +573,7 @@ func (c *Cluster) syncStatefulSet() error {
573573					}
574574				}
575575			}
576+ 			annotationToRemove  :=  "" 
576577			for  anno  :=  range  c .Statefulset .Spec .Template .Annotations  {
577578				if  _ , ok  :=  desiredSts .Spec .Template .Annotations [anno ]; ! ok  {
578579					// template annotation was removed 
@@ -581,14 +582,21 @@ func (c *Cluster) syncStatefulSet() error {
581582							continue 
582583						}
583584					}
584- 					annotationToRemove  :=  []byte (fmt .Sprintf (`{"metadata":{"annotations":{"%s":null}}}` , anno ))
585- 					for  _ , pod  :=  range  pods  {
586- 						_ , err  =  c .KubeClient .Pods (c .Namespace ).Patch (context .Background (), pod .Name ,
587- 							types .StrategicMergePatchType , annotationToRemove , metav1.PatchOptions {})
588- 						if  err  !=  nil  {
589- 							c .logger .Errorf ("failed to remove annotation %s from pod %s: %v" , anno , pod .Name , err )
590- 							return  err 
591- 						}
585+ 					if  annotationToRemove  !=  ""  {
586+ 						annotationToRemove  =  `{"metadata":{"annotations":{` 
587+ 					}
588+ 					annotationToRemove  +=  fmt .Sprintf (`"%s":null,` , anno )
589+ 					// annotationToRemove := []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":null}}}`, anno)) 
590+ 				}
591+ 			}
592+ 			if  annotationToRemove  !=  ""  {
593+ 				annotationToRemove  =  strings .TrimSuffix (annotationToRemove , "," ) +  `}}}` 
594+ 				for  _ , pod  :=  range  pods  {
595+ 					_ , err  =  c .KubeClient .Pods (c .Namespace ).Patch (context .Background (), pod .Name ,
596+ 						types .StrategicMergePatchType , []byte (annotationToRemove ), metav1.PatchOptions {})
597+ 					if  err  !=  nil  {
598+ 						c .logger .Errorf ("failed to remove annotations from pod %s: %v" , pod .Name , err )
599+ 						return  err 
592600					}
593601				}
594602			}
@@ -1614,6 +1622,7 @@ func (c *Cluster) syncLogicalBackupJob() error {
16141622				c .logger .Infof ("reason: %s" , reason )
16151623			}
16161624			if  strings .Contains (reason , "annotations do not match" ) {
1625+ 				annotationToRemoveTemplate  :=  `{"spec":{"jobTemplate":{"spec":{"template":{"metadata":{"annotations":{` 
16171626				for  anno  :=  range  job .Spec .JobTemplate .Spec .Template .Annotations  {
16181627					if  _ , ok  :=  desiredJob .Spec .JobTemplate .Spec .Template .Annotations [anno ]; ! ok  {
16191628						// template annotation was removed 
@@ -1622,16 +1631,16 @@ func (c *Cluster) syncLogicalBackupJob() error {
16221631								continue 
16231632							}
16241633						}
1625- 						annotationToRemoveTemplate  :=  []byte (fmt .Sprintf (
1626- 							`{"spec":{"jobTemplate":{"spec":{"template":{"metadata":{"annotations":{"%s":null}}}}}}}` , anno ))
1627- 						job , err  =  c .KubeClient .CronJobs (c .Namespace ).Patch (context .TODO (),
1628- 							jobName , types .StrategicMergePatchType , annotationToRemoveTemplate , metav1.PatchOptions {}, "" )
1629- 						if  err  !=  nil  {
1630- 							c .logger .Errorf ("failed to remove annotation %s from the logical backup job %q pod template: %v" , anno , jobName , err )
1631- 							return  err 
1632- 						}
1634+ 						annotationToRemoveTemplate  +=  fmt .Sprintf (`"%s":null,` , anno )
16331635					}
16341636				}
1637+ 				annotationToRemoveTemplate  =  strings .TrimSuffix (annotationToRemoveTemplate , "," ) +  `}}}}}}}` 
1638+ 				job , err  =  c .KubeClient .CronJobs (c .Namespace ).Patch (context .TODO (),
1639+ 					jobName , types .StrategicMergePatchType , []byte (annotationToRemoveTemplate ), metav1.PatchOptions {}, "" )
1640+ 				if  err  !=  nil  {
1641+ 					c .logger .Errorf ("failed to remove annotations from the logical backup job %q pod template: %v" , jobName , err )
1642+ 					return  err 
1643+ 				}
16351644			}
16361645			if  err  =  c .patchLogicalBackupJob (desiredJob ); err  !=  nil  {
16371646				return  fmt .Errorf ("could not update logical backup job to match desired state: %v" , err )
0 commit comments