Skip to content

Commit

Permalink
Add offspring controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 20, 2017
1 parent 2825fdb commit c248eec
Show file tree
Hide file tree
Showing 11 changed files with 630 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/builtin/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ var (
APIRoot = types.Schema{
ID: "apiRoot",
Version: Version,
ResourceMethods: []string{},
CollectionMethods: []string{},
CollectionMethods: []string{"GET"},
ResourceMethods: []string{"GET"},
ResourceFields: map[string]types.Field{
"apiVersion": {Type: "map[json]"},
"path": {Type: "string"},
Expand Down
34 changes: 34 additions & 0 deletions clientbase/object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (p *ObjectClient) UnstructuredClient() *ObjectClient {
}
}

func (p *ObjectClient) GroupVersionKind() schema.GroupVersionKind {
return p.gvk
}

func (p *ObjectClient) getAPIPrefix() string {
if p.gvk.Group == "" {
return "api"
Expand Down Expand Up @@ -90,6 +94,23 @@ func (p *ObjectClient) Create(o runtime.Object) (runtime.Object, error) {
return result, err
}

func (p *ObjectClient) GetNamespace(name, namespace string, opts metav1.GetOptions) (runtime.Object, error) {
result := p.Factory.Object()
req := p.restClient.Get().
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version)
if namespace != "" {
req = req.Namespace(namespace)
}
err := req.NamespaceIfScoped(p.ns, p.resource.Namespaced).
Resource(p.resource.Name).
VersionedParams(&opts, dynamic.VersionedParameterEncoderWithV1Fallback).
Name(name).
Do().
Into(result)
return result, err

}

func (p *ObjectClient) Get(name string, opts metav1.GetOptions) (runtime.Object, error) {
result := p.Factory.Object()
err := p.restClient.Get().
Expand Down Expand Up @@ -123,6 +144,19 @@ func (p *ObjectClient) Update(name string, o runtime.Object) (runtime.Object, er
return result, err
}

func (p *ObjectClient) DeleteNamespace(name, namespace string, opts *metav1.DeleteOptions) error {
req := p.restClient.Delete().
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version)
if namespace != "" {
req = req.Namespace(namespace)
}
return req.Resource(p.resource.Name).
Name(name).
Body(opts).
Do().
Error()
}

func (p *ObjectClient) Delete(name string, opts *metav1.DeleteOptions) error {
return p.restClient.Delete().
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version).
Expand Down
2 changes: 1 addition & 1 deletion controller/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Starter interface {
Start(ctx context.Context, threadiness int) error
}

func SyncThenSync(ctx context.Context, threadiness int, starters ...Starter) error {
func SyncThenStart(ctx context.Context, threadiness int, starters ...Starter) error {
if err := Sync(ctx, starters...); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Baz struct {
var (
version = types.APIVersion{
Version: "v1",
Group: "io.cattle.core.example",
Group: "example.core.cattle.io",
Path: "/example/v1",
}

Expand Down
19 changes: 18 additions & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func generateClient(outputDir string, schemas []*types.Schema) error {
})
}

func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage string, objs ...interface{}) error {
func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage string, nsObjs []interface{}, objs []interface{}) error {
baseDir := args.DefaultSourceTree()
k8sDir := path.Join(baseDir, k8sOutputPackage)

Expand All @@ -294,6 +294,23 @@ func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage stri
}
}

for _, obj := range nsObjs {
schema, err := schemas.Import(version, obj)
if err != nil {
return err
}
schema.Scope = types.NamespaceScope
controllers = append(controllers, schema)

if err := generateController(true, k8sDir, schema, schemas); err != nil {
return err
}

if err := generateLifecycle(true, k8sDir, schema, schemas); err != nil {
return err
}
}

if err := deepCopyGen(baseDir, k8sOutputPackage); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion lifecycle/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
created = "io.cattle.lifecycle.create"
created = "lifecycle.cattle.io/create"
)

type ObjectLifecycle interface {
Expand Down
Loading

0 comments on commit c248eec

Please sign in to comment.