Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random fixes #221

Merged
merged 6 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (c *Config) Build(ctx context.Context, opts *Options) (context.Context, *Se
return ctx, nil, err
}

if c.CustomizeSchemas != nil {
if err := c.CustomizeSchemas(ctx, c.ClientGetter, r.AllSchemas); err != nil {
return ctx, nil, err
}
}

if c.GlobalSetup != nil {
ctx, err = c.GlobalSetup(ctx)
if err != nil {
Expand All @@ -80,7 +86,7 @@ func (c *Config) Build(ctx context.Context, opts *Options) (context.Context, *Se
}

if !opts.DisableControllers {
go c.masterControllers(ctx, r)
go c.masterControllers(ctx, starters, r)
}

if !c.DisableAPI {
Expand All @@ -99,7 +105,7 @@ func (c *Config) Build(ctx context.Context, opts *Options) (context.Context, *Se
}

func (c *Config) apiServer(ctx context.Context, r *Runtime) error {
if c.K3s.RemoteDialerAuthorizer != nil {
if c.K3s.RemoteDialerAuthorizer != nil && r.K3sTunnelServer == nil {
r.K3sTunnelServer = remotedialer.New(c.K3s.RemoteDialerAuthorizer, remotedialer.DefaultErrorWriter)
}

Expand Down Expand Up @@ -129,18 +135,12 @@ func (c *Config) registerControllers(ctx context.Context, controllers []Controll
return nil
}

func (c *Config) masterControllers(ctx context.Context, r *Runtime) {
func (c *Config) masterControllers(ctx context.Context, starters []controller.Starter, r *Runtime) {
leader.RunOrDie(ctx, c.LeaderLockNamespace, c.Name, c.K8sClient, func(ctx context.Context) {
var (
err error
starters []controller.Starter
err error
)

ctx, starters, err = c.clients(ctx, r)
if err != nil {
logrus.Fatalf("failed to create master clients: %v", err)
}

if c.MasterSetup != nil {
ctx, err = c.MasterSetup(ctx)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions controller/generic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ func (g *genericController) Start(ctx context.Context, threadiness int) error {
g.Lock()
defer g.Unlock()

if !g.synced {
if err := g.sync(ctx); err != nil {
return err
}
if err := g.sync(ctx); err != nil {
return err
}

if !g.running {
Expand All @@ -202,7 +200,7 @@ func (g *genericController) Start(ctx context.Context, threadiness int) error {

if g.running {
for _, h := range g.handlers {
if h.generation != g.generation {
if h.generation < g.generation {
continue
}
for _, key := range g.informer.GetStore().ListKeys() {
Expand Down
4 changes: 2 additions & 2 deletions generator/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
baseK8s = "apis"
)

func DefaultGenerate(schemas *types.Schemas, pkgPath string, publicAPI bool, foreignTypes map[string]bool) error {
func DefaultGenerate(schemas *types.Schemas, pkgPath string, publicAPI bool, privateTypes map[string]bool) error {
version := getVersion(schemas)
group := strings.Split(version.Group, ".")[0]

Expand All @@ -24,7 +24,7 @@ func DefaultGenerate(schemas *types.Schemas, pkgPath string, publicAPI bool, for
}
k8sOutputPackage := path.Join(pkgPath, baseK8s, version.Group, version.Version)

if err := Generate(schemas, foreignTypes, cattleOutputPackage, k8sOutputPackage); err != nil {
if err := Generate(schemas, privateTypes, cattleOutputPackage, k8sOutputPackage); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage stri
return gofmt(baseDir, k8sOutputPackage)
}

func Generate(schemas *types.Schemas, foreignTypes map[string]bool, cattleOutputPackage, k8sOutputPackage string) error {
func Generate(schemas *types.Schemas, privateTypes map[string]bool, cattleOutputPackage, k8sOutputPackage string) error {
baseDir := args.DefaultSourceTree()
cattleDir := path.Join(baseDir, cattleOutputPackage)
k8sDir := path.Join(baseDir, k8sOutputPackage)
Expand All @@ -382,15 +382,15 @@ func Generate(schemas *types.Schemas, foreignTypes map[string]bool, cattleOutput
continue
}

_, backendType := foreignTypes[schema.ID]
_, privateType := privateTypes[schema.ID]

if cattleDir != "" {
if err := generateType(cattleDir, schema, schemas); err != nil {
return err
}
}

if backendType ||
if privateType ||
(contains(schema.CollectionMethods, http.MethodGet) &&
!strings.HasPrefix(schema.PkgName, "k8s.io") &&
!strings.Contains(schema.PkgName, "/vendor/")) {
Expand All @@ -403,7 +403,7 @@ func Generate(schemas *types.Schemas, foreignTypes map[string]bool, cattleOutput
}
}

if !backendType {
if !privateType {
cattleClientTypes = append(cattleClientTypes, schema)
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/subscribe/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ func handler(apiContext *types.APIContext) error {
if schema != nil {
buffer := &bytes.Buffer{}
if err := jsonWriter.VersionBody(apiContext, &schema.Version, buffer, item); err != nil {
return err
cancel()
continue
}

if err := writeData(c, header, buffer.Bytes()); err != nil {
return err
cancel()
}
}
case <-t.C:
if err := writeData(c, `{"name":"ping","data":`, []byte("{}")); err != nil {
return err
cancel()
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ type Config struct {
Threadiness int
K3s K3sConfig

GlobalSetup func(context.Context) (context.Context, error)
MasterSetup func(context.Context) (context.Context, error)
PreStart func(context.Context) error
APISetup func(context.Context, *api.Server) error
CustomizeSchemas func(context.Context, proxy.ClientGetter, *types.Schemas) error
GlobalSetup func(context.Context) (context.Context, error)
MasterSetup func(context.Context) (context.Context, error)
PreStart func(context.Context) error
APISetup func(context.Context, *api.Server) error

PerServerControllers []ControllerRegister
MasterControllers []ControllerRegister
Expand Down