forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
36 lines (29 loc) · 1.22 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package generator
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/build/generator"
"github.com/openshift/origin/pkg/build/registry/instantiate"
)
// NewStorage creates a new storage object for build generation
func NewStorage(generator *generator.BuildGenerator) *InstantiateREST {
return &InstantiateREST{generator: generator}
}
// InstantiateREST is a RESTStorage implementation for a BuildGenerator which supports only
// the Get operation (as the generator has no underlying storage object).
type InstantiateREST struct {
generator *generator.BuildGenerator
}
// New creates a new build generation request
func (s *InstantiateREST) New() runtime.Object {
return &buildapi.BuildRequest{}
}
// Create instantiates a new build from a build configuration
func (s *InstantiateREST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
if err := rest.BeforeCreate(instantiate.Strategy, ctx, obj); err != nil {
return nil, err
}
return s.generator.Instantiate(ctx, obj.(*buildapi.BuildRequest))
}