New creates a new Runnable.
( kubeClient kubernetes.Interface, instance *postgres.Instance, )
| 115 | |
| 116 | // New creates a new Runnable. |
| 117 | func New( |
| 118 | kubeClient kubernetes.Interface, |
| 119 | instance *postgres.Instance, |
| 120 | ) *Runnable { |
| 121 | return &Runnable{ |
| 122 | instance: instance, |
| 123 | config: defaultConfig(), |
| 124 | lock: &resourcelock.LeaseLock{ |
| 125 | LeaseMeta: metav1.ObjectMeta{ |
| 126 | Namespace: instance.GetNamespaceName(), |
| 127 | Name: instance.GetClusterName(), |
| 128 | }, |
| 129 | Client: kubeClient.CoordinationV1(), |
| 130 | LockConfig: resourcelock.ResourceLockConfig{ |
| 131 | // Identity is the pod name alone. The operator creates Pods |
| 132 | // directly and reuses a pod name only after the previous |
| 133 | // incarnation is confirmed dead, so any process running under |
| 134 | // this Identity is the legitimate holder. |
| 135 | Identity: instance.GetPodName(), |
| 136 | }, |
| 137 | }, |
| 138 | activateCh: make(chan struct{}), |
| 139 | heldCh: make(chan struct{}), |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // Acquire signals the runnable to start competing for the lease using the |
| 144 | // provided configuration, then blocks until the lease is held or ctx is |
no test coverage detected