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

Method Execute

pkg/utils/fencing.go:180–206  ·  view source on GitHub ↗

Execute executes the instructions given with the fluent builder, returns any error encountered

(ctx context.Context, key types.NamespacedName, obj client.Object)

Source from the content-addressed store, hash-verified

178
179// Execute executes the instructions given with the fluent builder, returns any error encountered
180func (fb *FencingMetadataExecutor) Execute(ctx context.Context, key types.NamespacedName, obj client.Object) error {
181 if len(fb.instanceNames) == 0 {
182 return errors.New("chose an operation to execute")
183 }
184 if len(fb.instanceNames) > 1 && slices.Contains(fb.instanceNames, FenceAllInstances) {
185 return errors.New("the fence-all-instances token (*) cannot be used along other instances")
186 }
187
188 if err := fb.cli.Get(ctx, key, obj); err != nil {
189 return err
190 }
191
192 var appliedChange bool
193 fencedObject := obj.DeepCopyObject().(client.Object)
194 for _, name := range fb.instanceNames {
195 changed, err := fb.fenceFunc(name, fencedObject)
196 if err != nil {
197 return err
198 }
199 appliedChange = appliedChange || changed
200 }
201 if !appliedChange {
202 return nil
203 }
204
205 return fb.cli.Patch(ctx, fencedObject, client.MergeFrom(obj))
206}

Callers 15

ensurePodIsFencedMethod · 0.80
EnsurePodIsUnfencedFunction · 0.80
startTransitionFunction · 0.80
CreateHBARulesFunction · 0.80
CreateIdentRulesFunction · 0.80
BuildConfigurationFilesFunction · 0.80
ensureClusterIsNotFencedFunction · 0.80
cluster_test.goFile · 0.80
NewCmdFunction · 0.80
generateConfigMapMethod · 0.80
renderTemplateFunction · 0.80

Calls 3

GetMethod · 0.45
DeepCopyObjectMethod · 0.45
PatchMethod · 0.45

Tested by 1

renderTemplateFunction · 0.64