private void updateConfigMap(ConfigMap oldConfigMap, ConfigMap newConfigMap) { kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .lockResourceVersion(oldConfigMap.getMetadata().getResourceVersion()) .replace(newConfigMap); } }
@Override public void eventReceived(Action action, ReplicationController resource) { logger.info("{}: {}", action, resource.getMetadata().getResourceVersion()); }
/** * Returns the resource version for the entity or null if it does not have one */ public static String getResourceVersion(HasMetadata entity) { if (entity != null) { ObjectMeta metadata = entity.getMetadata(); if (metadata != null) { String resourceVersion = metadata.getResourceVersion(); if (!Utils.isNullOrEmpty(resourceVersion)) { return resourceVersion; } } } return null; }
/** * A wait method that combines watching and polling. * The need for that is that in some cases a pure watcher approach consistently fails. * @param i The number of iterations to perform. * @param started Time in milliseconds where the watch started. * @param interval The amount of time in millis to wait on each iteration. * @param amount The maximum amount in millis of time since started to wait. * @return The {@link ReplicationController} if ready. */ protected T periodicWatchUntilReady(int i, long started, long interval, long amount) { T item = fromServer().get(); if (Readiness.isReady(item)) { return item; } ReadinessWatcher<T> watcher = new ReadinessWatcher<>(item); try (Watch watch = watch(item.getMetadata().getResourceVersion(), watcher)) { try { return watcher.await(interval, TimeUnit.MILLISECONDS); } catch (KubernetesClientTimeoutException e) { if (i <= 0) { throw e; } } long remaining = (started + amount) - System.currentTimeMillis(); long next = Math.max(0, Math.min(remaining, interval)); return periodicWatchUntilReady(i - 1, started, next, amount); } }
String newResourceVersion = ((HasMetadata) obj).getMetadata().getResourceVersion(); if (currentResourceVersion == null || currentResourceVersion.compareTo(newResourceVersion) < 0) { resourceVersion.compareAndSet(currentResourceVersion, newResourceVersion);
T obj = (T) object; resourceVersion.set(((HasMetadata) obj).getMetadata().getResourceVersion()); Watcher.Action action = Watcher.Action.valueOf(event.getType()); watcher.eventReceived(action, obj);
spec.setReplicas(replicas); DeploymentConfig updated = resource.patch(deploymentConfig); System.out.println("Updated the DeploymentConfig " + name + " version: " + deploymentConfig.getApiVersion() + " with replicas: " + replicas + " to resourceVersion: " + updated.getMetadata().getResourceVersion()); } catch (Exception e) { System.out.println("Failed to update the DeploymentConfig " + name + " with replicas: " + replicas); System.out.println("Updated the list.item DeploymentConfig " + name + " version: " + found.getApiVersion() + " with replicas: " + oldReplicas + " to resourceVersion: " + updated.getMetadata().getResourceVersion()); } catch (Exception e) { System.out.println("Failed to update the list.item DeploymentConfig " + name + " with replicas: " + oldReplicas);
resourceVersion = got.getMetadata().getResourceVersion(); } else { resourceVersion = null;
dummyClient.withResourceVersion(created.getMetadata().getResourceVersion()).watch(new Watcher<Dummy>() { @Override public void eventReceived(Action action, Dummy resource) {
@Override public String getResourceVersion(T item) { return item.getMetadata().getResourceVersion(); } }
/** * Returns the resource version for the entity or null if it does not have one */ public static String getResourceVersion(HasMetadata entity) { if (entity != null) { ObjectMeta metadata = entity.getMetadata(); if (metadata != null) { String resourceVersion = metadata.getResourceVersion(); if (StringUtils.isNotBlank(resourceVersion)) { return resourceVersion; } } } return null; }
private boolean wasChanged(T oldVersion, T newVersion) { if (oldVersion != null && oldVersion.getMetadata() != null && newVersion != null && newVersion.getMetadata() != null) { return !Objects.equals(oldVersion.getMetadata().getResourceVersion(), newVersion.getMetadata().getResourceVersion()); } else { return true; } }
public static long parseResourceVersion(HasMetadata obj) { return parseResourceVersion(obj.getMetadata().getResourceVersion()); }
@Override public T apply(T resource) { try { resource.getMetadata().setResourceVersion(got.getMetadata().getResourceVersion()); return handleReplace(resource); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } } };
public BuildConfigProjectProperty(BuildConfig bc) { this( bc.getMetadata().getNamespace(), bc.getMetadata().getName(), bc.getMetadata().getUid(), bc.getMetadata().getResourceVersion(), bc.getSpec().getSource().getContextDir() ); }
public ObjectMetaBuilder( ObjectMetaFluent<?> fluent , ObjectMeta instance ){ this.fluent = fluent; fluent.withAnnotations(instance.getAnnotations()); fluent.withCreationTimestamp(instance.getCreationTimestamp()); fluent.withDeletionTimestamp(instance.getDeletionTimestamp()); fluent.withGenerateName(instance.getGenerateName()); fluent.withLabels(instance.getLabels()); fluent.withName(instance.getName()); fluent.withNamespace(instance.getNamespace()); fluent.withResourceVersion(instance.getResourceVersion()); fluent.withSelfLink(instance.getSelfLink()); fluent.withUid(instance.getUid()); } public ObjectMetaBuilder( ObjectMeta instance ){
public ObjectMetaBuilder( ObjectMetaFluent<?> fluent , ObjectMeta instance ){ this.fluent = fluent; fluent.withAnnotations(instance.getAnnotations()); fluent.withCreationTimestamp(instance.getCreationTimestamp()); fluent.withDeletionTimestamp(instance.getDeletionTimestamp()); fluent.withGenerateName(instance.getGenerateName()); fluent.withLabels(instance.getLabels()); fluent.withName(instance.getName()); fluent.withNamespace(instance.getNamespace()); fluent.withResourceVersion(instance.getResourceVersion()); fluent.withSelfLink(instance.getSelfLink()); fluent.withUid(instance.getUid()); } public ObjectMetaBuilder( ObjectMeta instance ){
public ObjectMetaBuilder( ObjectMeta instance ){ this.fluent = this; this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withGenerateName(instance.getGenerateName()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }
public ObjectMetaBuilder( ObjectMeta instance ){ this.fluent = this; this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withGenerateName(instance.getGenerateName()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }
public ObjectMetaFluentImpl(ObjectMeta instance){ this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionGracePeriodSeconds(instance.getDeletionGracePeriodSeconds()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withFinalizers(instance.getFinalizers()); this.withGenerateName(instance.getGenerateName()); this.withGeneration(instance.getGeneration()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withOwnerReferences(instance.getOwnerReferences()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }