forked from openshift/origin
/
templateconfigs.go
64 lines (56 loc) · 1.93 KB
/
templateconfigs.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package client
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
templateapi "github.com/openshift/origin/pkg/template/api"
)
// TemplateConfigNamespacer has methods to work with Image resources in a namespace
// TODO: Rename to ProcessedTemplates
type TemplateConfigsNamespacer interface {
TemplateConfigs(namespace string) TemplateConfigInterface
}
// TemplateConfigInterface exposes methods on Image resources.
type TemplateConfigInterface interface {
Create(t *templateapi.Template) (*templateapi.Template, error)
}
// templateConfigs implements TemplateConfigsNamespacer interface
type templateConfigs struct {
r *Client
ns string
}
// newTemplateConfigs returns an TemplateConfigInterface
func newTemplateConfigs(c *Client, namespace string) TemplateConfigInterface {
return &templateConfigs{
r: c,
ns: namespace,
}
}
// resourceName returns templates's URL resource name based on resource version.
// Uses "templateConfigs" as the URL resource name for v1beta1 and v1beta2.
func (c *templateConfigs) resourceName() string {
if kapi.PreV1Beta3(c.r.APIVersion()) {
return "templateConfigs"
}
return "processedTemplates"
}
// Create process the Template and returns its current state
func (c *templateConfigs) Create(in *templateapi.Template) (*templateapi.Template, error) {
if kapi.PreV1Beta3(c.r.APIVersion()) {
// TODO: path is deprecated, remove
config := &kapi.List{}
if err := c.r.Post().Namespace(c.ns).Resource(c.resourceName()).Body(in).Do().Into(config); err != nil {
return nil, err
}
// TODO: support copy instead of mutating the in, once we have a way to deep copy runtime.Object
// in upstream.
/*t, err := kapi.Scheme.Copy(in)
if err != nil {
return nil, err
}*/
template := in
template.Objects = config.Items
return template, nil
}
template := &templateapi.Template{}
err := c.r.Post().Namespace(c.ns).Resource(c.resourceName()).Body(in).Do().Into(template)
return template, err
}