-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Refactor controller initialization (part 2) #14293
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,10 +51,33 @@ func init() { | |
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("get", "list", "watch", "update", "delete").Groups(buildGroup, legacyBuildGroup).Resources("builds").RuleOrDie(), | ||
rbac.NewRule("get").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs").RuleOrDie(), | ||
rbac.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("builds/docker", "builds/source", "builds/custom", "builds/jenkinspipeline").RuleOrDie(), | ||
rbac.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("builds/optimizeddocker", "builds/docker", "builds/source", "builds/custom", "builds/jenkinspipeline").RuleOrDie(), | ||
rbac.NewRule("get").Groups(imageGroup, legacyImageGroup).Resources("imagestreams").RuleOrDie(), | ||
rbac.NewRule("get", "list", "create", "delete").Groups(kapiGroup).Resources("pods").RuleOrDie(), | ||
rbac.NewRule("get").Groups(kapiGroup).Resources("namespaces").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
|
||
// build-pod-controller | ||
addControllerRole(rbac.ClusterRole{ | ||
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraBuildPodControllerServiceAccountName}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("create", "get", "list", "watch", "update", "delete").Groups(buildGroup, legacyBuildGroup).Resources("builds").RuleOrDie(), | ||
rbac.NewRule("get", "list", "create", "delete").Groups(kapiGroup).Resources("pods").RuleOrDie(), | ||
rbac.NewRule("get").Groups(kapiGroup).Resources("secrets").RuleOrDie(), | ||
rbac.NewRule("get").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs").RuleOrDie(), | ||
// Needed for strategyrestriction admission | ||
rbac.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("builds/optimizeddocker", "builds/docker", "builds/source", "builds/custom", "builds/jenkinspipeline").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
|
||
// build-config-change-controller | ||
addControllerRole(rbac.ClusterRole{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bparees and this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delegate to @csrwng, he just touched this whole space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @csrwng ping. |
||
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraBuildConfigChangeControllerServiceAccountName}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("get", "list", "watch").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs").RuleOrDie(), | ||
rbac.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs/instantiate").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
|
@@ -103,8 +126,39 @@ func init() { | |
}, | ||
}) | ||
|
||
// template-instance-controller | ||
controllerRoleBindings = append(controllerRoleBindings, | ||
rbac.NewClusterBinding(EditRoleName).SAs(DefaultOpenShiftInfraNamespace, InfraTemplateInstanceControllerServiceAccountName).BindingOrDie()) | ||
|
||
// origin-namespace-controller | ||
addControllerRole(rbac.ClusterRole{ | ||
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraOriginNamespaceServiceAccountName}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("get", "list", "watch").Groups(kapiGroup).Resources("namespaces").RuleOrDie(), | ||
rbac.NewRule("update").Groups(kapiGroup).Resources("namespaces/finalize", "namespaces/status").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
|
||
// serviceaccount-controller | ||
addControllerRole(rbac.ClusterRole{ | ||
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraServiceAccountControllerServiceAccountName}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("get", "list", "watch", "create", "update", "patch", "delete").Groups(kapiGroup).Resources("serviceaccounts").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
|
||
// serviceaccount-pull-secrets-controller | ||
addControllerRole(rbac.ClusterRole{ | ||
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraServiceAccountPullSecretsControllerServiceAccountName}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule("get", "list", "watch", "create", "update").Groups(kapiGroup).Resources("serviceaccounts").RuleOrDie(), | ||
rbac.NewRule("get", "list", "watch", "create", "update", "patch", "delete").Groups(kapiGroup).Resources("secrets").RuleOrDie(), | ||
rbac.NewRule("get", "list", "watch").Groups(kapiGroup).Resources("services").RuleOrDie(), | ||
eventsRule(), | ||
}, | ||
}) | ||
} | ||
|
||
// ControllerRoles returns the cluster roles used by controllers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" | ||
projectcontroller "github.com/openshift/origin/pkg/project/controller" | ||
) | ||
|
||
func RunOriginNamespaceController(ctx ControllerContext) (bool, error) { | ||
controller := projectcontroller.NewProjectFinalizerController( | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().Namespaces(), | ||
ctx.ClientBuilder.KubeInternalClientOrDie(bootstrappolicy.InfraOriginNamespaceServiceAccountName), | ||
) | ||
go controller.Run(ctx.Stop, 5) | ||
return true, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
|
||
kapiv1 "k8s.io/kubernetes/pkg/api/v1" | ||
"k8s.io/kubernetes/pkg/controller" | ||
sacontroller "k8s.io/kubernetes/pkg/controller/serviceaccount" | ||
"k8s.io/kubernetes/pkg/serviceaccount" | ||
|
||
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" | ||
serviceaccountcontrollers "github.com/openshift/origin/pkg/serviceaccounts/controllers" | ||
) | ||
|
||
type ServiceAccountControllerOptions struct { | ||
ManagedNames []string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this. Much cleaner than what we had before. |
||
} | ||
|
||
func (c *ServiceAccountControllerOptions) RunController(ctx ControllerContext) (bool, error) { | ||
if len(c.ManagedNames) == 0 { | ||
glog.Infof("Skipped starting Service Account Manager, no managed names specified") | ||
return false, nil | ||
} | ||
|
||
options := sacontroller.DefaultServiceAccountsControllerOptions() | ||
options.ServiceAccounts = []kapiv1.ServiceAccount{} | ||
|
||
for _, saName := range c.ManagedNames { | ||
sa := kapiv1.ServiceAccount{} | ||
sa.Name = saName | ||
|
||
options.ServiceAccounts = append(options.ServiceAccounts, sa) | ||
} | ||
|
||
go sacontroller.NewServiceAccountsController( | ||
ctx.DeprecatedOpenshiftInformers.KubernetesInformers().Core().V1().ServiceAccounts(), | ||
ctx.DeprecatedOpenshiftInformers.KubernetesInformers().Core().V1().Namespaces(), | ||
ctx.ClientBuilder.ClientOrDie(bootstrappolicy.InfraServiceAccountControllerServiceAccountName), | ||
options).Run(3, ctx.Stop) | ||
|
||
return true, nil | ||
} | ||
|
||
type ServiceAccountTokensControllerOptions struct { | ||
RootCA []byte | ||
ServiceServingCA []byte | ||
PrivateKey interface{} | ||
|
||
RootClientBuilder controller.SimpleControllerClientBuilder | ||
} | ||
|
||
func (c *ServiceAccountTokensControllerOptions) RunController(ctx ControllerContext) (bool, error) { | ||
go sacontroller.NewTokensController( | ||
ctx.DeprecatedOpenshiftInformers.KubernetesInformers().Core().V1().ServiceAccounts(), | ||
ctx.DeprecatedOpenshiftInformers.KubernetesInformers().Core().V1().Secrets(), | ||
c.RootClientBuilder.ClientOrDie(bootstrappolicy.InfraServiceAccountTokensControllerServiceAccountName), | ||
sacontroller.TokensControllerOptions{ | ||
TokenGenerator: serviceaccount.JWTTokenGenerator(c.PrivateKey), | ||
RootCA: c.RootCA, | ||
ServiceServingCA: c.ServiceServingCA, | ||
}, | ||
).Run(int(ctx.KubeControllerContext.Options.ConcurrentSATokenSyncs), ctx.Stop) | ||
return true, nil | ||
} | ||
|
||
func RunServiceAccountPullSecretsController(ctx ControllerContext) (bool, error) { | ||
kc := ctx.ClientBuilder.KubeInternalClientOrDie(bootstrappolicy.InfraServiceAccountPullSecretsControllerServiceAccountName) | ||
|
||
go serviceaccountcontrollers.NewDockercfgDeletedController( | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().Secrets(), | ||
kc, | ||
serviceaccountcontrollers.DockercfgDeletedControllerOptions{}, | ||
).Run(ctx.Stop) | ||
|
||
go serviceaccountcontrollers.NewDockercfgTokenDeletedController( | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().Secrets(), | ||
kc, | ||
serviceaccountcontrollers.DockercfgTokenDeletedControllerOptions{}, | ||
).Run(ctx.Stop) | ||
|
||
dockerURLsInitialized := make(chan struct{}) | ||
dockercfgController := serviceaccountcontrollers.NewDockercfgController( | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().ServiceAccounts(), | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().Secrets(), | ||
kc, | ||
serviceaccountcontrollers.DockercfgControllerOptions{DockerURLsInitialized: dockerURLsInitialized}, | ||
) | ||
go dockercfgController.Run(5, ctx.Stop) | ||
|
||
dockerRegistryControllerOptions := serviceaccountcontrollers.DockerRegistryServiceControllerOptions{ | ||
RegistryNamespace: "default", | ||
RegistryServiceName: "docker-registry", | ||
DockercfgController: dockercfgController, | ||
DockerURLsInitialized: dockerURLsInitialized, | ||
} | ||
go serviceaccountcontrollers.NewDockerRegistryServiceController( | ||
ctx.DeprecatedOpenshiftInformers.InternalKubernetesInformers().Core().InternalVersion().Secrets(), | ||
kc, | ||
dockerRegistryControllerOptions, | ||
).Run(10, ctx.Stop) | ||
|
||
return true, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bparees can you please review these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delegate to @csrwng, he just touched this whole space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csrwng need to make sure I don't miss any client calls you do and I don't have any extra listed here...