Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
//"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"

"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/api/validation"
configapi "github.com/openshift/origin/pkg/config/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
projectapi "github.com/openshift/origin/pkg/project/api"
routeapi "github.com/openshift/origin/pkg/route/api"
templateapi "github.com/openshift/origin/pkg/template/api"
"github.com/openshift/origin/pkg/util"
)

type mockService struct{}
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestExampleObjectSchemas(t *testing.T) {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return
}
if errors := util.ValidateObject(expectedType); len(errors) > 0 {
if errors := validation.ValidateObject(expectedType); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors)
}
})
Expand Down
4 changes: 3 additions & 1 deletion examples/sample-app/application-template-custombuild.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"metadata":{
"name": "ruby-helloworld-sample",
"annotations": {
"description": "This example shows how to create a simple ruby application in openshift origin v3"
}
},
"kind": "Template",
"apiVersion": "v1beta1",
"description": "This example shows how to create a simple ruby application in openshift origin v3",
"parameters": [
{
"name": "ADMIN_USERNAME",
Expand Down
4 changes: 3 additions & 1 deletion examples/sample-app/application-template-dockerbuild.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"metadata":{
"name": "ruby-helloworld-sample",
"annotations": {
"description": "This example shows how to create a simple ruby application in openshift origin v3"
}
},
"kind": "Template",
"apiVersion": "v1beta1",
"description": "This example shows how to create a simple ruby application in openshift origin v3",
"parameters": [
{
"name": "ADMIN_USERNAME",
Expand Down
4 changes: 3 additions & 1 deletion examples/sample-app/application-template-stibuild.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"metadata":{
"name": "ruby-helloworld-sample",
"annotations": {
"description": "This example shows how to create a simple ruby application in openshift origin v3"
}
},
"kind": "Template",
"apiVersion": "v1beta1",
"description": "This example shows how to create a simple ruby application in openshift origin v3",
"parameters": [
{
"name": "ADMIN_USERNAME",
Expand Down
15 changes: 13 additions & 2 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ API_HOST=${API_HOST:-127.0.0.1}
KUBELET_SCHEME=${KUBELET_SCHEME:-http}
KUBELET_PORT=${KUBELET_PORT:-10250}

TEMP_DIR=$(mktemp -d /tmp/openshift-cmd.XXXX)
TEMP_DIR=${USE_TEMP:-$(mktemp -d /tmp/openshift-cmd.XXXX)}
ETCD_DATA_DIR="${TEMP_DIR}/etcd"
VOLUME_DIR="${TEMP_DIR}/volumes"
CERT_DIR="${TEMP_DIR}/certs"
Expand Down Expand Up @@ -80,7 +80,7 @@ if [[ "${API_SCHEME}" == "https" ]]; then
fi

wait_for_url "http://${API_HOST}:${KUBELET_PORT}/healthz" "kubelet: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.25 80

# Set KUBERNETES_MASTER for osc
Expand All @@ -98,6 +98,17 @@ export OPENSHIFT_PROFILE="${CLI_PROFILE-}"
# Begin tests
#

osc get templates
osc create -f examples/sample-app/application-template-dockerbuild.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to be confusing behavior for users i think. (that you are creating a template object, not creating the things defined in the template). can't immediately think of a way to fix it that retains consistency with the create verb, but it bothers me so i figured i'd note it in case someone else has a thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create shouldn't create the things in the template anyway (otherwise the template isn't providing value) but yes, I agree.

osc get templates
osc get templates ruby-helloworld-sample
[ -n "$(osc get templates ruby-helloworld-sample -o json | osc process -f -)" ]
osc describe templates ruby-helloworld-sample
osc delete templates ruby-helloworld-sample
osc get templates
# TODO: create directly from template
echo "templates: ok"

# verify some default commands
[ "$(openshift cli)" ]
[ "$(openshift ex)" ]
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func fuzzInternalObject(t *testing.T, forVersion string, item runtime.Object, se
c.Fuzz(&j.ObjectMeta)
c.Fuzz(&j.Parameters)
// TODO: replace with structured type definition
j.Items = []runtime.Object{}
j.Objects = []runtime.Object{}
},
func(j *image.Image, c fuzz.Continue) {
c.Fuzz(&j.ObjectMeta)
Expand Down
20 changes: 11 additions & 9 deletions pkg/util/validate.go → pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package validation

import (
"fmt"
Expand All @@ -18,15 +18,11 @@ import (
projectv "github.com/openshift/origin/pkg/project/api/validation"
routeapi "github.com/openshift/origin/pkg/route/api"
routev "github.com/openshift/origin/pkg/route/api/validation"
templateapi "github.com/openshift/origin/pkg/template/api"
templatev "github.com/openshift/origin/pkg/template/api/validation"
)

type fakeServiceLister struct{}

func (f *fakeServiceLister) ListServices(kapi.Context) (*kapi.ServiceList, error) {
return &kapi.ServiceList{}, nil
}

// ValidateObject validates the runtime.Object and returns the validation errors
// ValidateObject runs all known validations and returns the validation errors
func ValidateObject(obj runtime.Object) (errors []error) {
if m, err := meta.Accessor(obj); err == nil {
if len(m.Namespace()) == 0 {
Expand All @@ -41,6 +37,11 @@ func ValidateObject(obj runtime.Object) (errors []error) {
errors = validation.ValidateService(t)
case *kapi.Pod:
errors = validation.ValidatePod(t)
case *kapi.Namespace:
errors = validation.ValidateNamespace(t)
case *kapi.Node:
errors = validation.ValidateMinion(t)

case *imageapi.Image:
errors = imagev.ValidateImage(t)
case *imageapi.ImageRepository:
Expand All @@ -61,6 +62,8 @@ func ValidateObject(obj runtime.Object) (errors []error) {
errors = buildv.ValidateBuildConfig(t)
case *buildapi.Build:
errors = buildv.ValidateBuild(t)
case *templateapi.Template:
errors = templatev.ValidateTemplate(t)
default:
if list, err := runtime.ExtractList(obj); err == nil {
for i := range list {
Expand All @@ -73,5 +76,4 @@ func ValidateObject(obj runtime.Object) (errors []error) {
return []error{fmt.Errorf("no validation defined for %#v", obj)}
}
return errors

}
6 changes: 6 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Interface interface {
PolicyBindingsNamespacer
ResourceAccessReviewsNamespacer
SubjectAccessReviewsNamespacer
TemplatesNamespacer
}

func (c *Client) Builds(namespace string) BuildInterface {
Expand Down Expand Up @@ -97,6 +98,11 @@ func (c *Client) TemplateConfigs(namespace string) TemplateConfigInterface {
return newTemplateConfigs(c, namespace)
}

// TemplateConfigs provides a REST client for TemplateConfig
func (c *Client) Templates(namespace string) TemplateInterface {
return newTemplates(c, namespace)
}

func (c *Client) Policies(namespace string) PolicyInterface {
return newPolicies(c, namespace)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (c *Fake) Routes(namespace string) RouteInterface {
return &FakeRoutes{Fake: c, Namespace: namespace}
}

func (c *Fake) Templates(namespace string) TemplateInterface {
return &FakeTemplates{Fake: c}
}

func (c *Fake) Users() UserInterface {
return &FakeUsers{Fake: c}
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/client/fake_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

templateapi "github.com/openshift/origin/pkg/template/api"
)

// FakeTemplates implements TemplateInterface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the methods you want to test easier.
type FakeTemplates struct {
Fake *Fake
Namespace string
}

func (c *FakeTemplates) List(label, field labels.Selector) (*templateapi.TemplateList, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "list-templates"})
return &templateapi.TemplateList{}, nil
}

func (c *FakeTemplates) Get(name string) (*templateapi.Template, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "get-template"})
return &templateapi.Template{}, nil
}

func (c *FakeTemplates) Create(template *templateapi.Template) (*templateapi.Template, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "create-template", Value: template})
return &templateapi.Template{}, nil
}

func (c *FakeTemplates) Update(template *templateapi.Template) (*templateapi.Template, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "update-template"})
return &templateapi.Template{}, nil
}

func (c *FakeTemplates) Delete(name string) error {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-template", Value: name})
return nil
}

func (c *FakeTemplates) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-templates"})
return nil, nil
}
89 changes: 89 additions & 0 deletions pkg/client/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"

templateapi "github.com/openshift/origin/pkg/template/api"
)

// TemplatesNamespacer has methods to work with Template resources in a namespace
type TemplatesNamespacer interface {
Templates(namespace string) TemplateInterface
}

// TemplateInterface exposes methods on Template resources.
type TemplateInterface interface {
List(label, field labels.Selector) (*templateapi.TemplateList, error)
Get(name string) (*templateapi.Template, error)
Create(template *templateapi.Template) (*templateapi.Template, error)
Update(template *templateapi.Template) (*templateapi.Template, error)
Delete(name string) error
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
}

// templates implements TemplatesNamespacer interface
type templates struct {
r *Client
ns string
}

// newTemplates returns a templates
func newTemplates(c *Client, namespace string) *templates {
return &templates{
r: c,
ns: namespace,
}
}

// List returns a list of templates that match the label and field selectors.
func (c *templates) List(label, field labels.Selector) (result *templateapi.TemplateList, err error) {
result = &templateapi.TemplateList{}
err = c.r.Get().
Namespace(c.ns).
Resource("templates").
SelectorParam("labels", label).
SelectorParam("fields", field).
Do().
Into(result)
return
}

// Get returns information about a particular template and error if one occurs.
func (c *templates) Get(name string) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Get().Namespace(c.ns).Resource("templates").Name(name).Do().Into(result)
return
}

// Create creates new template. Returns the server's representation of the template and error if one occurs.
func (c *templates) Create(template *templateapi.Template) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Post().Namespace(c.ns).Resource("templates").Body(template).Do().Into(result)
return
}

// Update updates the template on server. Returns the server's representation of the template and error if one occurs.
func (c *templates) Update(template *templateapi.Template) (result *templateapi.Template, err error) {
result = &templateapi.Template{}
err = c.r.Put().Namespace(c.ns).Resource("templates").Name(template.Name).Body(template).Do().Into(result)
return
}

// Delete deletes a template, returns error if one occurs.
func (c *templates) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("templates").Name(name).Do().Error()
return
}

// Watch returns a watch.Interface that watches the requested templates
func (c *templates) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("templates").
Param("resourceVersion", resourceVersion).
SelectorParam("labels", label).
SelectorParam("fields", field).
Watch()
}
Loading