PvcOperator extends AbstractResourceOperator<KubernetesClient, PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> { protected void revertImmutableChanges(PersistentVolumeClaim current, PersistentVolumeClaim desired) { desired.getSpec().setVolumeName(current.getSpec().getVolumeName()); desired.getSpec().setStorageClassName(current.getSpec().getStorageClassName()); desired.getSpec().setAccessModes(current.getSpec().getAccessModes()); desired.getSpec().setSelector(current.getSpec().getSelector()); desired.getSpec().setDataSource(current.getSpec().getDataSource()); } PvcOperator(Vertx vertx, KubernetesClient client);   }
@Test public void testRevertingImmutableFields() { PersistentVolumeClaim desired = new PersistentVolumeClaimBuilder() .withNewMetadata() .withName("my-pvc") .withNamespace("my-namespace") .endMetadata() .withNewSpec() .withNewResources() .withRequests(Collections.singletonMap("storage", new Quantity("100", null))) .endResources() .endSpec() .build(); PersistentVolumeClaim current = new PersistentVolumeClaimBuilder() .withNewMetadata() .withName("my-pvc") .withNamespace("my-namespace") .endMetadata() .withNewSpec() .withAccessModes("ReadWriteOnce") .withNewResources() .withRequests(Collections.singletonMap("storage", new Quantity("10", null))) .endResources() .withStorageClassName("my-storage-class") .withSelector(new LabelSelector(null, Collections.singletonMap("key", "label"))) .withVolumeName("pvc-ce9ebf52-435a-11e9-8fbc-06b5ff7c7748") .endSpec() .build(); PvcOperator op = createResourceOperations(vertx, mock(KubernetesClient.class)); op.revertImmutableChanges(current, desired); assertThat(current.getSpec().getStorageClassName(), is(desired.getSpec().getStorageClassName())); assertThat(current.getSpec().getAccessModes(), is(desired.getSpec().getAccessModes())); assertThat(current.getSpec().getSelector(), is(desired.getSpec().getSelector())); assertThat(current.getSpec().getVolumeName(), is(desired.getSpec().getVolumeName())); }