@Test void getWithExistingLeaseShouldReturnLeaderElectionRecord() { final Lease lease = new LeaseBuilder().withNewSpec() .withHolderIdentity("1337") .withLeaseDurationSeconds(15) .withAcquireTime(ZonedDateTime.of(2015, 10, 21, 4, 29, 0, 0, ZoneId.of("UTC"))) .withRenewTime(ZonedDateTime.of(2015, 10, 21, 7, 28, 0, 0, ZoneId.of("UTC"))) .withLeaseTransitions(0) .endSpec().build(); when(leases.withName(eq("name")).get()).thenReturn(lease); lease.setMetadata(new ObjectMetaBuilder().withResourceVersion("313373").build()); final LeaseLock lock = new LeaseLock("namespace", "name", "1337"); final LeaderElectionRecord result = lock.get(kc); assertNotNull(result); assertEquals("313373", result.getVersion()); assertEquals("1337", result.getHolderIdentity()); assertEquals(15, result.getLeaseDuration().getSeconds()); assertEquals(ZonedDateTime.of(2015, 10, 21, 4, 29, 0, 0, ZoneId.of("UTC")), result.getAcquireTime()); }
@Override public <C extends Namespaceable<C> & KubernetesClient> LeaderElectionRecord get(C client) { final Lease lease = client.inNamespace(leaseNamespace).leases().withName(leaseName).get(); return Optional.ofNullable(lease) .map(Lease::getSpec) .map(spec -> { final LeaderElectionRecord ret = new LeaderElectionRecord( spec.getHolderIdentity(), Duration.ofSeconds(spec.getLeaseDurationSeconds()), spec.getAcquireTime(), spec.getRenewTime(), Optional.ofNullable(spec.getLeaseTransitions()).orElse(0) ); ret.setVersion(lease.getMetadata().getResourceVersion()); return ret; }) .orElse(null); }
LeaseLock implements Lock { @Override public <C extends Namespaceable<C> & KubernetesClient> LeaderElectionRecord get(C client) { final Lease lease = client.inNamespace(leaseNamespace).leases().withName(leaseName).get(); return Optional.ofNullable(lease) .map(Lease::getSpec) .map(spec -> { final LeaderElectionRecord ret = new LeaderElectionRecord( spec.getHolderIdentity(), Duration.ofSeconds(spec.getLeaseDurationSeconds()), spec.getAcquireTime(), spec.getRenewTime(), Optional.ofNullable(spec.getLeaseTransitions()).orElse(0) ); ret.setVersion(lease.getMetadata().getResourceVersion()); return ret; }) .orElse(null); } }
LeaseLock implements Lock { @Override public <C extends Namespaceable<C> & KubernetesClient> LeaderElectionRecord get(C client) { final Lease lease = client.inNamespace(leaseNamespace).leases().withName(leaseName).get(); return Optional.ofNullable(lease) .map(Lease::getSpec) .map(spec -> { final LeaderElectionRecord ret = new LeaderElectionRecord( spec.getHolderIdentity(), Duration.ofSeconds(spec.getLeaseDurationSeconds()), spec.getAcquireTime(), spec.getRenewTime(), Optional.ofNullable(spec.getLeaseTransitions()).orElse(0) ); ret.setVersion(lease.getMetadata().getResourceVersion()); return ret; }) .orElse(null); } LeaseLock(String leaseNamespace, String leaseName, String identity); }
LeaseLock implements Lock { @Override public <C extends Namespaceable<C> & KubernetesClient> LeaderElectionRecord get(C client) { final Lease lease = client.inNamespace(leaseNamespace).leases().withName(leaseName).get(); return Optional.ofNullable(lease) .map(Lease::getSpec) .map(spec -> { final LeaderElectionRecord ret = new LeaderElectionRecord( spec.getHolderIdentity(), Duration.ofSeconds(spec.getLeaseDurationSeconds()), spec.getAcquireTime(), spec.getRenewTime(), Optional.ofNullable(spec.getLeaseTransitions()).orElse(0) ); ret.setVersion(lease.getMetadata().getResourceVersion()); return ret; }) .orElse(null); } LeaseLock(String leaseNamespace, String leaseName, String identity); @Override LeaderElectionRecord get(C client); @Override void create(
    C client, LeaderElectionRecord leaderElectionRecord); @Override void update(
    C client, LeaderElectionRecord leaderElectionRecord); @Override String identity(); @Override String describe(); }
LeaseLock implements Lock { @Override public <C extends Namespaceable<C> & KubernetesClient> LeaderElectionRecord get(C client) { final Lease lease = client.inNamespace(leaseNamespace).leases().withName(leaseName).get(); return Optional.ofNullable(lease) .map(Lease::getSpec) .map(spec -> { final LeaderElectionRecord ret = new LeaderElectionRecord( spec.getHolderIdentity(), Duration.ofSeconds(spec.getLeaseDurationSeconds()), spec.getAcquireTime(), spec.getRenewTime(), Optional.ofNullable(spec.getLeaseTransitions()).orElse(0) ); ret.setVersion(lease.getMetadata().getResourceVersion()); return ret; }) .orElse(null); } LeaseLock(String leaseNamespace, String leaseName, String identity); @Override LeaderElectionRecord get(C client); @Override void create(
    C client, LeaderElectionRecord leaderElectionRecord); @Override void update(
    C client, LeaderElectionRecord leaderElectionRecord); @Override String identity(); @Override String describe();  }