Skip to content

Commit

Permalink
initial ksonnet update
Browse files Browse the repository at this point in the history
  • Loading branch information
ukclivecox committed Jul 14, 2018
1 parent 84eb28b commit 243ff3f
Show file tree
Hide file tree
Showing 11 changed files with 698 additions and 373 deletions.
245 changes: 177 additions & 68 deletions seldon-core/seldon-core/core.libsonnet
Original file line number Diff line number Diff line change
@@ -1,96 +1,205 @@
local k = import 'k.libsonnet';
local k = import "k.libsonnet";
local deployment = k.extensions.v1beta1.deployment;
local container = k.apps.v1beta1.deployment.mixin.spec.template.spec.containersType;
local service = k.core.v1.service.mixin;
local serviceAccountMixin = k.core.v1.serviceAccount.mixin;
local clusterRoleBindingMixin = k.rbac.v1beta1.clusterRoleBinding.mixin;
local clusterRoleBinding = k.rbac.v1beta1.clusterRoleBinding;
local roleBindingMixin = k.rbac.v1beta1.roleBinding.mixin;
local roleBinding = k.rbac.v1beta1.roleBinding;
local roleMixin = k.rbac.v1beta1.role.mixin;
local serviceAccount = k.core.v1.serviceAccount;
local baseApife = import 'json/apife-deployment.json';
local apifeService = import 'json/apife-service.json';
local operatorDeployment = import 'json/operator-deployment.json';
local redisDeployment = import 'json/redis-deployment.json';
local redisService = import 'json/redis-service.json';
local rbacServiceAccount = import 'json/rbac-service-account.json';
local rbacClusterRoleBinding = import 'json/rbac-cluster-binding.json';
local crdDefn = import 'crd.libsonnet';

local crdDefn = import "crd.libsonnet";
local seldonTemplate = import "json/template.json";

local getOperatorDeployment(x) = x.metadata.name == 'RELEASE-NAME-seldon-cluster-manager';
local getApifeDeployment(x) = x.metadata.name == 'RELEASE-NAME-seldon-apiserver' && x.kind == "Deployment";
local getApifeService(x) = x.metadata.name == 'RELEASE-NAME-seldon-apiserver' && x.kind == "Service";
local getRedisDeployment(x) = x.metadata.name == 'RELEASE-NAME-redis' && x.kind == "Deployment";
local getRedisService(x) = x.metadata.name == 'RELEASE-NAME-redis' && x.kind == "Service";
local getServiceAccount(x) = x.kind == "ServiceAccount";
local getClusterRole(x) = x.kind == "ClusterRole";
local getClusterRoleBinding(x) = x.kind == "ClusterRoleBinding";
local getRoleBinding(x) = x.kind == "RoleBinding";
local getRole(x) = x.kind == "Role";
local getEnvNotRedis(x) = x.name != "SELDON_CLUSTER_MANAGER_REDIS_HOST";

