use of com.tsystemsmms.cmcc.cmccoperator.targetstate.TargetState in project cmcc-operator by T-Systems-MMS.
the class CoreMediaContentCloudReconciler method reconcile.
@Override
public UpdateControl<CoreMediaContentCloud> reconcile(CoreMediaContentCloud cmcc, Context context) {
cmcc = Utils.deepClone(cmcc, CoreMediaContentCloud.class);
CoreMediaContentCloudStatus status = cmcc.getStatus();
// create new desired state and its resources
TargetState targetState = targetStateFactory.buildTargetState(cmcc);
List<HasMetadata> newResources = targetState.buildResources();
// compute resources no longer desired
Set<ResourceRef> ownedResourceRefs = newResources.stream().map(ResourceRef::new).collect(Collectors.toSet());
Set<ResourceRef> abandonedResourceRefs = ResourceRef.fromJson(status.getOwnedResourceRefs());
abandonedResourceRefs.removeAll(ownedResourceRefs);
log.info("Updating dependent resource of cmcc {}: {} new/updated, {} abandoned resources, milestone {}", cmcc.getMetadata().getName(), newResources.size(), abandonedResourceRefs.size(), status.getMilestone());
// apply new and updated resources
KubernetesList list = new KubernetesListBuilder().withItems(newResources).build();
resourceReconcilerManager.createPatchUpdate(cmcc.getMetadata().getNamespace(), list);
// remove resources no longer in desired state
deleteResources(cmcc.getMetadata().getNamespace(), abandonedResourceRefs);
// save state
status.setOwnedResourceRefs(ResourceRef.toJson(ownedResourceRefs));
status.setError("");
status.setErrorMessage("");
cmcc.setStatus(status);
return UpdateControl.updateStatus(cmcc);
}
Aggregations