mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-19 07:28:50 +02:00
reuse existing block that define the annotations
This commit is contained in:
+33
-23
@@ -1783,36 +1783,46 @@ func (c *Cluster) syncLogicalBackupJob() error {
|
|||||||
return fmt.Errorf("could not patch labels of the logical backup job %q: %v", jobName, err)
|
return fmt.Errorf("could not patch labels of the logical backup job %q: %v", jobName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if changed, _ := c.compareAnnotations(job.Annotations, desiredJob.Annotations, nil); changed {
|
_, kubeIamInCurrent := job.Annotations[constants.KubeIAmAnnotation]
|
||||||
patchData, err := metaAnnotationsPatch(desiredJob.Annotations)
|
_, kubeIamInDesired := desiredJob.Annotations[constants.KubeIAmAnnotation]
|
||||||
if err != nil {
|
kubeIamNeedsRemoval := kubeIamInCurrent && !kubeIamInDesired
|
||||||
return fmt.Errorf("could not form patch for the logical backup job %q: %v", jobName, err)
|
if changed, _ := c.compareAnnotations(job.Annotations, desiredJob.Annotations, nil); changed || kubeIamNeedsRemoval {
|
||||||
|
patchAnnotations := make(map[string]interface{})
|
||||||
|
for k, v := range desiredJob.Annotations {
|
||||||
|
patchAnnotations[k] = v
|
||||||
}
|
}
|
||||||
_, err = c.KubeClient.CronJobs(c.Namespace).Patch(context.TODO(), jobName, types.MergePatchType, []byte(patchData), metav1.PatchOptions{})
|
if kubeIamNeedsRemoval {
|
||||||
|
patchAnnotations[constants.KubeIAmAnnotation] = nil
|
||||||
|
}
|
||||||
|
patchData, err := json.Marshal(map[string]interface{}{
|
||||||
|
"metadata": map[string]interface{}{"annotations": patchAnnotations},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not form patch for the logical backup job %q annotations: %v", jobName, err)
|
||||||
|
}
|
||||||
|
_, err = c.KubeClient.CronJobs(c.Namespace).Patch(context.TODO(), jobName, types.MergePatchType, patchData, metav1.PatchOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not patch annotations of the logical backup job %q: %v", jobName, err)
|
return fmt.Errorf("could not patch annotations of the logical backup job %q: %v", jobName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if _, ok := job.Spec.JobTemplate.Annotations[constants.KubeIAmAnnotation]; ok {
|
||||||
if c.OpConfig.KubeIAMRole == "" {
|
if _, exists := desiredJob.Spec.JobTemplate.Annotations[constants.KubeIAmAnnotation]; !exists {
|
||||||
patch, err := json.Marshal(map[string]interface{}{
|
patchData, err := json.Marshal(map[string]interface{}{
|
||||||
"metadata": map[string]interface{}{
|
"spec": map[string]interface{}{
|
||||||
"annotations": map[string]*string{constants.KubeIAmAnnotation: nil},
|
"jobTemplate": map[string]interface{}{
|
||||||
},
|
"metadata": map[string]interface{}{
|
||||||
"spec": map[string]interface{}{
|
"annotations": map[string]*string{constants.KubeIAmAnnotation: nil},
|
||||||
"jobTemplate": map[string]interface{}{
|
},
|
||||||
"metadata": map[string]interface{}{
|
|
||||||
"annotations": map[string]*string{constants.KubeIAmAnnotation: nil},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
})
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("could not form patch for the logical backup job %q job template annotations: %v", jobName, err)
|
||||||
return fmt.Errorf("could not marshal kube2iam annotation removal patch for logical backup job %q: %v", jobName, err)
|
}
|
||||||
}
|
_, err = c.KubeClient.CronJobs(c.Namespace).Patch(context.TODO(), jobName, types.MergePatchType, patchData, metav1.PatchOptions{})
|
||||||
_, err = c.KubeClient.CronJobs(c.Namespace).Patch(context.TODO(), jobName, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("could not remove kube2iam annotation from logical backup job %q job template: %v", jobName, err)
|
||||||
return fmt.Errorf("could not remove kube2iam annotation from logical backup job %q: %v", jobName, err)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.LogicalBackupJob = desiredJob
|
c.LogicalBackupJob = desiredJob
|
||||||
|
|||||||
Reference in New Issue
Block a user