Merge pull request #113747 from thockin/safer-controller-init-map

Make static controller registration slightly safer
This commit is contained in:
Kubernetes Prow Robot 2022-11-08 12:43:25 -08:00 committed by GitHub
commit 2f22404003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -422,49 +422,58 @@ const (
// paired to their InitFunc. This allows for structured downstream composition and subdivision. // paired to their InitFunc. This allows for structured downstream composition and subdivision.
func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc { func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc {
controllers := map[string]InitFunc{} controllers := map[string]InitFunc{}
controllers["endpoint"] = startEndpointController
controllers["endpointslice"] = startEndpointSliceController // All of the controllers must have unique names, or else we will explode.
controllers["endpointslicemirroring"] = startEndpointSliceMirroringController register := func(name string, fn InitFunc) {
controllers["replicationcontroller"] = startReplicationController if _, found := controllers[name]; found {
controllers["podgc"] = startPodGCController panic(fmt.Sprintf("controller name %q was registered twice", name))
controllers["resourcequota"] = startResourceQuotaController }
controllers["namespace"] = startNamespaceController controllers[name] = fn
controllers["serviceaccount"] = startServiceAccountController }
controllers["garbagecollector"] = startGarbageCollectorController
controllers["daemonset"] = startDaemonSetController register("endpoint", startEndpointController)
controllers["job"] = startJobController register("endpointslice", startEndpointSliceController)
controllers["deployment"] = startDeploymentController register("endpointslicemirroring", startEndpointSliceMirroringController)
controllers["replicaset"] = startReplicaSetController register("replicationcontroller", startReplicationController)
controllers["horizontalpodautoscaling"] = startHPAController register("podgc", startPodGCController)
controllers["disruption"] = startDisruptionController register("resourcequota", startResourceQuotaController)
controllers["statefulset"] = startStatefulSetController register("namespace", startNamespaceController)
controllers["cronjob"] = startCronJobController register("serviceaccount", startServiceAccountController)
controllers["csrsigning"] = startCSRSigningController register("garbagecollector", startGarbageCollectorController)
controllers["csrapproving"] = startCSRApprovingController register("daemonset", startDaemonSetController)
controllers["csrcleaner"] = startCSRCleanerController register("job", startJobController)
controllers["ttl"] = startTTLController register("deployment", startDeploymentController)
controllers["bootstrapsigner"] = startBootstrapSignerController register("replicaset", startReplicaSetController)
controllers["tokencleaner"] = startTokenCleanerController register("horizontalpodautoscaling", startHPAController)
controllers["nodeipam"] = startNodeIpamController register("disruption", startDisruptionController)
controllers["nodelifecycle"] = startNodeLifecycleController register("statefulset", startStatefulSetController)
register("cronjob", startCronJobController)
register("csrsigning", startCSRSigningController)
register("csrapproving", startCSRApprovingController)
register("csrcleaner", startCSRCleanerController)
register("ttl", startTTLController)
register("bootstrapsigner", startBootstrapSignerController)
register("tokencleaner", startTokenCleanerController)
register("nodeipam", startNodeIpamController)
register("nodelifecycle", startNodeLifecycleController)
if loopMode == IncludeCloudLoops { if loopMode == IncludeCloudLoops {
controllers["service"] = startServiceController register("service", startServiceController)
controllers["route"] = startRouteController register("route", startRouteController)
controllers["cloud-node-lifecycle"] = startCloudNodeLifecycleController register("cloud-node-lifecycle", startCloudNodeLifecycleController)
// TODO: volume controller into the IncludeCloudLoops only set. // TODO: volume controller into the IncludeCloudLoops only set.
} }
controllers["persistentvolume-binder"] = startPersistentVolumeBinderController register("persistentvolume-binder", startPersistentVolumeBinderController)
controllers["attachdetach"] = startAttachDetachController register("attachdetach", startAttachDetachController)
controllers["persistentvolume-expander"] = startVolumeExpandController register("persistentvolume-expander", startVolumeExpandController)
controllers["clusterrole-aggregation"] = startClusterRoleAggregrationController register("clusterrole-aggregation", startClusterRoleAggregrationController)
controllers["pvc-protection"] = startPVCProtectionController register("pvc-protection", startPVCProtectionController)
controllers["pv-protection"] = startPVProtectionController register("pv-protection", startPVProtectionController)
controllers["ttl-after-finished"] = startTTLAfterFinishedController register("ttl-after-finished", startTTLAfterFinishedController)
controllers["root-ca-cert-publisher"] = startRootCACertPublisher register("root-ca-cert-publisher", startRootCACertPublisher)
controllers["ephemeral-volume"] = startEphemeralVolumeController register("ephemeral-volume", startEphemeralVolumeController)
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerIdentity) && if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerIdentity) &&
utilfeature.DefaultFeatureGate.Enabled(genericfeatures.StorageVersionAPI) { utilfeature.DefaultFeatureGate.Enabled(genericfeatures.StorageVersionAPI) {
controllers["storage-version-gc"] = startStorageVersionGCController register("storage-version-gc", startStorageVersionGCController)
} }
return controllers return controllers