2017-11-13 19:50:25 +00:00
|
|
|
package generator
|
|
|
|
|
|
|
|
var k8sClientTemplate = `package {{.version.Version}}
|
|
|
|
|
|
|
|
import (
|
2020-05-16 00:38:28 +00:00
|
|
|
"github.com/rancher/lasso/pkg/client"
|
|
|
|
"github.com/rancher/lasso/pkg/controller"
|
2018-04-03 19:49:20 +00:00
|
|
|
"github.com/rancher/norman/objectclient"
|
2020-05-16 00:38:28 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2017-11-13 19:50:25 +00:00
|
|
|
"k8s.io/client-go/rest"
|
2020-07-14 19:25:37 +00:00
|
|
|
{{.importPackage}}
|
2017-11-13 19:50:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Interface interface {
|
|
|
|
{{range .schemas}}
|
|
|
|
{{.CodeNamePlural}}Getter{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Client struct {
|
2020-05-16 00:38:28 +00:00
|
|
|
controllerFactory controller.SharedControllerFactory
|
|
|
|
clientFactory client.SharedClientFactory
|
2017-11-13 19:50:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 00:38:28 +00:00
|
|
|
func NewForConfig(cfg rest.Config) (Interface, error) {
|
|
|
|
scheme := runtime.NewScheme()
|
2020-07-14 19:25:37 +00:00
|
|
|
if err := {{.prefix}}AddToScheme(scheme); err != nil {
|
2020-05-16 00:38:28 +00:00
|
|
|
return nil, err
|
2017-11-13 19:50:25 +00:00
|
|
|
}
|
2020-05-16 00:38:28 +00:00
|
|
|
controllerFactory, err := controller.NewSharedControllerFactoryFromConfig(&cfg, scheme)
|
2017-11-13 19:50:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-16 00:38:28 +00:00
|
|
|
return NewFromControllerFactory(controllerFactory)
|
|
|
|
}
|
2017-11-13 19:50:25 +00:00
|
|
|
|
2020-05-16 00:38:28 +00:00
|
|
|
func NewFromControllerFactory(factory controller.SharedControllerFactory) (Interface, error) {
|
2017-11-13 19:50:25 +00:00
|
|
|
return &Client{
|
2020-05-16 00:38:28 +00:00
|
|
|
controllerFactory: factory,
|
|
|
|
clientFactory: factory.SharedCacheFactory().SharedClientFactory(),
|
2017-11-13 19:50:25 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .schemas}}
|
|
|
|
type {{.CodeNamePlural}}Getter interface {
|
|
|
|
{{.CodeNamePlural}}(namespace string) {{.CodeName}}Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) {{.CodeNamePlural}}(namespace string) {{.CodeName}}Interface {
|
2020-05-16 00:38:28 +00:00
|
|
|
sharedClient := c.clientFactory.ForResourceKind({{.CodeName}}GroupVersionResource, {{.CodeName}}GroupVersionKind.Kind, {{ . | namespaced }})
|
|
|
|
objectClient := objectclient.NewObjectClient(namespace, sharedClient, &{{.CodeName}}Resource, {{.CodeName}}GroupVersionKind, {{.ID}}Factory{})
|
2017-11-13 19:50:25 +00:00
|
|
|
return &{{.ID}}Client{
|
|
|
|
ns: namespace,
|
|
|
|
client: c,
|
|
|
|
objectClient: objectClient,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
`
|