static <L, R> boolean itemExists(L item, Collection<R> collection) { for (R candidate : collection) { if (configEqual(item, candidate)) { return true; } } return false; }
protected static boolean configEqualList(List v1, List v2) { int size1 = size(v1); int size2 = size(v2); if (size1 != size2) { return false; } int idx = 0; for (Object value : v1) { Object value2 = v2.get(idx++); if (!configEqual(value, value2)) { return false; } } return true; }
protected static boolean configEqualMap(Map entity1, Map entity2) { if (entity1 == entity2) { return true; } else if (entity1 == null || entity2 == null) { return false; } int size1 = size(entity1); int size2 = size(entity2); if (size1 != size2) { return false; } Set<Map.Entry> entries = entity1.entrySet(); for (Map.Entry entry : entries) { Object key = entry.getKey(); Object value = entry.getValue(); Object value2 = entity2.get(key); if (!configEqual(value, value2)) { return false; } } return true; }
Object value1 = invokeMethod(entity1, readMethod); Object value2 = invokeMethod(entity2, readMethod); if (value1 != null && value2 != null && !configEqual(value1, value2)) { return false;
private static EntityPatcher<ReplicationController> rcPatcher() { return (KubernetesClient client, String namespace, ReplicationController newObj, ReplicationController oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneableReplicationController entity = client.replicationControllers() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
private static EntityPatcher<PersistentVolumeClaim> pvcPatcher() { return (KubernetesClient client, String namespace, PersistentVolumeClaim newObj, PersistentVolumeClaim oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneablePersistentVolumeClaim entity = client.persistentVolumeClaims() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
private static EntityPatcher<BuildConfig> bcPatcher() { return (KubernetesClient client, String namespace, BuildConfig newObj, BuildConfig oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } OpenShiftClient openShiftClient = OpenshiftHelper.asOpenShiftClient(client); if (openShiftClient == null) { throw new IllegalArgumentException("BuildConfig can only be patched when connected to an OpenShift cluster"); } DoneableBuildConfig entity = openShiftClient.buildConfigs() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
private static EntityPatcher<Secret> secretPatcher() { return (KubernetesClient client, String namespace, Secret newObj, Secret oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneableSecret entity = client.secrets() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getData(), oldObj.getData())) { entity.withData(newObj.getData()); } if(!UserConfigurationCompare.configEqual(newObj.getStringData(), oldObj.getStringData())) { entity.withStringData(newObj.getStringData()); } return entity.done(); }; }
private static EntityPatcher<Service> servicePatcher() { return (KubernetesClient client, String namespace, Service newObj, Service oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneableService entity = client.services() .inNamespace(namespace) .withName(newObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
private static EntityPatcher<Pod> podPatcher() { return (KubernetesClient client, String namespace, Pod newObj, Pod oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } DoneablePod entity = client.pods() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
private static EntityPatcher<ImageStream> isPatcher() { return (KubernetesClient client, String namespace, ImageStream newObj, ImageStream oldObj) -> { if (UserConfigurationCompare.configEqual(newObj, oldObj)) { return oldObj; } OpenShiftClient openShiftClient = OpenshiftHelper.asOpenShiftClient(client); if (openShiftClient == null) { throw new IllegalArgumentException("ImageStream can only be patched when connected to an OpenShift cluster"); } DoneableImageStream entity = openShiftClient.imageStreams() .inNamespace(namespace) .withName(oldObj.getMetadata().getName()) .edit(); if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) { entity.withMetadata(newObj.getMetadata()); } if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) { entity.withSpec(newObj.getSpec()); } return entity.done(); }; }
BuildConfig old = openShiftClient.buildConfigs().inNamespace(namespace).withName(id).get(); if (isRunning(old)) { if (UserConfigurationCompare.configEqual(entity, old)) { log.info("BuildConfig has not changed so not doing anything"); } else {
if (UserConfigurationCompare.configEqual(secret, old)) { log.info("Secret has not changed so not doing anything"); return;
if (UserConfigurationCompare.configEqual(service, old)) { log.info("Service has not changed so not doing anything"); } else {
if (UserConfigurationCompare.configEqual(pod, old)) { log.info("Pod has not changed so not doing anything"); } else {
RoleBinding old = openShiftClient.roleBindings().inNamespace(namespace).withName(id).get(); if (isRunning(old)) { if (UserConfigurationCompare.configEqual(entity, old)) { log.info("RoleBinding has not changed so not doing anything"); } else {
if (UserConfigurationCompare.configEqual(resource, old)) { log.info(kind + " has not changed so not doing anything"); } else {
return; if (UserConfigurationCompare.configEqual(entity, old)) { log.info("OAuthClient has not changed so not doing anything"); } else {
if (UserConfigurationCompare.configEqual(serviceAccount, old)) { log.info("ServiceAccount has not changed so not doing anything"); } else {
if (UserConfigurationCompare.configEqual(entity, old)) { log.info("PersistentVolumeClaim has not changed so not doing anything"); } else {