On marks an instance in a cluster as fenced
( ctx context.Context, crudClient client.Client, serverName, namespace, clusterName string, fencingMethod Method, )
| 44 | |
| 45 | // On marks an instance in a cluster as fenced |
| 46 | func On( |
| 47 | ctx context.Context, |
| 48 | crudClient client.Client, |
| 49 | serverName, |
| 50 | namespace, |
| 51 | clusterName string, |
| 52 | fencingMethod Method, |
| 53 | ) error { |
| 54 | switch fencingMethod { |
| 55 | case UsingPlugin: |
| 56 | _, _, err := run.Run(fmt.Sprintf("kubectl cnpg fencing on %v %v -n %v", |
| 57 | clusterName, serverName, namespace)) |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | case UsingAnnotation: |
| 62 | err := utils.NewFencingMetadataExecutor(crudClient). |
| 63 | AddFencing(). |
| 64 | ForInstance(serverName). |
| 65 | Execute(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, &apiv1.Cluster{}) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | default: |
| 70 | return fmt.Errorf("unrecognized fencing Method: %s", fencingMethod) |
| 71 | } |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | // Off marks an instance in a cluster as not fenced |
| 76 | func Off( |
no test coverage detected