Skip to content
Snippets Groups Projects
Commit 4275521f authored by Alex Clemmer's avatar Alex Clemmer
Browse files

Transition system prototypes to ksonnet-lib beta.3

parent b68464fd
No related branches found
No related tags found
No related merge requests found
......@@ -11,33 +11,13 @@ var defaultPrototypes = []*SpecificationSchema{
Description: `A simple namespace. Labels are automatically populated from the name of the
namespace.`,
ShortDescription: `Namespace with labels automatically populated from the name`,
YAMLBody: []string{
"kind: Namespace",
"apiVersion: v1",
"metadata:",
" name: ${name}",
" labels:",
" name: ${name}",
},
JSONBody: []string{
`{`,
` "kind": "Namespace",`,
` "apiVersion": "v1",`,
` "metadata": {`,
` "name": ${name},`,
` "labels": {`,
` "name": ${name}`,
` }`,
` }`,
`}`,
},
JsonnetBody: []string{
`local k = import "k.libsonnet";`,
`local ns = k.core.v1.namespace;`,
`local namespace = k.core.v1.namespace;`,
``,
`ns.new() +`,
`ns.mixin.metadata.name(import 'param://name') +`,
`ns.mixin.metadata.labels({name: import 'param://name'})`,
`namespace`,
` .new(import 'param://name')`,
` .withLabels({name: import 'param://name'})`,
},
},
},
......@@ -60,51 +40,17 @@ will typically look something like:
ks prototype use service --targetLabelSelector "{app: 'nginx'}" [...]`,
ShortDescription: `Service that exposes a single port`,
YAMLBody: []string{
`kind: Service`,
`apiVersion: v1`,
`metadata:`,
` name: ${name}`,
`spec:`,
` selector:`,
` ${targetLabelSelector}`,
` type: ${type}`,
` ports:`,
` - protocol: ${protocol}`,
` port: ${servicePort}`,
` targetPort: ${targetPort}`,
},
JSONBody: []string{
`{`,
` "kind": "Service",`,
` "apiVersion": "v1",`,
` "metadata": {`,
` "name": ${name}`,
` },`,
` "spec": {`,
` "selector":`,
` ${targetLabelSelector},`,
` "type": ${type},`,
` "ports": [`,
` {`,
` "protocol": ${protocol},`,
` "port": ${servicePort},`,
` "targetPort": ${targetPort}`,
` }`,
` ]`,
` }`,
`}`,
},
JsonnetBody: []string{
`local k = import "k.libsonnet";`,
`local service = k.core.v1.service;`,
`local port = k.core.v1.service.mixin.spec.portsType;`,
``,
`service.new(`,
` import 'param://name',`,
` import 'param://targetLabelSelector',`,
` port.new(import 'param://servicePort', import 'param://targetPort')) +`,
`service.mixin.spec.type(import 'param://type')`,
`service`,
` .new(`,
` import 'param://name',`,
` import 'param://targetLabelSelector',`,
` port.new(import 'param://servicePort', import 'param://targetPort'))`,
` .withType(import 'param://type')`,
},
},
},
......@@ -123,95 +69,6 @@ will typically look something like:
Description: `A service that exposes 'servicePort', and directs traffic
to 'targetLabelSelector', at 'targetPort'.`,
ShortDescription: `A deployment exposed with a service`,
YAMLBody: []string{
`apiVersion: v1`,
`items:`,
` - apiVersion: v1`,
` kind: Service`,
` metadata:`,
` name: ${name}`,
` spec:`,
` ports:`,
` - port: ${servicePort}`,
` targetPort: ${containerPort}`,
` selector:`,
` app: ${name}`,
` type: ${type}`,
` - apiVersion: apps/v1beta1`,
` kind: Deployment`,
` metadata:`,
` name: ${name}`,
` spec:`,
` replicas: ${replicas}`,
` template:`,
` metadata:`,
` labels:`,
` app: ${name}`,
` spec:`,
` containers:`,
` - image: ${name}`,
` name: ${image}`,
` ports:`,
` - containerPort: ${containerPort}`,
`kind: List`,
},
JSONBody: []string{
`{`,
` "apiVersion": "v1",`,
` "items": [`,
` {`,
` "apiVersion": "v1",`,
` "kind": "Service",`,
` "metadata": {`,
` "name": ${name}`,
` },`,
` "spec": {`,
` "ports": [`,
` {`,
` "port": ${servicePort},`,
` "targetPort": ${containerPort}`,
` }`,
` ],`,
` "selector": {`,
` "app": ${name}`,
` },`,
` "type": ${type}`,
` }`,
` },`,
` {`,
` "apiVersion": "apps/v1beta1",`,
` "kind": "Deployment",`,
` "metadata": {`,
` "name": ${name}`,
` },`,
` "spec": {`,
` "replicas": ${replicas},`,
` "template": {`,
` "metadata": {`,
` "labels": {`,
` "app": ${name}`,
` }`,
` },`,
` "spec": {`,
` "containers": [`,
` {`,
` "image": ${name},`,
` "name": ${image},`,
` "ports": [`,
` {`,
` "containerPort": ${containerPort}`,
` }`,
` ]`,
` }`,
` ]`,
` }`,
` }`,
` }`,
` }`,
` ],`,
` "kind": "List"`,
`}`,
},
JsonnetBody: []string{
`local k = import "k.libsonnet";`,
`local deployment = k.apps.v1beta1.deployment;`,
......@@ -223,18 +80,21 @@ to 'targetLabelSelector', at 'targetPort'.`,
`local targetPort = import 'param://containerPort';`,
`local labels = {app: import 'param://name'};`,
``,
`local appService = service.new(`,
` import 'param://name',`,
` labels,`,
` servicePort.new(import 'param://servicePort', targetPort)) +`,
`service.mixin.spec.type(import 'param://type');`,
`local appService = service`,
` .new(`,
` import 'param://name',`,
` labels,`,
` servicePort.new(import 'param://servicePort', targetPort))`,
` .withType(import 'param://type');`,
``,
`local appDeployment = deployment.new(`,
` import 'param://name',`,
` import 'param://replicas',`,
` container.new(import 'param://name', import 'param://image') +`,
` container.ports(containerPort.new(targetPort)),`,
` labels);`,
`local appDeployment = deployment`,
` .new(`,
` import 'param://name',`,
` import 'param://replicas',`,
` container`,
` .new(import 'param://name', import 'param://image')`,
` .withPorts(containerPort.new(targetPort)),`,
` labels);`,
``,
`k.core.v1.list.new([appService, appDeployment])`,
},
......@@ -250,30 +110,11 @@ to 'targetLabelSelector', at 'targetPort'.`,
Template: SnippetSchema{
Description: `A simple config map with optional user-specified data.`,
ShortDescription: `A simple config map with optional user-specified data`,
YAMLBody: []string{
"apiVersion: v1",
"kind: ConfigMap",
"metadata:",
" name: ${name}",
"data: ${data}",
},
JSONBody: []string{
`{`,
` "apiVersion": "v1",`,
` "kind": "ConfigMap",`,
` "metadata": {`,
` "name": ${name}`,
` },`,
` "data": ${data}`,
`}`,
},
JsonnetBody: []string{
`local k = import "k.libsonnet";`,
`local configMap = k.core.v1.configMap;`,
``,
`configMap.new() +`,
`configMap.mixin.metadata.name(import 'param://name') +`,
`configMap.data(import 'param://data')`,
`configMap.new(import 'param://name', import 'param://data')`,
},
},
},
......@@ -291,56 +132,6 @@ to 'targetLabelSelector', at 'targetPort'.`,
(default: 1), and exposes a port (default: 80). Labels are automatically
populated from 'name'.`,
ShortDescription: `Replicates a container n times, exposes a single port`,
YAMLBody: []string{
"apiVersion: apps/v1beta1",
"kind: Deployment",
"metadata:",
" name: ${name}",
"spec:",
" replicas: ${replicas:1}",
" template:",
" metadata:",
" labels:",
" app: ${name}",
" spec:",
" containers:",
" - name: ${name}",
" image: ${image}",
" ports:",
" - containerPort: ${port:80}",
},
JSONBody: []string{
`{`,
` "apiVersion": "apps/v1beta1",`,
` "kind": "Deployment",`,
` "metadata": {`,
` "name": ${name}`,
` },`,
` "spec": {`,
` "replicas": ${replicas:1},`,
` "template": {`,
` "metadata": {`,
` "labels": {`,
` "app": ${name}`,
` }`,
` },`,
` "spec": {`,
` "containers": [`,
` {`,
` "name": ${name},`,
` "image": ${image},`,
` "ports": [`,
` {`,
` "containerPort": ${port:80}`,
` }`,
` ]`,
` }`,
` ]`,
` }`,
` }`,
` }`,
`}`,
},
JsonnetBody: []string{
`local k = import "k.libsonnet";`,
`local deployment = k.apps.v1beta1.deployment;`,
......@@ -350,8 +141,9 @@ populated from 'name'.`,
`deployment.new(`,
` import 'param://name',`,
` import 'param://replicas',`,
` container.new(import 'param://name', import 'param://image') +`,
` container.ports(port.new(import 'param://port')),`,
` container`,
` .new(import 'param://name', import 'param://image')`,
` .withPorts(port.new(import 'param://port')),`,
` {app: import 'param://name'})`,
},
},
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment