Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
ksonnet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ijaz Ahmad
ksonnet
Commits
f1fba0a1
Commit
f1fba0a1
authored
7 years ago
by
Alex Clemmer
Browse files
Options
Downloads
Patches
Plain Diff
Add combination deployment/service system prototype
parent
5ac3a915
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
prototype/prototype_test.go
+4
-0
4 additions, 0 deletions
prototype/prototype_test.go
prototype/systemPrototypes.go
+152
-17
152 additions, 17 deletions
prototype/systemPrototypes.go
with
156 additions
and
17 deletions
prototype/prototype_test.go
+
4
−
0
View file @
f1fba0a1
...
...
@@ -113,6 +113,7 @@ func TestSearch(t *testing.T) {
"io.ksonnet.pkg.single-port-service"
,
"io.ksonnet.pkg.namespace"
,
"io.ksonnet.pkg.configMap"
,
"io.ksonnet.pkg.deployment-exposed-with-service"
,
"io.ksonnet.pkg.single-port-deployment"
,
})
assertSearch
(
t
,
idx
,
Prefix
,
"foo"
,
[]
string
{})
...
...
@@ -120,6 +121,7 @@ func TestSearch(t *testing.T) {
// Suffix searches.
assertSearch
(
t
,
idx
,
Suffix
,
"service"
,
[]
string
{
"io.ksonnet.pkg.single-port-service"
,
"io.ksonnet.pkg.deployment-exposed-with-service"
,
"io.some-vendor.pkg.simple-service"
,
})
assertSearch
(
t
,
idx
,
Suffix
,
"simple"
,
[]
string
{})
...
...
@@ -129,6 +131,7 @@ func TestSearch(t *testing.T) {
// Substring searches.
assertSearch
(
t
,
idx
,
Substring
,
"service"
,
[]
string
{
"io.ksonnet.pkg.single-port-service"
,
"io.ksonnet.pkg.deployment-exposed-with-service"
,
"io.some-vendor.pkg.simple-service"
,
})
assertSearch
(
t
,
idx
,
Substring
,
"simple"
,
[]
string
{
...
...
@@ -136,6 +139,7 @@ func TestSearch(t *testing.T) {
"io.some-vendor.pkg.simple-service"
,
})
assertSearch
(
t
,
idx
,
Substring
,
"io.ksonnet"
,
[]
string
{
"io.ksonnet.pkg.deployment-exposed-with-service"
,
"io.ksonnet.pkg.single-port-service"
,
"io.ksonnet.pkg.single-port-deployment"
,
"io.ksonnet.pkg.configMap"
,
...
...
This diff is collapsed.
Click to expand it.
prototype/systemPrototypes.go
+
152
−
17
View file @
f1fba0a1
...
...
@@ -47,9 +47,10 @@ namespace.`,
Params
:
ParamSchemas
{
RequiredParam
(
"name"
,
"serviceName"
,
"Name of the service"
,
String
),
RequiredParam
(
"targetLabelSelector"
,
"selector"
,
`Label for the service to target (e.g., "{app: 'MyApp'}").`
,
Object
),
Required
Param
(
"servicePort"
,
"port"
,
"Port for the service to expose."
,
NumberOrString
),
Required
Param
(
"targetPort"
,
"port"
,
"Port for the service target."
,
NumberOrString
),
Optional
Param
(
"servicePort"
,
"port"
,
"Port for the service to expose."
,
"80"
,
NumberOrString
),
Optional
Param
(
"targetPort"
,
"port"
,
"Port for the service target."
,
"80"
,
NumberOrString
),
OptionalParam
(
"protocol"
,
"protocol"
,
"Protocol to use (either TCP or UDP)."
,
"TCP"
,
String
),
OptionalParam
(
"type"
,
"serviceType"
,
"Type of service to expose"
,
"ClusterIP"
,
String
),
},
Template
:
SnippetSchema
{
Description
:
`A service that exposes 'servicePort', and directs traffic
...
...
@@ -60,17 +61,18 @@ will typically look something like:
ksonnet 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}"
,
" ports:"
,
" - protocol: ${protocol}"
,
" port: ${servicePort}"
,
" targetPort: ${targetPort}"
,
`kind: Service`
,
`apiVersion: v1`
,
`metadata:`
,
` name: ${name}`
,
`spec:`
,
` selector:`
,
` ${targetLabelSelector}`
,
` type: ${type}`
,
` ports:`
,
` - protocol: ${protocol}`
,
` port: ${servicePort}`
,
` targetPort: ${targetPort}`
,
},
JSONBody
:
[]
string
{
`{`
,
...
...
@@ -80,9 +82,9 @@ will typically look something like:
` "name": ${name}`
,
` },`
,
` "spec": {`
,
` "selector":
{
`
,
` ${targetLabelSelector}`
,
` },`
,
` "selector":`
,
` ${targetLabelSelector}
,
`
,
`
"type": ${type
},`
,
` "ports": [`
,
` {`
,
` "protocol": ${protocol},`
,
...
...
@@ -101,7 +103,140 @@ will typically look something like:
`service.new(`
,
` ${name},`
,
` ${targetLabelSelector},`
,
` port.new(${servicePort}, ${targetPort}))`
,
` port.new(${servicePort}, ${targetPort})) +`
,
`service.mixin.spec.type(${type})`
,
},
},
},
&
SpecificationSchema
{
APIVersion
:
"0.1"
,
Name
:
"io.ksonnet.pkg.deployment-exposed-with-service"
,
Params
:
ParamSchemas
{
RequiredParam
(
"name"
,
"name"
,
"Name of the service and deployment"
,
String
),
RequiredParam
(
"image"
,
"containerImage"
,
"Container image to deploy"
,
String
),
OptionalParam
(
"servicePort"
,
"port"
,
"Port for the service to expose."
,
"80"
,
NumberOrString
),
OptionalParam
(
"containerPort"
,
"port"
,
"Container port for service to target."
,
"80"
,
NumberOrString
),
OptionalParam
(
"replicas"
,
"replicas"
,
"Number of replicas"
,
"1"
,
Number
),
OptionalParam
(
"type"
,
"serviceType"
,
"Type of service to expose"
,
"ClusterIP"
,
String
),
},
Template
:
SnippetSchema
{
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;`
,
`local container = k.apps.v1beta1.deployment.mixin.spec.template.spec.containersType;`
,
`local containerPort = container.portsType;`
,
`local service = k.core.v1.service;`
,
`local servicePort = k.core.v1.service.mixin.spec.portsType;`
,
``
,
`local targetPort = ${containerPort};`
,
`local labels = {app: ${name}};`
,
``
,
`local appService = service.new(`
,
` ${name},`
,
` labels,`
,
` servicePort.new(${servicePort}, targetPort)) +`
,
`service.mixin.spec.type(${type});`
,
``
,
`local appDeployment = deployment.new(`
,
` ${name},`
,
` ${replicas},`
,
` container.new(${name}, ${image}) +`
,
` container.ports(containerPort.new(targetPort)),`
,
` labels);`
,
``
,
`k.core.v1.list.new([appService, appDeployment])`
,
},
},
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment