fdb-kubernetes-monitor: Ensure that the annotations are updated when the correct configuration is already loaded (#11486)
This commit is contained in:
parent
e52fc3621f
commit
2753f4e2b2
|
@ -239,11 +239,6 @@ func (podClient *kubernetesClient) updateAnnotationsOnPod(annotationChanges map[
|
|||
if podClient.podMetadata == nil {
|
||||
return fmt.Errorf("pod client has no metadata present")
|
||||
}
|
||||
|
||||
annotations := podClient.podMetadata.Annotations
|
||||
if len(annotations) == 0 {
|
||||
annotations = map[string]string{}
|
||||
}
|
||||
|
||||
if !podClient.podMetadata.DeletionTimestamp.IsZero() {
|
||||
return fmt.Errorf("pod is marked for deletion, cannot update annotations")
|
||||
|
@ -264,13 +259,24 @@ func (podClient *kubernetesClient) updateAnnotationsOnPod(annotationChanges map[
|
|||
|
||||
return true
|
||||
}, func() error {
|
||||
annotations := podClient.podMetadata.Annotations
|
||||
if len(annotations) == 0 {
|
||||
annotations = map[string]string{}
|
||||
currentAnnotations := podClient.podMetadata.Annotations
|
||||
if len(currentAnnotations) == 0 {
|
||||
currentAnnotations = map[string]string{}
|
||||
}
|
||||
|
||||
var hasChanges bool
|
||||
for key, val := range annotationChanges {
|
||||
annotations[key] = val
|
||||
currentValue, present := currentAnnotations[key]
|
||||
if !present || currentValue != val {
|
||||
podClient.Logger.Info("update annotation with new value", "annotation", key, "currentValue", currentValue, "newValue", val, "present", present)
|
||||
currentAnnotations[key] = val
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
|
||||
// If no changes are present, we can skip the patch.
|
||||
if !hasChanges {
|
||||
return nil
|
||||
}
|
||||
|
||||
return podClient.Patch(context.Background(), &corev1.Pod{
|
||||
|
@ -281,7 +287,7 @@ func (podClient *kubernetesClient) updateAnnotationsOnPod(annotationChanges map[
|
|||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: podClient.podMetadata.Namespace,
|
||||
Name: podClient.podMetadata.Name,
|
||||
Annotations: annotations,
|
||||
Annotations: currentAnnotations,
|
||||
},
|
||||
}, client.Apply, client.FieldOwner("fdb-kubernetes-monitor"), client.ForceOwnership)
|
||||
})
|
||||
|
|
|
@ -283,6 +283,12 @@ func (monitor *monitor) loadConfiguration() {
|
|||
}
|
||||
|
||||
monitor.acceptConfiguration(configuration, configurationBytes)
|
||||
// Always update the annotations if needed to handle cases where the fdb-kubernetes-monitor
|
||||
// has loaded the new configuration but was not able to update the annotations.
|
||||
err := monitor.podClient.updateAnnotations(monitor)
|
||||
if err != nil {
|
||||
monitor.logger.Error(err, "Error updating pod annotations")
|
||||
}
|
||||
}
|
||||
|
||||
// checkOwnerExecutable validates that a path is a file that exists and is
|
||||
|
@ -332,11 +338,6 @@ func (monitor *monitor) acceptConfiguration(configuration *api.ProcessConfigurat
|
|||
if hasRunningProcesses && !monitor.activeConfiguration.ShouldRunServers() {
|
||||
monitor.sendSignalToProcesses(syscall.SIGTERM)
|
||||
}
|
||||
|
||||
err := monitor.podClient.updateAnnotations(monitor)
|
||||
if err != nil {
|
||||
monitor.logger.Error(err, "Error updating pod annotations")
|
||||
}
|
||||
}
|
||||
|
||||
// getBackoffDuration returns the backoff duration. The backoff time will increase exponential with a maximum of 60 seconds.
|
||||
|
|
Loading…
Reference in New Issue