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

Function classifyLeaseAdoption

internal/controller/primary_lease.go:118–132  ·  view source on GitHub ↗

classifyLeaseAdoption decides what to do with an existing Lease named after the cluster. It is pure so the three branches can be unit-tested without an apiserver.

(existing *coordinationv1.Lease, cluster *apiv1.Cluster)

Source from the content-addressed store, hash-verified

116// the cluster. It is pure so the three branches can be unit-tested without an
117// apiserver.
118func classifyLeaseAdoption(existing *coordinationv1.Lease, cluster *apiv1.Cluster) leaseAdoption {
119 if metav1.IsControlledBy(existing, cluster) {
120 return adoptAlreadyOurs
121 }
122 owner := metav1.GetControllerOf(existing)
123 if owner == nil {
124 return adoptOrphan
125 }
126 if owner.Kind == apiv1.ClusterKind &&
127 owner.APIVersion == apiv1.SchemeGroupVersion.String() &&
128 owner.Name == cluster.Name {
129 return adoptOrphan
130 }
131 return adoptRefuseForeign
132}

Callers 2

reconcilePrimaryLeaseMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected