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)
| 116 | // the cluster. It is pure so the three branches can be unit-tested without an |
| 117 | // apiserver. |
| 118 | func 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 | } |
no test coverage detected