uds5501 commented on code in PR #18413:
URL: https://github.com/apache/druid/pull/18413#discussion_r2293422920
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/k8s/K3sDruidService.java:
##########
@@ -67,22 +91,51 @@ public String createManifestYaml(String druidImage)
{
try {
final String template = Files.readString(
- Resources.getFileForResource(MANIFEST_TEMPLATE).toPath()
+ Resources.getFileForResource(manifestTemplate).toPath()
);
String manifest = StringUtils.replace(template, "${service}", getName());
manifest = StringUtils.replace(manifest, "${command}",
command.getName());
- manifest = StringUtils.replace(manifest, "${port}",
String.valueOf(command.getExposedPorts()[0]));
+ String port = isGovernedByOperator
+ ? String.valueOf(command.getExposedOperatorPort())
+ : String.valueOf(command.getExposedPorts()[0]);
+ manifest = StringUtils.replace(manifest, "${port}", port);
manifest = StringUtils.replace(manifest, "${image}", druidImage);
manifest = StringUtils.replace(manifest, "${serviceFolder}",
getServicePropsFolder());
+ if (isGovernedByOperator) {
+ manifest = replaceOperatorVariables(manifest);
+ }
return manifest;
}
catch (Exception e) {
throw new ISE(e, "Could not create manifest for service[%s]", command);
}
}
+ private String replaceOperatorVariables(String manifest)
+ {
+ String hostname = EmbeddedHostname.containerFriendly().toString();
+ this.properties.setProperty("druid.host", hostname);
+
+ String nodePropertiesString = prepareNodePropertiesString(this.properties);
+ manifest = StringUtils.replace(manifest, "${nodeRuntimeProperties}",
nodePropertiesString);
+
+ for (Map.Entry<String, String> entry :
operatorVariablesTemplate.entrySet()) {
+ manifest = StringUtils.replace(manifest, "${" + entry.getKey() + "}",
entry.getValue());
+ }
+ return manifest;
+ }
+
+ private String prepareNodePropertiesString(Properties nodeProperties)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (String key : nodeProperties.stringPropertyNames()) {
+ sb.append("
").append(key).append("=").append(nodeProperties.getProperty(key)).append("\n");
+ }
+ return sb.toString().trim(); // Remove trailing newline
Review Comment:
Probably not, I need to make a valid yaml, I don't see how it'll handle the
required indentation.
Yup. Doesn't work for some reason the runtime bit cries. Used a different
builder. (however there i am not indenting and the tests are working so not too
sure)
Edit: Nope, indentation was indeed required to get the yaml working.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]