(objectType, namespace, name string, record rl.LeaderElectionRecord)
| 38 | ) |
| 39 | |
| 40 | func createLockObject(objectType, namespace, name string, record rl.LeaderElectionRecord) (obj runtime.Object) { |
| 41 | objectMeta := metav1.ObjectMeta{ |
| 42 | Namespace: namespace, |
| 43 | Name: name, |
| 44 | } |
| 45 | switch objectType { |
| 46 | case "endpoints": |
| 47 | recordBytes, _ := json.Marshal(record) |
| 48 | objectMeta.Annotations = map[string]string{ |
| 49 | rl.LeaderElectionRecordAnnotationKey: string(recordBytes), |
| 50 | } |
| 51 | obj = &corev1.Endpoints{ObjectMeta: objectMeta} |
| 52 | case "configmaps": |
| 53 | recordBytes, _ := json.Marshal(record) |
| 54 | objectMeta.Annotations = map[string]string{ |
| 55 | rl.LeaderElectionRecordAnnotationKey: string(recordBytes), |
| 56 | } |
| 57 | obj = &corev1.ConfigMap{ObjectMeta: objectMeta} |
| 58 | case "leases": |
| 59 | spec := rl.LeaderElectionRecordToLeaseSpec(&record) |
| 60 | obj = &coordinationv1.Lease{ObjectMeta: objectMeta, Spec: spec} |
| 61 | default: |
| 62 | panic("unexpected objType:" + objectType) |
| 63 | } |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | // Will test leader election using endpoints as the resource |
| 68 | func TestTryAcquireOrRenewEndpoints(t *testing.T) { |
no outgoing calls
no test coverage detected