setFencedInstances sets the list of fenced servers inside the annotations
(object metav1.Object, data *stringset.Data)
| 65 | |
| 66 | // setFencedInstances sets the list of fenced servers inside the annotations |
| 67 | func setFencedInstances(object metav1.Object, data *stringset.Data) error { |
| 68 | annotations := object.GetAnnotations() |
| 69 | defer func() { |
| 70 | object.SetAnnotations(annotations) |
| 71 | }() |
| 72 | if data.Len() == 0 { |
| 73 | delete(annotations, FencedInstanceAnnotation) |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | serverList := data.ToList() |
| 78 | sort.Strings(serverList) |
| 79 | |
| 80 | annotationValue, err := json.Marshal(serverList) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | if annotations == nil { |
| 85 | annotations = make(map[string]string) |
| 86 | } |
| 87 | annotations[FencedInstanceAnnotation] = string(annotationValue) |
| 88 | |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | // AddFencedInstance adds the given server name to the FencedInstanceAnnotation annotation |
| 93 | // returns an error if the instance was already fenced |
no test coverage detected