Combine VmDefinitionModel and VmDefinition.
This commit is contained in:
parent
b250398213
commit
85a4521299
16 changed files with 121 additions and 206 deletions
|
|
@ -10,7 +10,7 @@ metadata:
|
|||
annotations:
|
||||
vmoperator.jdrupes.org/version: ${ managerVersion }
|
||||
ownerReferences:
|
||||
- apiVersion: ${ cr.apiVersion }
|
||||
- apiVersion: ${ cr.apiVersion() }
|
||||
kind: ${ constants.VM_OP_KIND_VM }
|
||||
name: ${ cr.name() }
|
||||
uid: ${ cr.metadata().getUid() }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ metadata:
|
|||
annotations:
|
||||
vmoperator.jdrupes.org/version: ${ managerVersion }
|
||||
ownerReferences:
|
||||
- apiVersion: ${ cr.apiVersion }
|
||||
- apiVersion: ${ cr.apiVersion() }
|
||||
kind: ${ constants.VM_OP_KIND_VM }
|
||||
name: ${ cr.name() }
|
||||
uid: ${ cr.metadata().getUid() }
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ metadata:
|
|||
vmrunner.jdrupes.org/cmVersion: "${ cm.metadata.resourceVersion }"
|
||||
vmoperator.jdrupes.org/version: ${ managerVersion }
|
||||
ownerReferences:
|
||||
- apiVersion: ${ cr.apiVersion }
|
||||
- apiVersion: ${ cr.apiVersion() }
|
||||
kind: ${ constants.VM_OP_KIND_VM }
|
||||
name: ${ cr.name() }
|
||||
uid: ${ cr.metadata().getUid() }
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ public class Controller extends Component {
|
|||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
vmDef.namespace(), vmDef.name());
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.status();
|
||||
JsonObject status = from.statusJson();
|
||||
var assignment = GsonPtr.to(status).to("assignment");
|
||||
assignment.set("pool", event.usedPool());
|
||||
assignment.set("user", event.toUser());
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ public class DisplaySecretMonitor
|
|||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
event.vmDefinition().namespace(), event.vmDefinition().name());
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.status();
|
||||
JsonObject status = from.statusJson();
|
||||
status.addProperty("consoleUser", event.user());
|
||||
return status;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -187,7 +187,8 @@ public class PoolMonitor extends
|
|||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
vmDef.namespace(), vmDef.name());
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.status();
|
||||
// TODO
|
||||
JsonObject status = from.statusJson();
|
||||
var assignment = GsonPtr.to(status).to("assignment");
|
||||
assignment.set("lastUsed", ccChange.get().toString());
|
||||
return status;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import org.jdrupes.vmoperator.common.K8sV1ConfigMapStub;
|
|||
import org.jdrupes.vmoperator.common.K8sV1PodStub;
|
||||
import org.jdrupes.vmoperator.common.K8sV1StatefulSetStub;
|
||||
import org.jdrupes.vmoperator.common.VmDefinition;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionModel;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionModels;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||
import org.jdrupes.vmoperator.common.VmPool;
|
||||
|
|
@ -65,7 +64,7 @@ import org.jgrapes.core.annotation.Handler;
|
|||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
||||
public class VmMonitor extends
|
||||
AbstractMonitor<VmDefinitionModel, VmDefinitionModels, VmChannel> {
|
||||
AbstractMonitor<VmDefinition, VmDefinitionModels, VmChannel> {
|
||||
|
||||
private final ChannelManager<String, VmChannel, ?> channelManager;
|
||||
|
||||
|
|
@ -77,7 +76,7 @@ public class VmMonitor extends
|
|||
*/
|
||||
public VmMonitor(Channel componentChannel,
|
||||
ChannelManager<String, VmChannel, ?> channelManager) {
|
||||
super(componentChannel, VmDefinitionModel.class,
|
||||
super(componentChannel, VmDefinition.class,
|
||||
VmDefinitionModels.class);
|
||||
this.channelManager = channelManager;
|
||||
}
|
||||
|
|
@ -122,7 +121,7 @@ public class VmMonitor extends
|
|||
|
||||
@Override
|
||||
protected void handleChange(K8sClient client,
|
||||
Watch.Response<VmDefinitionModel> response) {
|
||||
Watch.Response<VmDefinition> response) {
|
||||
V1ObjectMeta metadata = response.object.getMetadata();
|
||||
AtomicBoolean toBeAdded = new AtomicBoolean(false);
|
||||
VmChannel channel = channelManager.channel(metadata.getName())
|
||||
|
|
@ -132,21 +131,17 @@ public class VmMonitor extends
|
|||
});
|
||||
|
||||
// Get full definition and associate with channel as backup
|
||||
var vmModel = response.object;
|
||||
if (vmModel.data() == null) {
|
||||
var vmDef = response.object;
|
||||
if (vmDef.data() == null) {
|
||||
// ADDED event does not provide data, see
|
||||
// https://github.com/kubernetes-client/java/issues/3215
|
||||
vmModel = getModel(client, vmModel);
|
||||
vmDef = getModel(client, vmDef);
|
||||
}
|
||||
VmDefinition vmDef = null;
|
||||
if (vmModel.data() != null) {
|
||||
if (vmDef.data() != null) {
|
||||
// New data, augment and save
|
||||
vmDef = client.getJSON().getGson().fromJson(vmModel.data(),
|
||||
VmDefinition.class);
|
||||
addDynamicData(channel.client(), vmDef, channel.vmDefinition());
|
||||
channel.setVmDefinition(vmDef);
|
||||
}
|
||||
if (vmDef == null) {
|
||||
} else {
|
||||
// Reuse cached (e.g. if deleted)
|
||||
vmDef = channel.vmDefinition();
|
||||
}
|
||||
|
|
@ -173,8 +168,7 @@ public class VmMonitor extends
|
|||
channel.pipeline().fire(chgEvt, channel);
|
||||
}
|
||||
|
||||
private VmDefinitionModel getModel(K8sClient client,
|
||||
VmDefinitionModel vmDef) {
|
||||
private VmDefinition getModel(K8sClient client, VmDefinition vmDef) {
|
||||
try {
|
||||
return VmDefinitionStub.get(client, context(), namespace(),
|
||||
vmDef.metadata().getName()).model().orElse(null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue