Search in sources :

Example 1 with Deployment

use of io.kubernetes.client.proto.V1beta1Extensions.Deployment in project seldon-core by SeldonIO.

the class SeldonDeploymentControllerImpl method createDeployments.

private void createDeployments(ProtoClient client, String namespace, List<Deployment> deployments) throws ApiException, IOException, SeldonDeploymentException {
    for (Deployment d : deployments) {
        final String listApiPath = "/apis/" + DEPLOYMENT_API_VERSION + "/namespaces/{namespace}/deployments/{name}".replaceAll("\\{" + "name" + "\\}", client.getApiClient().escapeString(d.getMetadata().getName())).replaceAll("\\{" + "namespace" + "\\}", client.getApiClient().escapeString(namespace));
        logger.debug("Will try to call LIST " + listApiPath);
        ObjectOrStatus<Deployment> os = client.list(Deployment.newBuilder(), listApiPath);
        if (os.status != null) {
            if (os.status.getCode() == 404) {
                // Create
                logger.debug("About to CREATE " + ProtoBufUtils.toJson(d));
                final String createApiPath = "/apis/" + DEPLOYMENT_API_VERSION + "/namespaces/{namespace}/deployments".replaceAll("\\{" + "namespace" + "\\}", client.getApiClient().escapeString(namespace));
                os = client.create(d, createApiPath, DEPLOYMENT_API_VERSION, "Deployment");
                if (os.status != null) {
                    logger.error("Error creating deployment:" + ProtoBufUtils.toJson(os.status));
                    throw new SeldonDeploymentException("Failed to create deployment " + d.getMetadata().getName());
                } else {
                    logger.debug("Created deployment:" + ProtoBufUtils.toJson(os.object));
                }
            } else {
                logger.error("Error listing deployment:" + ProtoBufUtils.toJson(os.status));
                throw new SeldonDeploymentException("Failed to list deployment " + d.getMetadata().getName());
            }
        } else {
            // Update
            logger.debug("About to UPDATE " + ProtoBufUtils.toJson(d));
            os = client.update(d, listApiPath, DEPLOYMENT_API_VERSION, "Deployment");
            if (os.status != null) {
                logger.error("Error updating deployment:" + ProtoBufUtils.toJson(os.status));
                throw new SeldonDeploymentException("Failed to update deployment " + d.getMetadata().getName());
            } else {
                logger.debug("Updated deployment:" + ProtoBufUtils.toJson(os.object));
            }
        }
    }
}
Also used : SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) Deployment(io.kubernetes.client.proto.V1beta1Extensions.Deployment) ExtensionsV1beta1Deployment(io.kubernetes.client.models.ExtensionsV1beta1Deployment)

Example 2 with Deployment

use of io.kubernetes.client.proto.V1beta1Extensions.Deployment 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 Deployment

use of io.kubernetes.client.proto.V1beta1Extensions.Deployment in project seldon-core by SeldonIO.

the class SeldonDeploymentOperatorImpl method createResources.

@Override
public DeploymentResources createResources(SeldonDeployment mlDep) throws SeldonDeploymentException {
    OwnerReference ownerRef = getOwnerReference(mlDep);
    List<Deployment> deployments = new ArrayList<>();
    // for each predictor Create/replace deployment
    String serviceLabel = mlDep.getSpec().getName();
    for (PredictorSpec p : mlDep.getSpec().getPredictorsList()) {
        String depName = getKubernetesDeploymentName(mlDep.getSpec().getName(), p.getName());
        PodTemplateSpec.Builder podSpecBuilder = PodTemplateSpec.newBuilder(p.getComponentSpec());
        podSpecBuilder.getSpecBuilder().addContainers(createEngineContainer(mlDep, p)).setTerminationGracePeriodSeconds(20);
        podSpecBuilder.getMetadataBuilder().putAnnotations("prometheus.io/path", "/prometheus").putAnnotations("prometheus.io/port", "" + clusterManagerProperites.getEngineContainerPort()).putAnnotations("prometheus.io/scrape", "true");
        Deployment deployment = V1beta1Extensions.Deployment.newBuilder().setMetadata(ObjectMeta.newBuilder().setName(depName).putLabels(SeldonDeploymentOperatorImpl.LABEL_SELDON_APP, serviceLabel).putLabels(Constants.LABEL_SELDON_ID, mlDep.getSpec().getName()).putLabels("app", depName).putLabels("version", // FIXME
        "v1").putLabels(SeldonDeploymentOperatorImpl.LABEL_SELDON_TYPE_KEY, SeldonDeploymentOperatorImpl.LABEL_SELDON_TYPE_VAL).addOwnerReferences(ownerRef)).setSpec(DeploymentSpec.newBuilder().setTemplate(podSpecBuilder.build()).setStrategy(DeploymentStrategy.newBuilder().setRollingUpdate(RollingUpdateDeployment.newBuilder().setMaxUnavailable(IntOrString.newBuilder().setType(1).setStrVal("10%")))).setReplicas(p.getReplicas())).build();
        deployments.add(deployment);
    }
    final String serviceName = mlDep.getSpec().getName();
    Service s = Service.newBuilder().setMetadata(ObjectMeta.newBuilder().setName(serviceName).putLabels(SeldonDeploymentOperatorImpl.LABEL_SELDON_APP, serviceLabel).putLabels("seldon-deployment-id", mlDep.getSpec().getName()).addOwnerReferences(ownerRef).putAnnotations("getambassador.io/config", getAmbassadorAnnotation(mlDep, serviceName))).setSpec(ServiceSpec.newBuilder().addPorts(ServicePort.newBuilder().setProtocol("TCP").setPort(clusterManagerProperites.getEngineContainerPort()).setTargetPort(IntOrString.newBuilder().setIntVal(clusterManagerProperites.getEngineContainerPort())).setName("http")).addPorts(ServicePort.newBuilder().setProtocol("TCP").setPort(clusterManagerProperites.getEngineGrpcContainerPort()).setTargetPort(IntOrString.newBuilder().setIntVal(clusterManagerProperites.getEngineGrpcContainerPort())).setName("grpc")).setType("ClusterIP").putSelector(SeldonDeploymentOperatorImpl.LABEL_SELDON_APP, serviceLabel)).build();
    // Create service for deployment
    return new DeploymentResources(deployments, s);
}
Also used : V1OwnerReference(io.kubernetes.client.models.V1OwnerReference) OwnerReference(io.kubernetes.client.proto.Meta.OwnerReference) PodTemplateSpec(io.kubernetes.client.proto.V1.PodTemplateSpec) ArrayList(java.util.ArrayList) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) Deployment(io.kubernetes.client.proto.V1beta1Extensions.Deployment) RollingUpdateDeployment(io.kubernetes.client.proto.V1beta1Extensions.RollingUpdateDeployment) Service(io.kubernetes.client.proto.V1.Service) IntOrString(io.kubernetes.client.proto.IntStr.IntOrString) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec)

Aggregations

Deployment (io.kubernetes.client.proto.V1beta1Extensions.Deployment)3 SeldonDeployment (io.seldon.protos.DeploymentProtos.SeldonDeployment)3 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)2 ExtensionsV1beta1DeploymentList (io.kubernetes.client.models.ExtensionsV1beta1DeploymentList)1 V1OwnerReference (io.kubernetes.client.models.V1OwnerReference)1 IntOrString (io.kubernetes.client.proto.IntStr.IntOrString)1 DeleteOptions (io.kubernetes.client.proto.Meta.DeleteOptions)1 OwnerReference (io.kubernetes.client.proto.Meta.OwnerReference)1 PodTemplateSpec (io.kubernetes.client.proto.V1.PodTemplateSpec)1 Service (io.kubernetes.client.proto.V1.Service)1 RollingUpdateDeployment (io.kubernetes.client.proto.V1beta1Extensions.RollingUpdateDeployment)1 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)1 ArrayList (java.util.ArrayList)1