AddFencedInstance adds the given server name to the FencedInstanceAnnotation annotation returns an error if the instance was already fenced
(instanceName string, object metav1.Object)
| 92 | // AddFencedInstance adds the given server name to the FencedInstanceAnnotation annotation |
| 93 | // returns an error if the instance was already fenced |
| 94 | func AddFencedInstance(instanceName string, object metav1.Object) (bool, error) { |
| 95 | fencedInstances, err := GetFencedInstances(object.GetAnnotations()) |
| 96 | if err != nil { |
| 97 | return false, err |
| 98 | } |
| 99 | |
| 100 | if fencedInstances.Has(FenceAllInstances) || fencedInstances.Has(instanceName) { |
| 101 | return false, nil |
| 102 | } |
| 103 | |
| 104 | switch instanceName { |
| 105 | case FenceAllInstances: |
| 106 | fencedInstances = stringset.From([]string{FenceAllInstances}) |
| 107 | default: |
| 108 | fencedInstances.Put(instanceName) |
| 109 | } |
| 110 | |
| 111 | return true, setFencedInstances(object, fencedInstances) |
| 112 | } |
| 113 | |
| 114 | // removeFencedInstance removes the given server name from the FencedInstanceAnnotation annotation |
| 115 | // returns an error if the instance was already unfenced |
no test coverage detected