{
parts(namespace):: {

apife(apifeImage,withRbac)::

local c = baseApife.spec.template.spec.containers[0] +
container.withImage(apifeImage) +
container.withImagePullPolicy("IfNotPresent");

local apiFeBase =
baseApife +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.spec.template.spec.withContainers([c]);

if withRbac == "true" then
apiFeBase +
deployment.mixin.spec.template.spec.withServiceAccountName("seldon")
else
apiFeBase,


apifeService(serviceType)::

apifeService +
service.metadata.withNamespace(namespace) +
service.spec.withType(serviceType),

deploymentOperator(engineImage, clusterManagerImage, springOpts, javaOpts, withRbac):
local env = [
{ name: "JAVA_OPTS", value: javaOpts },
{ name: "SPRING_OPTS", value: springOpts },
{ name: "ENGINE_CONTAINER_IMAGE_AND_VERSION", value: engineImage },
];

local c = operatorDeployment.spec.template.spec.containers[0] +
container.withImage(clusterManagerImage) +
container.withEnvMixin(env) +
container.withImagePullPolicy("IfNotPresent");

local depOp = operatorDeployment +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.spec.template.spec.withContainers([c]);

if withRbac == "true" then
depOp +
deployment.mixin.spec.template.spec.withServiceAccountName("seldon")
else
depOp,
parts(name,namespace):: {

apife(apifeImage, withRbac)::

local baseApife = std.filter(getApifeDeployment,seldonTemplate.items)[0];

local env = [
{ name: "SELDON_CLUSTER_MANAGER_REDIS_HOST", value: name+"-redis" },
];

local env2 = std.filter(getEnvNotRedis,baseApife.spec.template.spec.containers[0].env);

local c = baseApife.spec.template.spec.containers[0] +
container.withImage(apifeImage) +
container.withEnv(env+env2) +
container.withImagePullPolicy("IfNotPresent");

local labels = { "app.kubernetes.io/name" : name,
"heritage" : "ksonnet",
"release" : name
};


local apiFeBase1 =
baseApife +
deployment.mixin.metadata.withName(name+"-seldon-apiserver") +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.metadata.withLabelsMixin(labels) +
deployment.mixin.spec.template.spec.withContainers([c]);

// Ensure labels copied to enclosed parts
local apiFeBase = apiFeBase1 +
deployment.mixin.spec.selector.withMatchLabels(apiFeBase1.metadata.labels) +
deployment.mixin.spec.template.metadata.withLabels(apiFeBase1.metadata.labels);


if withRbac == "true" then
apiFeBase +
deployment.mixin.spec.template.spec.withServiceAccountName("seldon")
else
apiFeBase,


apifeService(serviceType)::

local apifeService = std.filter(getApifeService,seldonTemplate.items)[0];

local labels = { "app.kubernetes.io/name" : name };

apifeService +
service.metadata.withName(name+"-seldon-apiserver") +
service.metadata.withNamespace(namespace) +
service.metadata.withLabelsMixin(labels) +
service.spec.withType(serviceType),

deploymentOperator(engineImage, clusterManagerImage, springOpts, javaOpts, withRbac):

local op = std.filter(getOperatorDeployment,seldonTemplate.items)[0];

local env = [
{ name: "JAVA_OPTS", value: javaOpts },
{ name: "SPRING_OPTS", value: springOpts },
{ name: "ENGINE_CONTAINER_IMAGE_AND_VERSION", value: engineImage },
{ name: "SELDON_CLUSTER_MANAGER_REDIS_HOST", value: name+"-redis" },
{ name: "SELDON_CLUSTER_MANAGER_POD_NAMESPACE", valueFrom: {fieldRef:{apiVersion: "v1",fieldPath: "metadata.namespace"}}},
];

local c = op.spec.template.spec.containers[0] +
container.withImage(clusterManagerImage) +
container.withEnv(env) +
container.withImagePullPolicy("IfNotPresent");


local labels = { "app.kubernetes.io/name" : name,
"heritage" : "ksonnet",
"release" : name
};

local depOp1 = op +
deployment.mixin.metadata.withName(name+"-seldon-cluster-manager") +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.metadata.withLabelsMixin(labels) +
deployment.mixin.spec.template.spec.withContainers([c]);

// Ensure labels copied to enclosed parts
local depOp = depOp1 +
deployment.mixin.spec.selector.withMatchLabels(depOp1.metadata.labels) +
deployment.mixin.spec.template.metadata.withLabels(depOp1.metadata.labels);


if withRbac == "true" then
depOp +
deployment.mixin.spec.template.spec.withServiceAccountName("seldon")
else
depOp,

redisDeployment():

redisDeployment +
deployment.mixin.metadata.withNamespace(namespace),
local redisDeployment = std.filter(getRedisDeployment,seldonTemplate.items)[0];

local labels = { "app" : name+"-redis-app",
"app.kubernetes.io/name" : name,
"heritage" : "ksonnet",
"release" : name
};

local redisDeployment1 = redisDeployment +
deployment.mixin.metadata.withName(name+"-redis") +
deployment.mixin.metadata.withNamespace(namespace) +
deployment.mixin.metadata.withLabelsMixin(labels);

redisDeployment1 +
deployment.mixin.spec.selector.withMatchLabels(redisDeployment1.metadata.labels) +
deployment.mixin.spec.template.metadata.withLabels(redisDeployment1.metadata.labels),

redisService():

redisService +
service.metadata.withNamespace(namespace),
local redisService = std.filter(getRedisService,seldonTemplate.items)[0];

local labels = { "app.kubernetes.io/name" : name };

redisService +
service.metadata.withName(name+"-redis") +
service.metadata.withNamespace(namespace) +
service.metadata.withLabelsMixin(labels) +
service.spec.withSelector({"app":name+"-redis-app"}),

rbacServiceAccount():

rbacServiceAccount +
serviceAccountMixin.metadata.withNamespace(namespace),
local rbacServiceAccount = std.filter(getServiceAccount,seldonTemplate.items)[0];

rbacServiceAccount +
serviceAccountMixin.metadata.withNamespace(namespace),


rbacClusterRole():

local clusterRole = std.filter(getClusterRole,seldonTemplate.items)[0];

clusterRole,

rbacRole():

local role = std.filter(getRole,seldonTemplate.items)[0];

role +
roleMixin.metadata.withNamespace(namespace),


rbacClusterRoleBinding():

local subject = rbacClusterRoleBinding.subjects[0] +
{"namespace":namespace};
local rbacClusterRoleBinding = std.filter(getClusterRoleBinding,seldonTemplate.items)[0];

local subject = rbacClusterRoleBinding.subjects[0]
{ namespace: namespace };

rbacClusterRoleBinding +
clusterRoleBindingMixin.metadata.withNamespace(namespace) +
clusterRoleBinding.withSubjects([subject]),

rbacRoleBinding():

local rbacRoleBinding = std.filter(getRoleBinding,seldonTemplate.items)[0];

local subject = rbacRoleBinding.subjects[0]
{ namespace: namespace };

rbacClusterRoleBinding +
clusterRoleBindingMixin.metadata.withNamespace(namespace) +
clusterRoleBinding.withSubjects([subject]),
rbacRoleBinding +
roleBindingMixin.metadata.withNamespace(namespace) +
roleBinding.withSubjects([subject]),

crd():

crdDefn.crd(),
crdDefn.crd(),

}, // parts
}
7 changes: 7 additions & 0 deletions seldon-core/seldon-core/json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The template.json is generated from the helm source chart at https://github.com/SeldonIO/seldon-core/tree/master/helm-charts/seldon-core

```
helm template ${SELDON-CORE-HOME}/helm-charts/seldon-core > template.yaml
kubectl convert -f template.yaml -o json > template.json
rm template.yaml
```
52 changes: 0 additions & 52 deletions seldon-core/seldon-core/json/apife-deployment.json

This file was deleted.

34 changes: 0 additions & 34 deletions seldon-core/seldon-core/json/apife-service.json

This file was deleted.

Loading

0 comments on commit 243ff3f

Please sign in to comment.