Skip to content

Commit

Permalink
Implement TemplateConfig endpoint
Browse files Browse the repository at this point in the history
Adds TemplateProcessor implementation using the default
ExpressionValueGenerator, which is capable of transforming
Template api objects into Config api objects.

Authors:
  Michal Fojtik <mfojtik@redhat.com>
  Vojtech Vitek <vvitek@redhat.com>
  • Loading branch information
mfojtik authored and VojtechVitek committed Sep 9, 2014
1 parent 8108839 commit 0671283
Show file tree
Hide file tree
Showing 28 changed files with 1,106 additions and 4 deletions.
151 changes: 151 additions & 0 deletions examples/guestbook/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"id": "guestbook",
"kind": "Template",
"name": "guestbook-example",
"description": "Example shows how to build a simple multi-tier application using Kubernetes and Docker",
"parameters": [
{
"name": "ADMIN_USERNAME",
"description": "Guestbook administrator username",
"type": "string",
"expression": "admin[A-Z0-9]{3}"
},
{
"name": "ADMIN_PASSWORD",
"description": "Guestboot administrator password",
"type": "string",
"expression": "[a-zA-Z0-9]{8}"
},
{
"name": "REDIS_PASSWORD",
"description": "The password Redis use for communication",
"type": "string",
"expression": "[a-zA-Z0-9]{8}"
}
],
"items": [
{
"id": "frontend",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 5432,
"selector": {
"name": "frontend"
}
},
{
"id": "redismaster",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 10000,
"selector": {
"name": "redis-master"
}
},
{
"id": "redisslave",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 10001,
"labels": {
"name": "redisslave"
},
"selector": {
"name": "redisslave"
}
},
{
"id": "redis-master-2",
"kind": "Pod",
"apiVersion": "v1beta1",
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "redis-master-2",
"containers": [{
"name": "master",
"image": "dockerfile/redis",
"env": [
{
"name": "REDIS_PASSWORD",
"value": "${REDIS_PASSWORD}"
}
],
"ports": [{
"containerPort": 6379
}]
}]
}
},
"labels": {
"name": "redis-master"
}
},
{
"id": "frontendController",
"kind": "ReplicationController",
"apiVersion": "v1beta1",
"desiredState": {
"replicas": 3,
"replicaSelector": {"name": "frontend"},
"podTemplate": {
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "frontendController",
"containers": [{
"name": "php-redis",
"image": "brendanburns/php-redis",
"env": [
{
"name": "ADMIN_USERNAME",
"value": "${ADMIN_USERNAME}"
},
{
"name": "ADMIN_PASSWORD",
"value": "${ADMIN_PASSWORD}"
},
{
"name": "REDIS_PASSWORD",
"value": "${REDIS_PASSWORD}"
}
],
"ports": [{"containerPort": 80, "hostPort": 8000}]
}]
}
},
"labels": {"name": "frontend"}
}},
"labels": {"name": "frontend"}
},
{
"id": "redisSlaveController",
"kind": "ReplicationController",
"apiVersion": "v1beta1",
"desiredState": {
"replicas": 2,
"replicaSelector": {"name": "redisslave"},
"podTemplate": {
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "redisSlaveController",
"containers": [{
"name": "slave",
"image": "brendanburns/redis-slave",
"env": [
{
"name": "REDIS_PASSWORD",
"value": "${REDIS_PASSWORD}"
}
],
"ports": [{"containerPort": 6379, "hostPort": 6380}]
}]
}
},
"labels": {"name": "redisslave"}
}},
"labels": {"name": "redisslave"}
}
]
}
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package api

import ()
import ()
13 changes: 10 additions & 3 deletions pkg/cmd/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ import (
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
"github.com/google/cadvisor/client"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/build"
buildapi "github.com/openshift/origin/pkg/build/api"
buildregistry "github.com/openshift/origin/pkg/build/registry/build"
buildconfigregistry "github.com/openshift/origin/pkg/build/registry/buildconfig"
"github.com/openshift/origin/pkg/build/strategy"
osclient "github.com/openshift/origin/pkg/client"
"github.com/spf13/cobra"
"github.com/openshift/origin/pkg/template"

// Register versioned api types
_ "github.com/openshift/origin/pkg/config/api/v1beta1"
_ "github.com/openshift/origin/pkg/template/api/v1beta1"
)

