Add generation of fallback properties.
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
This commit is contained in:
parent
7835686304
commit
ee96f869da
2 changed files with 28 additions and 2 deletions
|
|
@ -14,6 +14,8 @@ spec:
|
|||
cpu: 1
|
||||
memory: 2Gi
|
||||
|
||||
cloudInit: {}
|
||||
|
||||
vm:
|
||||
# state: Running
|
||||
bootMenu: yes
|
||||
|
|
|
|||
|
|
@ -209,6 +209,15 @@ public class Reconciler extends Component {
|
|||
private DynamicKubernetesObject patchCr(DynamicKubernetesObject vmDef) {
|
||||
var json = vmDef.getRaw().deepCopy();
|
||||
// Adjust cdromImage path
|
||||
adjustCdRomPaths(json);
|
||||
|
||||
// Adjust cloud-init data
|
||||
adjustCloudInitData(json);
|
||||
|
||||
return new DynamicKubernetesObject(json);
|
||||
}
|
||||
|
||||
private void adjustCdRomPaths(JsonObject json) {
|
||||
var disks
|
||||
= GsonPtr.to(json).to("spec", "vm", "disks").get(JsonArray.class);
|
||||
for (var disk : disks) {
|
||||
|
|
@ -233,7 +242,23 @@ public class Reconciler extends Component {
|
|||
logger.warning(() -> "Invalid CDROM image: " + image);
|
||||
}
|
||||
}
|
||||
return new DynamicKubernetesObject(json);
|
||||
}
|
||||
|
||||
private void adjustCloudInitData(JsonObject json) {
|
||||
var spec = GsonPtr.to(json).to("spec").get(JsonObject.class);
|
||||
if (!spec.has("cloudInit")) {
|
||||
return;
|
||||
}
|
||||
var metaData = GsonPtr.to(spec).to("cloudInit", "metaData");
|
||||
if (metaData.getAsString("instance-id").isEmpty()) {
|
||||
metaData.set("instance-id",
|
||||
GsonPtr.to(json).getAsString("metadata", "resourceVersion")
|
||||
.map(s -> "v" + s).orElse("v1"));
|
||||
}
|
||||
if (metaData.getAsString("local-hostname").isEmpty()) {
|
||||
metaData.set("local-hostname",
|
||||
GsonPtr.to(json).getAsString("metadata", "name").get());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.CognitiveComplexity")
|
||||
|
|
@ -300,5 +325,4 @@ public class Reconciler extends Component {
|
|||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue