ServiceOperator extends AbstractResourceOperator<KubernetesClient, Service, ServiceList, DoneableService, ServiceResource<Service, DoneableService>> { protected void patchNodePorts(Service current, Service desired) { for (ServicePort desiredPort : desired.getSpec().getPorts()) { String portName = desiredPort.getName(); for (ServicePort currentPort : current.getSpec().getPorts()) { if (desiredPort.getNodePort() == null && portName.equals(currentPort.getName()) && currentPort.getNodePort() != null) { desiredPort.setNodePort(currentPort.getNodePort()); } } } } ServiceOperator(Vertx vertx, KubernetesClient client); Future<Void> endpointReadiness(String namespace, String name, long pollInterval, long operationTimeoutMs); Future<Void> hasIngressAddress(String namespace, String name, long pollIntervalMs, long timeoutMs); boolean isIngressAddressReady(String namespace, String name); Future<Void> hasNodePort(String namespace, String name, long pollIntervalMs, long timeoutMs); boolean isNodePortReady(String namespace, String name);  }
@Test public void testNodePortPatching() { KubernetesClient client = mock(KubernetesClient.class); Service current = new ServiceBuilder() .withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withType("NodePort") .withPorts( new ServicePortBuilder() .withName("port1") .withPort(1234) .withTargetPort(new IntOrString(1234)) .withNodePort(31234) .build(), new ServicePortBuilder() .withName("port2") .withPort(5678) .withTargetPort(new IntOrString(5678)) .withNodePort(35678) .build() ) .endSpec() .build(); Service desired = new ServiceBuilder() .withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withType("NodePort") .withPorts( new ServicePortBuilder() .withName("port2") .withPort(5678) .withTargetPort(new IntOrString(5678)) .build(), new ServicePortBuilder() .withName("port1") .withPort(1234) .withTargetPort(new IntOrString(1234)) .build() ) .endSpec() .build(); ServiceOperator op = new ServiceOperator(vertx, client); op.patchNodePorts(current, desired); assertThat(current.getSpec().getPorts().get(0).getNodePort(), is(desired.getSpec().getPorts().get(1).getNodePort())); assertThat(current.getSpec().getPorts().get(1).getNodePort(), is(desired.getSpec().getPorts().get(0).getNodePort())); }