Search in sources :

Example 1 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment 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)

Example 2 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonDeploymentControllerImpl method removeDeployments.

private void removeDeployments(ProtoClient client, String namespace, SeldonDeployment seldonDeployment, List<Deployment> deployments) throws ApiException, IOException, SeldonDeploymentException {
    Set<String> names = getDeploymentNames(deployments);
    ExtensionsV1beta1DeploymentList depList = crdHandler.getOwnedDeployments(seldonDeployment.getSpec().getName());
    for (ExtensionsV1beta1Deployment d : depList.getItems()) {
        if (!names.contains(d.getMetadata().getName())) {
            final String deleteApiPath = "/apis/" + DEPLOYMENT_API_VERSION + "/namespaces/{namespace}/deployments/{name}".replaceAll("\\{" + "name" + "\\}", client.getApiClient().escapeString(d.getMetadata().getName())).replaceAll("\\{" + "namespace" + "\\}", client.getApiClient().escapeString(namespace));
            DeleteOptions options = DeleteOptions.newBuilder().setPropagationPolicy("Foreground").build();
            ObjectOrStatus<Deployment> os = client.delete(Deployment.newBuilder(), deleteApiPath, options);
            if (os.status != null) {
                logger.error("Error deleting deployment:" + ProtoBufUtils.toJson(os.status));
                throw new SeldonDeploymentException("Failed to delete deployment " + d.getMetadata().getName());
            } else {
                logger.debug("Deleted deployment:" + ProtoBufUtils.toJson(os.object));
            }
        }
    }
}
Also used : DeleteOptions(io.kubernetes.client.proto.Meta.DeleteOptions) ExtensionsV1beta1DeploymentList(io.kubernetes.client.models.ExtensionsV1beta1DeploymentList) ExtensionsV1beta1Deployment(io.kubernetes.client.models.ExtensionsV1beta1Deployment) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) Deployment(io.kubernetes.client.proto.V1beta1Extensions.Deployment) ExtensionsV1beta1Deployment(io.kubernetes.client.models.ExtensionsV1beta1Deployment)

Example 3 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonDeploymentOperatorImpl method defaulting.

@Override
public SeldonDeployment defaulting(SeldonDeployment mlDep) {
    SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder(mlDep);
    int idx = 0;
    String serviceName = mlDep.getSpec().getName();
    String deploymentName = mlDep.getMetadata().getName();
    for (PredictorSpec p : mlDep.getSpec().getPredictorsList()) {
        ObjectMeta.Builder metaBuilder = ObjectMeta.newBuilder(p.getComponentSpec().getMetadata()).putLabels(LABEL_SELDON_APP, serviceName);
        mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().setMetadata(metaBuilder);
        int cIdx = 0;
        mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().clearContainers();
        String predictorName = p.getName();
        for (V1.Container c : p.getComponentSpec().getSpec().getContainersList()) {
            V1.Container c2 = this.updateContainer(c, findPredictiveUnitForContainer(mlDep.getSpec().getPredictors(idx).getGraph(), c.getName()), cIdx, deploymentName, predictorName);
            mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().addContainers(cIdx, c2);
            updatePredictiveUnitBuilderByName(mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getGraphBuilder(), c2);
            cIdx++;
        }
        idx++;
    }
    return mlBuilder.build();
}
Also used : ObjectMeta(io.kubernetes.client.proto.Meta.ObjectMeta) IntOrString(io.kubernetes.client.proto.IntStr.IntOrString) V1(io.kubernetes.client.proto.V1) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) Endpoint(io.seldon.protos.DeploymentProtos.Endpoint) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec)

Example 4 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonDeploymentStatusUpdateImpl method removeStatus.

@Override
public void removeStatus(String mlDepName, String depName) {
    logger.info(String.format("DELETE %s : %s", mlDepName, depName));
    SeldonDeployment mlDep = crdHandler.getSeldonDeployment(mlDepName);
    if (mlDep != null) {
        SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder(mlDep);
        int idx = 0;
        for (PredictorStatus.Builder b : mlBuilder.getStatusBuilder().getPredictorStatusBuilderList()) {
            if (b.getName().equals(depName)) {
                mlBuilder.getStatusBuilder().removePredictorStatus(idx);
                break;
            }
        }
        crdHandler.updateSeldonDeployment(mlBuilder.build());
    } else
        logger.error("Can't find seldondeployment " + mlDepName + " to remove " + depName);
}
Also used : PredictorStatus(io.seldon.protos.DeploymentProtos.PredictorStatus) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment)

Example 5 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class AuthorizationServerConfiguration method configure.

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.withClientDetails(clientDetailsService);
    String client_key = System.getenv().get(TEST_CLIENT_KEY);
    // Create Fake seldon deployment for testing
    if (client_key != null) {
        String client_secret = System.getenv().get(TEST_CLIENT_SECRET);
        clientDetailsService.addClient(client_key, client_secret);
        SeldonDeployment dep = SeldonDeployment.newBuilder().setApiVersion("v1alpha1").setKind("SeldonDeplyment").setSpec(DeploymentSpec.newBuilder().setName("localhost").setOauthKey(client_key).setOauthSecret(client_secret)).build();
        deploymentStore.deploymentAdded(dep);
    }
}
Also used : SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment)

Aggregations

SeldonDeployment (io.seldon.protos.DeploymentProtos.SeldonDeployment)15 AppTest (io.seldon.clustermanager.AppTest)5 Test (org.junit.Test)5 IntOrString (io.kubernetes.client.proto.IntStr.IntOrString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ApiException (io.kubernetes.client.ApiException)2 Deployment (io.kubernetes.client.proto.V1beta1Extensions.Deployment)2 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)2 PredictorStatus (io.seldon.protos.DeploymentProtos.PredictorStatus)2 IOException (java.io.IOException)2 ApiClient (io.kubernetes.client.ApiClient)1 ProtoClient (io.kubernetes.client.ProtoClient)1 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)1 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)1 ExtensionsV1beta1DeploymentList (io.kubernetes.client.models.ExtensionsV1beta1DeploymentList)1 V1OwnerReference (io.kubernetes.client.models.V1OwnerReference)1 DeleteOptions (io.kubernetes.client.proto.Meta.DeleteOptions)1 ObjectMeta (io.kubernetes.client.proto.Meta.ObjectMeta)1 OwnerReference (io.kubernetes.client.proto.Meta.OwnerReference)1 V1 (io.kubernetes.client.proto.V1)1