use of com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus 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);
}
use of com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus in project cmcc-operator by T-Systems-MMS.
the class CoreMediaContentCloudReconciler method cleanup.
@Override
public DeleteControl cleanup(CoreMediaContentCloud cmcc, Context context) {
CoreMediaContentCloudStatus status = new CoreMediaContentCloudStatus();
Set<ResourceRef> abandonedResourceRefs = ResourceRef.fromJson(cmcc.getStatus().getOwnedResourceRefs());
log.info("Deleting dependent resource of cmcc \"{}\": {} abandoned resources", cmcc.getMetadata().getName(), abandonedResourceRefs.size());
deleteResources(cmcc.getMetadata().getNamespace(), abandonedResourceRefs);
status.setOwnedResourceRefs("[]");
cmcc.setStatus(status);
return DeleteControl.defaultDelete();
}
use of com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus in project cmcc-operator by T-Systems-MMS.
the class CoreMediaContentCloudReconciler method updateErrorStatus.
@Override
public Optional<CoreMediaContentCloud> updateErrorStatus(CoreMediaContentCloud resource, RetryInfo retryInfo, RuntimeException e) {
CoreMediaContentCloudStatus status = resource.getStatus();
status.setErrorMessage(e.getMessage());
status.setError("error");
return Optional.of(resource);
}
Aggregations