MCPcopy
hub / github.com/kubernetes/client-go / createLockObject

Function createLockObject

tools/leaderelection/leaderelection_test.go:40–65  ·  view source on GitHub ↗
(objectType, namespace, name string, record rl.LeaderElectionRecord)

Source from the content-addressed store, hash-verified

38)
39
40func 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
68func TestTryAcquireOrRenewEndpoints(t *testing.T) {

Callers 1

testTryAcquireOrRenewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected