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));
}
}
}
}
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));
}
}
}
}
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);
}
Aggregations