use of com.redhat.service.smartevents.shard.operator.networking.NetworkResource in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeIngressController method reconcile.
@Override
public UpdateControl<BridgeIngress> reconcile(BridgeIngress bridgeIngress, Context context) {
LOGGER.debug("Create or update BridgeIngress: '{}' in namespace '{}'", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
Secret secret = bridgeIngressService.fetchBridgeIngressSecret(bridgeIngress);
if (secret == null) {
LOGGER.debug("Secrets for the BridgeIngress '{}' have been not created yet.", bridgeIngress.getMetadata().getName());
return UpdateControl.noUpdate();
}
// Check if the image of the ingress has to be updated
String image = bridgeIngressService.getIngressImage();
if (!image.equals(bridgeIngress.getSpec().getImage())) {
bridgeIngress.getSpec().setImage(image);
return UpdateControl.updateResource(bridgeIngress);
}
Deployment deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(bridgeIngress, secret);
if (!Readiness.isDeploymentReady(deployment)) {
LOGGER.debug("Ingress deployment BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
bridgeIngress.getStatus().setConditionsFromDeployment(deployment);
if (DeploymentStatusUtils.isTimeoutFailure(deployment)) {
notifyDeploymentFailure(bridgeIngress, DeploymentStatusUtils.getReasonAndMessageForTimeoutFailure(deployment));
} else if (DeploymentStatusUtils.isStatusReplicaFailure(deployment)) {
notifyDeploymentFailure(bridgeIngress, DeploymentStatusUtils.getReasonAndMessageForReplicaFailure(deployment));
}
return UpdateControl.updateStatus(bridgeIngress);
}
LOGGER.debug("Ingress deployment BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
// Create Service
Service service = bridgeIngressService.fetchOrCreateBridgeIngressService(bridgeIngress, deployment);
if (service.getStatus() == null) {
LOGGER.debug("Ingress service BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready);
bridgeIngress.getStatus().markConditionTrue(ConditionType.Augmentation, ConditionReason.ServiceNotReady);
return UpdateControl.updateStatus(bridgeIngress);
}
LOGGER.debug("Ingress service BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
// Create Route
NetworkResource networkResource = networkingService.fetchOrCreateNetworkIngress(bridgeIngress, service);
if (!networkResource.isReady()) {
LOGGER.debug("Ingress networking resource BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready);
bridgeIngress.getStatus().markConditionTrue(ConditionType.Augmentation, ConditionReason.NetworkResourceNotReady);
return UpdateControl.updateStatus(bridgeIngress);
}
LOGGER.debug("Ingress networking resource BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
Optional<ServiceMonitor> serviceMonitor = monitorService.fetchOrCreateServiceMonitor(bridgeIngress, service, BridgeIngress.COMPONENT_NAME);
if (serviceMonitor.isPresent()) {
// this is an optional resource
LOGGER.debug("Ingress monitor resource BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
} else {
LOGGER.warn("Ingress monitor resource BridgeIngress: '{}' in namespace '{}' is failed to deploy, Prometheus not installed.", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
BridgeError prometheusNotAvailableError = bridgeErrorService.getError(PrometheusNotInstalledException.class).orElseThrow(() -> new RuntimeException("PrometheusNotInstalledException not found in error catalog"));
bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready, ConditionReason.PrometheusUnavailable, prometheusNotAvailableError.getReason(), prometheusNotAvailableError.getCode());
notifyManager(bridgeIngress, ManagedResourceStatus.FAILED);
return UpdateControl.updateStatus(bridgeIngress);
}
if (!bridgeIngress.getStatus().isReady() || !networkResource.getEndpoint().equals(bridgeIngress.getStatus().getEndpoint())) {
bridgeIngress.getStatus().setEndpoint(networkResource.getEndpoint());
bridgeIngress.getStatus().markConditionTrue(ConditionType.Ready);
bridgeIngress.getStatus().markConditionFalse(ConditionType.Augmentation);
notifyManager(bridgeIngress, ManagedResourceStatus.READY);
return UpdateControl.updateStatus(bridgeIngress);
}
return UpdateControl.noUpdate();
}
Aggregations