func NewCommandStartAllInOne(name string) *cobra.Command {
Expand Down Expand Up @@ -119,8 +125,9 @@ func startAllInOne() {

// initialize OpenShift API
storage := map[string]apiserver.RESTStorage{
"builds": buildregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
"buildConfigs": buildconfigregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
"builds": buildregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
"buildConfigs": buildconfigregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
"templateConfigs": template.NewStorage(),
}

osMux := http.NewServeMux()
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/api/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package api defines and registers types for Config objects.
package api
7 changes: 7 additions & 0 deletions pkg/config/api/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package api

import "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

func init() {
runtime.AddKnownTypes("", Config{})
}
25 changes: 25 additions & 0 deletions pkg/config/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package api

import (
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// Config contains a set of Kubernetes resources to be applied.
// TODO: Unify with Kubernetes Config
// https://github.com/GoogleCloudPlatform/kubernetes/pull/1007
type Config struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`

// Required: Name identifies the Config.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Config.
Description string `json:"description" yaml:"description"`

// Required: Items is an array of Kubernetes resources of Service,
// Pod and/or ReplicationController kind.
// TODO: Handle unregistered types. Define custom []interface{}
// type and its unmarshaller instead of []runtime.Object.
Items []runtime.Object `json:"items" yaml:"items"`
}
7 changes: 7 additions & 0 deletions pkg/config/api/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v1beta1

import "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

func init() {
runtime.AddKnownTypes("v1beta1", Config{})
}
25 changes: 25 additions & 0 deletions pkg/config/api/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1beta1

import (
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// Config contains a set of Kubernetes resources to be applied.
// TODO: Unify with Kubernetes Config
// https://github.com/GoogleCloudPlatform/kubernetes/pull/1007
type Config struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`

// Required: Name identifies the Config.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Config.
Description string `json:"description" yaml:"description"`

// Required: Items is an array of Kubernetes resources of Service,
// Pod and/or ReplicationController kind.
// TODO: Handle unregistered types. Define custom []interface{}
// type and its unmarshaller instead of []runtime.Object.
Items []runtime.Object `json:"items" yaml:"items"`
}
2 changes: 2 additions & 0 deletions pkg/template/api/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package api defines and registers types for Template objects.
package api
7 changes: 7 additions & 0 deletions pkg/template/api/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package api

import "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

func init() {
runtime.AddKnownTypes("", Template{})
}
52 changes: 52 additions & 0 deletions pkg/template/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package api

import (
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// Template contains the inputs needed to produce a Config.
type Template struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`

// Required: Name identifies the Template.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Template.
Description string `json:"description" yaml:"description"`

// Required: Items is an array of Kubernetes resources of Service,
// Pod and/or ReplicationController kind.
// TODO: Handle unregistered types. Define custom []interface{}
// type and its unmarshaller instead of []runtime.Object.
Items []runtime.Object `json:"items" yaml:"items"`

// Optional: Parameters is an array of Parameters used during the
// Template to Config transformation.
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

// Parameter defines a name/value variable that is to be processed during
// the Template to Config transformation.
type Parameter struct {
// Required: Name uniquely identifies the Parameter. A TemplateProcessor
// searches given Template for all occurances of the Parameter name, ie.
// ${PARAM_NAME}, and replaces it with it's corresponding Parameter value.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Parameter.
Description string `json:"description" yaml:"description"`

// Required: Type defines the type of the Parameter value.
Type string `json:"type" yaml:"type"`

// Optional: Expression generates new Value data using the
// GeneratorExpressionValue expression.
// TODO: Support more Generator types.
Expression string `json:"expression,omitempty" yaml:"expression,omitempty"`

// Optional: Value holds the Parameter data. The data replaces all occurances
// of the Parameter name during the Template to Config transformation.
// TODO: Change this to interface{} and support more types than just string.
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
7 changes: 7 additions & 0 deletions pkg/template/api/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v1beta1

import "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

func init() {
runtime.AddKnownTypes("v1beta1", Template{})
}
52 changes: 52 additions & 0 deletions pkg/template/api/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package v1beta1

import (
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// Template contains the inputs needed to produce a Config.
type Template struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`

// Required: Name identifies the Template.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Template.
Description string `json:"description" yaml:"description"`

// Required: Items is an array of Kubernetes resources of Service,
// Pod and/or ReplicationController kind.
// TODO: Handle unregistered types. Define custom []interface{}
// type and its unmarshaller instead of []runtime.Object.
Items []runtime.Object `json:"items" yaml:"items"`

// Optional: Parameters is an array of Parameters used during the
// Template to Config transformation.
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

// Parameter defines a name/value variable that is to be processed during
// the Template to Config transformation.
type Parameter struct {
// Required: Name uniquely identifies the Parameter. A TemplateProcessor
// searches given Template for all occurances of the Parameter name, ie.
// ${PARAM_NAME}, and replaces it with it's corresponding Parameter value.
Name string `json:"name" yaml:"name"`

// Optional: Description describes the Parameter.
Description string `json:"description" yaml:"description"`

// Required: Type defines the type of the Parameter value.
Type string `json:"type" yaml:"type"`

// Optional: Expression generates new Value data using the
// GeneratorExpressionValue expression.
// TODO: Support more Generator types.
Expression string `json:"expression,omitempty" yaml:"expression,omitempty"`

// Optional: Value holds the Parameter data. The data replaces all occurances
// of the Parameter name during the Template to Config transformation.
// TODO: Change this to interface{} and support more types than just string.
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
4 changes: 4 additions & 0 deletions pkg/template/api/validation/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package validation has functions for validating the correctness of
// Template objects and explaining what is wrong with them when
// they aren't valid.
package validation
Loading

0 comments on commit 0671283

Please sign in to comment.