Skip to content

Commit

Permalink
Move user controllers to agent
Browse files Browse the repository at this point in the history
  • Loading branch information
dramich authored and ibuildthecloud committed Oct 16, 2018
1 parent f18af13 commit c31fb40
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 6 deletions.
35 changes: 35 additions & 0 deletions pkg/agent/cluster/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cluster

import (
"context"

clusterController "github.com/rancher/rancher/pkg/controllers/user"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
"k8s.io/client-go/rest"
)

func RunControllers() error {
logrus.Info("Starting user controllers")
c, err := rest.InClusterConfig()
if err != nil {
return err
}

userOnly, err := config.NewUserOnlyContext(*c)
if err != nil {
return err
}

err = clusterController.RegisterUserOnly(context.Background(), userOnly)
if err != nil {
return err
}

err = userOnly.Start(context.Background())
if err != nil {
return err
}

return nil
}
4 changes: 4 additions & 0 deletions pkg/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func run() error {
}

if isCluster() {
err = cluster.RunControllers()
if err != nil {
logrus.Fatal(err)
}
return nil
}

Expand Down
27 changes: 22 additions & 5 deletions pkg/controllers/user/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/rancher/rancher/pkg/controllers/user/targetworkloadservice"
"github.com/rancher/rancher/pkg/controllers/user/workload"
"github.com/rancher/types/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// init upgrade implement
_ "github.com/rancher/rancher/pkg/controllers/user/alert/upgrade"
Expand Down Expand Up @@ -57,12 +58,19 @@ func Register(ctx context.Context, cluster *config.UserContext, kubeConfigGetter
resourcequota.Register(ctx, cluster)

userOnlyContext := cluster.UserOnlyContext()
dnsrecord.Register(ctx, userOnlyContext)
externalservice.Register(ctx, userOnlyContext)
ingress.Register(ctx, userOnlyContext, cluster)
ingresshostgen.Register(userOnlyContext)
targetworkloadservice.Register(ctx, userOnlyContext)
workload.Register(ctx, userOnlyContext)

c, err := cluster.Management.Management.Clusters("").Get(cluster.ClusterName, metav1.GetOptions{})
if err != nil {
return err
}

if c.Spec.Internal {
err = RegisterUserOnly(ctx, userOnlyContext)
if err != nil {
return err
}
}

return nil
}
Expand All @@ -73,3 +81,12 @@ func RegisterFollower(ctx context.Context, cluster *config.UserContext, kubeConf
cluster.RBAC.RoleBindings("").Controller()
return nil
}

func RegisterUserOnly(ctx context.Context, cluster *config.UserOnlyContext) error {
dnsrecord.Register(ctx, cluster)
externalservice.Register(ctx, cluster)
ingresshostgen.Register(cluster)
targetworkloadservice.Register(ctx, cluster)
workload.Register(ctx, cluster)
return nil
}
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ github.com/smartystreets/go-aws-auth 8ef1316913ee4f44bc48c2456e44a5c1c6
github.com/mcuadros/go-version 6d5863ca60fa6fe914b5fd43ed8533d7567c5b0b

github.com/rancher/rdns-server bf662911db6acce4d6a85d2878653f68413b9176
github.com/rancher/types 52df5bbb83f3271986a9f781778d1657cc288d3d
github.com/rancher/types 006bf1d436540f6725b95988c2bdd21c7f891c3c


github.com/rancher/norman ad4865987ce75d8d012441478e193eaaa1e1078f
Expand Down
64 changes: 64 additions & 0 deletions vendor/github.com/rancher/types/config/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c31fb40

Please sign in to comment.