MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / AddFencedInstance

Function AddFencedInstance

pkg/utils/fencing.go:94–112  ·  view source on GitHub ↗

AddFencedInstance adds the given server name to the FencedInstanceAnnotation annotation returns an error if the instance was already fenced

(instanceName string, object metav1.Object)

Source from the content-addressed store, hash-verified

92// AddFencedInstance adds the given server name to the FencedInstanceAnnotation annotation
93// returns an error if the instance was already fenced
94func 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

Callers 3

offline_test.goFile · 0.92
fencing_test.goFile · 0.85

Calls 3

GetFencedInstancesFunction · 0.85
setFencedInstancesFunction · 0.85
HasMethod · 0.80

Tested by

no test coverage detected