Search in sources :

Example 1 with DeploymentResources

use of io.seldon.clustermanager.k8s.SeldonDeploymentOperatorImpl.DeploymentResources in project seldon-core by SeldonIO.

the class SeldonDeploymentControllerImpl method createOrReplaceSeldonDeployment.

@Override
public void createOrReplaceSeldonDeployment(SeldonDeployment mlDep) {
    if (mlDep.hasStatus() && mlDep.getStatus().hasState() && mlDep.getStatus().getState().equals(FAILED_STATE_MSG)) {
        logger.warn("Ignoring failed deployment " + mlDep.getMetadata().getName());
        return;
    }
    try {
        SeldonDeployment existing = mlCache.get(mlDep.getMetadata().getName());
        if (existing == null || !existing.getSpec().equals(mlDep.getSpec())) {
            logger.debug("Running updates for " + mlDep.getMetadata().getName());
            SeldonDeployment mlDep2 = operator.defaulting(mlDep);
            operator.validate(mlDep2);
            mlCache.put(mlDep2);
            DeploymentResources resources = operator.createResources(mlDep2);
            ProtoClient client = clientProvider.getProtoClient();
            String namespace = getNamespace(mlDep2);
            createDeployments(client, namespace, resources.deployments);
            removeDeployments(client, namespace, mlDep2, resources.deployments);
            createService(client, namespace, resources.service);
            if (!mlDep.getSpec().equals(mlDep2.getSpec())) {
                logger.debug("Pushing updated SeldonDeployment " + mlDep2.getMetadata().getName() + " back to kubectl");
                crdHandler.updateSeldonDeployment(mlDep2);
            } else
                logger.debug("Not pushing an update as no change to spec for SeldonDeployment " + mlDep2.getMetadata().getName());
        } else {
            mlCache.put(mlDep);
            logger.debug("Only updated cache for " + mlDep.getMetadata().getName());
        }
    } catch (SeldonDeploymentException e) {
        logger.error("Failed to create deployment ", e);
        failDeployment(mlDep, e);
    } catch (ApiException e) {
        logger.error("Kubernetes API exception deploying code:" + e.getCode() + "message:" + e.getResponseBody(), e);
        failDeployment(mlDep, e);
    } catch (IOException e) {
        logger.error("IOException during createReplace ", e);
        failDeployment(mlDep, e);
    }
}
Also used : IOException(java.io.IOException) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) DeploymentResources(io.seldon.clustermanager.k8s.SeldonDeploymentOperatorImpl.DeploymentResources) ProtoClient(io.kubernetes.client.ProtoClient) ApiException(io.kubernetes.client.ApiException)

Aggregations

ApiException (io.kubernetes.client.ApiException)1 ProtoClient (io.kubernetes.client.ProtoClient)1 DeploymentResources (io.seldon.clustermanager.k8s.SeldonDeploymentOperatorImpl.DeploymentResources)1 SeldonDeployment (io.seldon.protos.DeploymentProtos.SeldonDeployment)1 IOException (java.io.IOException)1