Skip to content

Commit

Permalink
Merge pull request #363 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Rebase on lasso
  • Loading branch information
ibuildthecloud authored May 17, 2020
2 parents 07a7713 + d8b2637 commit f53cae1
Show file tree
Hide file tree
Showing 43 changed files with 5,535 additions and 2,351 deletions.
379 changes: 25 additions & 354 deletions controller/generic_controller.go

Large diffs are not rendered by default.

107 changes: 0 additions & 107 deletions controller/noop_metrics.go

This file was deleted.

40 changes: 0 additions & 40 deletions controller/starter.go

This file was deleted.

44 changes: 18 additions & 26 deletions generator/controller_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
}
{{.schema.CodeName}}Resource = metav1.APIResource{
Name: "{{.schema.PluralName | toLower}}",
SingularName: "{{.schema.ID | toLower}}",
SingularName: "{{.schema.CodeName | toLower}}",
{{- if eq .schema.Scope "namespace" }}
Namespaced: true,
{{ else }}
Expand All @@ -55,11 +55,13 @@ func New{{.schema.CodeName}}(namespace, name string, obj {{.prefix}}{{.schema.Co
return &obj
}
{{ if eq .prefix "" }}
type {{.schema.CodeName}}List struct {
metav1.TypeMeta %BACK%json:",inline"%BACK%
metav1.ListMeta %BACK%json:"metadata,omitempty"%BACK%
Items []{{.prefix}}{{.schema.CodeName}} %BACK%json:"items"%BACK%
}
{{- end }}
type {{.schema.CodeName}}HandlerFunc func(key string, obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error)
Expand All @@ -80,8 +82,6 @@ type {{.schema.CodeName}}Controller interface {
AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, clusterName string, handler {{.schema.CodeName}}HandlerFunc)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, after time.Duration)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}
type {{.schema.CodeName}}Interface interface {
Expand All @@ -92,8 +92,8 @@ type {{.schema.CodeName}}Interface interface {
Update(*{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error)
Delete(name string, options *metav1.DeleteOptions) error
DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error)
ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.schema.CodeName}}List, error)
List(opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error)
ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() {{.schema.CodeName}}Controller
Expand Down Expand Up @@ -132,7 +132,7 @@ func (l *{{.schema.ID}}Lister) Get(namespace, name string) (*{{.prefix}}{{.schem
if !exists {
return nil, errors.NewNotFound(schema.GroupResource{
Group: {{.schema.CodeName}}GroupVersionKind.Group,
Resource: "{{.schema.ID}}",
Resource: {{.schema.CodeName}}GroupVersionResource.Resource,
}, key)
}
return obj.(*{{.prefix}}{{.schema.CodeName}}), nil
Expand Down Expand Up @@ -213,29 +213,16 @@ func (c {{.schema.ID}}Factory) Object() runtime.Object {
}
func (c {{.schema.ID}}Factory) List() runtime.Object {
return &{{.schema.CodeName}}List{}
return &{{.prefix}}{{.schema.CodeName}}List{}
}
func (s *{{.schema.ID}}Client) Controller() {{.schema.CodeName}}Controller {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.{{.schema.ID}}Controllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController({{.schema.CodeName}}GroupVersionKind.Kind+"Controller",
s.objectClient)
s.client.controllerFactory.ForResourceKind({{.schema.CodeName}}GroupVersionResource, {{.schema.CodeName}}GroupVersionKind.Kind, {{.schema | namespaced}}))
c = &{{.schema.ID}}Controller{
return &{{.schema.ID}}Controller{
GenericController: genericController,
}
s.client.{{.schema.ID}}Controllers[s.ns] = c
s.client.starters = append(s.client.starters, c)
return c
}
type {{.schema.ID}}Client struct {
Expand Down Expand Up @@ -269,6 +256,11 @@ func (s *{{.schema.ID}}Client) Update(o *{{.prefix}}{{.schema.CodeName}}) (*{{.p
return obj.(*{{.prefix}}{{.schema.CodeName}}), err
}
func (s *{{.schema.ID}}Client) UpdateStatus(o *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) {
obj, err := s.objectClient.UpdateStatus(o.Name, o)
return obj.(*{{.prefix}}{{.schema.CodeName}}), err
}
func (s *{{.schema.ID}}Client) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
Expand All @@ -277,14 +269,14 @@ func (s *{{.schema.ID}}Client) DeleteNamespaced(namespace, name string, options
return s.objectClient.DeleteNamespaced(namespace, name, options)
}
func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) {
func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error) {
obj, err := s.objectClient.List(opts)
return obj.(*{{.schema.CodeName}}List), err
return obj.(*{{.prefix}}{{.schema.CodeName}}List), err
}
func (s *{{.schema.ID}}Client) ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) {
func (s *{{.schema.ID}}Client) ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error) {
obj, err := s.objectClient.ListNamespaced(namespace, opts)
return obj.(*{{.schema.CodeName}}List), err
return obj.(*{{.prefix}}{{.schema.CodeName}}List), err
}
func (s *{{.schema.ID}}Client) Watch(opts metav1.ListOptions) (watch.Interface, error) {
Expand Down
66 changes: 0 additions & 66 deletions generator/default.go

This file was deleted.

5 changes: 5 additions & 0 deletions generator/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func funcs() template.FuncMap {
"hasGet": hasGet,
"hasPost": hasPost,
"getCollectionOutput": getCollectionOutput,
"namespaced": namespaced,
}
}

Expand All @@ -29,6 +30,10 @@ func hasGet(schema *types.Schema) bool {
return contains(schema.CollectionMethods, http.MethodGet)
}

func namespaced(schema *types.Schema) bool {
return schema.Scope == types.NamespaceScope
}

func hasPost(schema *types.Schema) bool {
return contains(schema.CollectionMethods, http.MethodPost)
}
Expand Down
Loading

0 comments on commit f53cae1

Please sign in to comment.