InitWriter { public boolean writeExternalAddress() { List<NodeAddress> addresses = client.nodes().withName(config.getNodeName()).get().getStatus().getAddresses(); StringBuilder externalAddresses = new StringBuilder(); String address = NodeUtils.findAddress(addresses, null); if (address == null) { log.error("External address not found"); return false; } else { log.info("Default External address found {}", address); externalAddresses.append(externalAddressExport(null, address)); } for (NodeAddressType type : NodeAddressType.values()) { address = NodeUtils.findAddress(addresses, type); log.info("External {} address found {}", type.toValue(), address); externalAddresses.append(externalAddressExport(type, address)); } return write(FILE_EXTERNAL_ADDRESS, externalAddresses.toString()); } InitWriter(KubernetesClient client, InitWriterConfig config); boolean writeRack(); boolean writeExternalAddress();  }
@Test public void testWriteExternalAddress() throws IOException { File kafkaFolder = new File(tempDir.getPath(), "/opt/kafka"); String addressFolder = kafkaFolder.getAbsolutePath() + "/external.address"; new File(addressFolder).mkdirs(); Map<String, String> envVars = new HashMap<>(InitWriterTest.envVars); envVars.put(InitWriterConfig.INIT_FOLDER, addressFolder); InitWriterConfig config = InitWriterConfig.fromMap(envVars); KubernetesClient client = mockKubernetesClient(config.getNodeName(), Collections.EMPTY_MAP, addresses); InitWriter writer = new InitWriter(client, config); assertThat(writer.writeExternalAddress(), is(true)); assertThat(readFile(addressFolder + "/external.address"), is("export STRIMZI_NODEPORT_DEFAULT_ADDRESS=my.external.address\n" + "export STRIMZI_NODEPORT_EXTERNALIP_ADDRESS=my.external.address\n" + "export STRIMZI_NODEPORT_EXTERNALDNS_ADDRESS=my.external.address\n" + "export STRIMZI_NODEPORT_INTERNALIP_ADDRESS=192.168.2.94\n" + "export STRIMZI_NODEPORT_INTERNALDNS_ADDRESS=my.internal.address\n" + "export STRIMZI_NODEPORT_HOSTNAME_ADDRESS=my.external.address\n")); }