Search in sources :

Example 1 with CoreMediaContentCloudStatus

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);
}
Also used : TargetState(com.tsystemsmms.cmcc.cmccoperator.targetstate.TargetState) CoreMediaContentCloud(com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloud) CoreMediaContentCloudStatus(com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus)

Example 2 with CoreMediaContentCloudStatus

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();
}
Also used : CoreMediaContentCloudStatus(com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus)

Example 3 with CoreMediaContentCloudStatus

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);
}
Also used : CoreMediaContentCloudStatus(com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus)

Aggregations

CoreMediaContentCloudStatus (com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloudStatus)3 CoreMediaContentCloud (com.tsystemsmms.cmcc.cmccoperator.crds.CoreMediaContentCloud)1 TargetState (com.tsystemsmms.cmcc.cmccoperator.targetstate.TargetState)1