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

Function setFencedInstances

pkg/utils/fencing.go:67–90  ·  view source on GitHub ↗

setFencedInstances sets the list of fenced servers inside the annotations

(object metav1.Object, data *stringset.Data)

Source from the content-addressed store, hash-verified

65
66// setFencedInstances sets the list of fenced servers inside the annotations
67func 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

Callers 2

AddFencedInstanceFunction · 0.85
removeFencedInstanceFunction · 0.85

Calls 1

LenMethod · 0.45

Tested by

no test coverage detected