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{ ...@@ -11,33 +11,13 @@ var defaultPrototypes = []*SpecificationSchema{
Description: `A simple namespace. Labels are automatically populated from the name of the Description: `A simple namespace. Labels are automatically populated from the name of the
namespace.`, namespace.`,
ShortDescription: `Namespace with labels automatically populated from the name`, 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{ JsonnetBody: []string{
`local k = import "k.libsonnet";`, `local k = import "k.libsonnet";`,
`local ns = k.core.v1.namespace;`, `local namespace = k.core.v1.namespace;`,
``, ``,
`ns.new() +`, `namespace`,
`ns.mixin.metadata.name(import 'param://name') +`, ` .new(import 'param://name')`,
`ns.mixin.metadata.labels({name: import 'param://name'})`, ` .withLabels({name: import 'param://name'})`,
}, },
}, },
}, },
...@@ -60,51 +40,17 @@ will typically look something like: ...@@ -60,51 +40,17 @@ will typically look something like:
ks prototype use service --targetLabelSelector "{app: 'nginx'}" [...]`, ks prototype use service --targetLabelSelector "{app: 'nginx'}" [...]`,
ShortDescription: `Service that exposes a single port`, 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{ JsonnetBody: []string{
`local k = import "k.libsonnet";`, `local k = import "k.libsonnet";`,
`local service = k.core.v1.service;`, `local service = k.core.v1.service;`,
`local port = k.core.v1.service.mixin.spec.portsType;`, `local port = k.core.v1.service.mixin.spec.portsType;`,
``, ``,
`service.new(`, `service`,
` import 'param://name',`, ` .new(`,
` import 'param://targetLabelSelector',`, ` import 'param://name',`,
` port.new(import 'param://servicePort', import 'param://targetPort')) +`, ` import 'param://targetLabelSelector',`,
`service.mixin.spec.type(import 'param://type')`, ` port.new(import 'param://servicePort', import 'param://targetPort'))`,
` .withType(import 'param://type')`,
}, },
}, },
}, },
...@@ -123,95 +69,6 @@ will typically look something like: ...@@ -123,95 +69,6 @@ will typically look something like:
Description: `A service that exposes 'servicePort', and directs traffic Description: `A service that exposes 'servicePort', and directs traffic
to 'targetLabelSelector', at 'targetPort'.`, to 'targetLabelSelector', at 'targetPort'.`,
ShortDescription: `A deployment exposed with a service`, 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{ JsonnetBody: []string{
`local k = import "k.libsonnet";`, `local k = import "k.libsonnet";`,
`local deployment = k.apps.v1beta1.deployment;`, `local deployment = k.apps.v1beta1.deployment;`,
...@@ -223,18 +80,21 @@ to 'targetLabelSelector', at 'targetPort'.`, ...@@ -223,18 +80,21 @@ to 'targetLabelSelector', at 'targetPort'.`,
`local targetPort = import 'param://containerPort';`, `local targetPort = import 'param://containerPort';`,
`local labels = {app: import 'param://name'};`, `local labels = {app: import 'param://name'};`,
``, ``,
`local appService = service.new(`, `local appService = service`,
` import 'param://name',`, ` .new(`,
` labels,`, ` import 'param://name',`,
` servicePort.new(import 'param://servicePort', targetPort)) +`, ` labels,`,
`service.mixin.spec.type(import 'param://type');`, ` servicePort.new(import 'param://servicePort', targetPort))`,
` .withType(import 'param://type');`,
``, ``,
`local appDeployment = deployment.new(`, `local appDeployment = deployment`,
` import 'param://name',`, ` .new(`,
` import 'param://replicas',`, ` import 'param://name',`,
` container.new(import 'param://name', import 'param://image') +`, ` import 'param://replicas',`,
` container.ports(containerPort.new(targetPort)),`, ` container`,
` labels);`, ` .new(import 'param://name', import 'param://image')`,
` .withPorts(containerPort.new(targetPort)),`,
` labels);`,
``, ``,
`k.core.v1.list.new([appService, appDeployment])`, `k.core.v1.list.new([appService, appDeployment])`,
}, },
...@@ -250,30 +110,11 @@ to 'targetLabelSelector', at 'targetPort'.`, ...@@ -250,30 +110,11 @@ to 'targetLabelSelector', at 'targetPort'.`,
Template: SnippetSchema{ Template: SnippetSchema{
Description: `A simple config map with optional user-specified data.`, Description: `A simple config map with optional user-specified data.`,
ShortDescription: `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{ JsonnetBody: []string{
`local k = import "k.libsonnet";`, `local k = import "k.libsonnet";`,
`local configMap = k.core.v1.configMap;`, `local configMap = k.core.v1.configMap;`,
``, ``,
`configMap.new() +`, `configMap.new(import 'param://name', import 'param://data')`,
`configMap.mixin.metadata.name(import 'param://name') +`,
`configMap.data(import 'param://data')`,
}, },
}, },
}, },
...@@ -291,56 +132,6 @@ to 'targetLabelSelector', at 'targetPort'.`, ...@@ -291,56 +132,6 @@ to 'targetLabelSelector', at 'targetPort'.`,
(default: 1), and exposes a port (default: 80). Labels are automatically (default: 1), and exposes a port (default: 80). Labels are automatically
populated from 'name'.`, populated from 'name'.`,
ShortDescription: `Replicates a container n times, exposes a single port`, 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{ JsonnetBody: []string{
`local k = import "k.libsonnet";`, `local k = import "k.libsonnet";`,
`local deployment = k.apps.v1beta1.deployment;`, `local deployment = k.apps.v1beta1.deployment;`,
...@@ -350,8 +141,9 @@ populated from 'name'.`, ...@@ -350,8 +141,9 @@ populated from 'name'.`,
`deployment.new(`, `deployment.new(`,
` import 'param://name',`, ` import 'param://name',`,
` import 'param://replicas',`, ` import 'param://replicas',`,
` container.new(import 'param://name', import 'param://image') +`, ` container`,
` container.ports(port.new(import 'param://port')),`, ` .new(import 'param://name', import 'param://image')`,
` .withPorts(port.new(import 'param://port')),`,
` {app: import 'param://name'})`, ` {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