Skip to content

Commit 3d5c295

Browse files
Merge pull request #18658 from smarterclayton/ingress_to_route
Replace router support for ingress with an ingress-to-route controller
2 parents 8a2f52d + c36b2e5 commit 3d5c295

31 files changed

+2925
-1461
lines changed

pkg/cmd/infra/router/f5.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (o *F5RouterOptions) Run() error {
251251

252252
factory := o.RouterSelection.NewFactory(routeclient, projectclient.Project().Projects(), kc)
253253
watchNodes := (len(o.InternalAddress) != 0 && len(o.VxlanGateway) != 0)
254-
controller := factory.Create(plugin, watchNodes, o.EnableIngress)
254+
controller := factory.Create(plugin, watchNodes)
255255
controller.Run()
256256

257257
select {}

pkg/cmd/infra/router/router.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ type RouterSelection struct {
6060

6161
ExtendedValidation bool
6262

63-
EnableIngress bool
64-
6563
ListenAddr string
6664
}
6765

@@ -82,8 +80,9 @@ func (o *RouterSelection) Bind(flag *pflag.FlagSet) {
8280
flag.StringSliceVar(&o.AllowedDomains, "allowed-domains", envVarAsStrings("ROUTER_ALLOWED_DOMAINS", "", ","), "List of comma separated domains to allow in routes. If specified, only the domains in this list will be allowed routes. Note that domains in the denied list take precedence over the ones in the allowed list")
8381
flag.BoolVar(&o.AllowWildcardRoutes, "allow-wildcard-routes", isTrue(cmdutil.Env("ROUTER_ALLOW_WILDCARD_ROUTES", "")), "Allow wildcard host names for routes")
8482
flag.BoolVar(&o.DisableNamespaceOwnershipCheck, "disable-namespace-ownership-check", isTrue(cmdutil.Env("ROUTER_DISABLE_NAMESPACE_OWNERSHIP_CHECK", "")), "Disables the namespace ownership checks for a route host with different paths or for overlapping host names in the case of wildcard routes. Please be aware that if namespace ownership checks are disabled, routes in a different namespace can use this mechanism to 'steal' sub-paths for existing domains. This is only safe if route creation privileges are restricted, or if all the users can be trusted.")
85-
flag.BoolVar(&o.EnableIngress, "enable-ingress", isTrue(cmdutil.Env("ROUTER_ENABLE_INGRESS", "")), "Enable configuration via ingress resources")
8683
flag.BoolVar(&o.ExtendedValidation, "extended-validation", isTrue(cmdutil.Env("EXTENDED_VALIDATION", "true")), "If set, then an additional extended validation step is performed on all routes admitted in by this router. Defaults to true and enables the extended validation checks.")
84+
flag.Bool("enable-ingress", false, "Enable configuration via ingress resources.")
85+
flag.MarkDeprecated("enable-ingress", "Ingress resources are now synchronized to routes automatically.")
8786
flag.StringVar(&o.ListenAddr, "listen-addr", cmdutil.Env("ROUTER_LISTEN_ADDR", ""), "The name of an interface to listen on to expose metrics and health checking. If not specified, will not listen. Overrides stats port.")
8887
}
8988

@@ -96,14 +95,10 @@ func (o *RouterSelection) RouteSelectionFunc() controller.RouteHostFunc {
9695
if !o.OverrideHostname && len(route.Spec.Host) > 0 {
9796
return route.Spec.Host
9897
}
99-
// GetNameForHost returns the ingress name for a generated route, and the route route
100-
// name otherwise. When a route and ingress in the same namespace share a name, the
101-
// route and the ingress' rules should receive the same generated host.
102-
nameForHost := controller.GetNameForHost(route.Name)
10398
s, err := variable.ExpandStrict(o.HostnameTemplate, func(key string) (string, bool) {
10499
switch key {
105100
case "name":
106-
return nameForHost, true
101+
return route.Name, true
107102
case "namespace":
108103
return route.Namespace, true
109104
default:

pkg/cmd/infra/router/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (o *TemplateRouterOptions) Run() error {
431431
plugin = controller.NewHostAdmitter(plugin, o.RouteAdmissionFunc(), o.AllowWildcardRoutes, o.RouterSelection.DisableNamespaceOwnershipCheck, recorder)
432432

433433
factory := o.RouterSelection.NewFactory(routeclient, projectclient.Project().Projects(), kc)
434-
controller := factory.Create(plugin, false, o.EnableIngress)
434+
controller := factory.Create(plugin, false)
435435
controller.Run()
436436

437437
proc.StartReaper()

pkg/cmd/openshift-controller-manager/controller/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ type OpenshiftControllerConfig struct {
6363

6464
ServiceServingCertsControllerOptions ServiceServingCertsControllerOptions
6565

66-
SDNControllerConfig SDNControllerConfig
67-
UnidlingControllerConfig UnidlingControllerConfig
68-
IngressIPControllerConfig IngressIPControllerConfig
66+
SDNControllerConfig SDNControllerConfig
67+
UnidlingControllerConfig UnidlingControllerConfig
68+
IngressIPControllerConfig IngressIPControllerConfig
69+
IngressToRouteControllerConfig IngressToRouteControllerConfig
6970

7071
ClusterQuotaReconciliationControllerConfig ClusterQuotaReconciliationControllerConfig
7172

@@ -98,6 +99,7 @@ func (c *OpenshiftControllerConfig) GetControllerInitializers() (map[string]Init
9899
ret["openshift.io/sdn"] = c.SDNControllerConfig.RunController
99100
ret["openshift.io/unidling"] = c.UnidlingControllerConfig.RunController
100101
ret["openshift.io/ingress-ip"] = c.IngressIPControllerConfig.RunController
102+
ret["openshift.io/ingress-to-route"] = c.IngressToRouteControllerConfig.RunController
101103

102104
ret["openshift.io/resourcequota"] = RunResourceQuotaManager
103105
ret["openshift.io/cluster-quota-reconciliation"] = c.ClusterQuotaReconciliationControllerConfig.RunController
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package controller
2+
3+
import (
4+
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
5+
6+
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
7+
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
8+
"github.com/openshift/origin/pkg/route/controller/ingress"
9+
)
10+
11+
type IngressToRouteControllerConfig struct{}
12+
13+
func (c *IngressToRouteControllerConfig) RunController(ctx ControllerContext) (bool, error) {
14+
clientConfig := ctx.ClientBuilder.ConfigOrDie(bootstrappolicy.InfraIngressToRouteControllerServiceAccountName)
15+
coreClient, err := coreclient.NewForConfig(clientConfig)
16+
if err != nil {
17+
return false, err
18+
}
19+
routeClient, err := routeclient.NewForConfig(clientConfig)
20+
if err != nil {
21+
return false, err
22+
}
23+
24+
controller := ingress.NewController(
25+
coreClient,
26+
routeClient,
27+
ctx.ExternalKubeInformers.Extensions().V1beta1().Ingresses(),
28+
ctx.ExternalKubeInformers.Core().V1().Secrets(),
29+
ctx.ExternalKubeInformers.Core().V1().Services(),
30+
ctx.RouteInformers.Route().V1().Routes(),
31+
)
32+
33+
go controller.Run(5, ctx.Stop)
34+
35+
return true, nil
36+
}

pkg/cmd/openshift-controller-manager/controller/interfaces.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
kinternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
1313
"k8s.io/kubernetes/pkg/controller"
1414

15+
routeinformer "github.com/openshift/client-go/route/informers/externalversions"
1516
appinformer "github.com/openshift/origin/pkg/apps/generated/informers/internalversion"
1617
appsclientinternal "github.com/openshift/origin/pkg/apps/generated/internalclientset"
1718
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
@@ -46,6 +47,7 @@ type ControllerContext struct {
4647
TemplateInformers templateinformer.SharedInformerFactory
4748
QuotaInformers quotainformer.SharedInformerFactory
4849
AuthorizationInformers authorizationinformer.SharedInformerFactory
50+
RouteInformers routeinformer.SharedInformerFactory
4951
SecurityInformers securityinformer.SharedInformerFactory
5052
GenericResourceInformer GenericResourceInformer
5153

pkg/cmd/openshift-controller-manager/controller_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func newControllerContext(
185185
NetworkInformers: informers.GetNetworkInformers(),
186186
QuotaInformers: informers.GetQuotaInformers(),
187187
SecurityInformers: informers.GetSecurityInformers(),
188+
RouteInformers: informers.GetRouteInformers(),
188189
TemplateInformers: informers.GetTemplateInformers(),
189190
GenericResourceInformer: informers.ToGenericInformer(),
190191
Stop: stopCh,

pkg/cmd/server/bootstrappolicy/controller_policy.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
InfraPersistentVolumeRecyclerControllerServiceAccountName = "pv-recycler-controller"
3636
InfraResourceQuotaControllerServiceAccountName = "resourcequota-controller"
3737
InfraDefaultRoleBindingsControllerServiceAccountName = "default-rolebindings-controller"
38+
InfraIngressToRouteControllerServiceAccountName = "ingress-to-route-controller"
3839

3940
// template instance controller watches for TemplateInstance object creation
4041
// and instantiates templates as a result.
@@ -296,6 +297,18 @@ func init() {
296297
},
297298
})
298299

300+
// ingress-to-route-controller
301+
addControllerRole(rbac.ClusterRole{
302+
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraIngressToRouteControllerServiceAccountName},
303+
Rules: []rbac.PolicyRule{
304+
rbac.NewRule("get", "list", "watch").Groups(kapiGroup).Resources("secrets", "services").RuleOrDie(),
305+
rbac.NewRule("get", "list", "watch").Groups(extensionsGroup).Resources("ingress").RuleOrDie(),
306+
rbac.NewRule("get", "list", "watch", "create", "update", "patch", "delete").Groups(routeGroup).Resources("routes").RuleOrDie(),
307+
rbac.NewRule("create", "update").Groups(routeGroup).Resources("routes/custom-host").RuleOrDie(),
308+
eventsRule(),
309+
},
310+
})
311+
299312
// pv-recycler-controller
300313
addControllerRole(rbac.ClusterRole{
301314
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraPersistentVolumeRecyclerControllerServiceAccountName},

pkg/cmd/server/origin/master_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"
2828
rbacauthorizer "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac"
2929

30+
routeinformer "github.com/openshift/client-go/route/informers/externalversions"
3031
userinformer "github.com/openshift/client-go/user/informers/externalversions"
3132
appinformer "github.com/openshift/origin/pkg/apps/generated/informers/internalversion"
3233
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
@@ -96,6 +97,7 @@ type MasterConfig struct {
9697
InternalKubeInformers kinternalinformers.SharedInformerFactory
9798
ClientGoKubeInformers kubeclientgoinformers.SharedInformerFactory
9899
AuthorizationInformers authorizationinformer.SharedInformerFactory
100+
RouteInformers routeinformer.SharedInformerFactory
99101
QuotaInformers quotainformer.SharedInformerFactory
100102
SecurityInformers securityinformer.SharedInformerFactory
101103
}
@@ -112,6 +114,7 @@ type InformerAccess interface {
112114
GetOauthInformers() oauthinformer.SharedInformerFactory
113115
GetQuotaInformers() quotainformer.SharedInformerFactory
114116
GetSecurityInformers() securityinformer.SharedInformerFactory
117+
GetRouteInformers() routeinformer.SharedInformerFactory
115118
GetUserInformers() userinformer.SharedInformerFactory
116119
GetTemplateInformers() templateinformer.SharedInformerFactory
117120
ToGenericInformer() GenericResourceInformer
@@ -226,6 +229,7 @@ func BuildMasterConfig(
226229
AuthorizationInformers: informers.GetAuthorizationInformers(),
227230
QuotaInformers: informers.GetQuotaInformers(),
228231
SecurityInformers: informers.GetSecurityInformers(),
232+
RouteInformers: informers.GetRouteInformers(),
229233
}
230234

231235
for name, hook := range authenticatorPostStartHooks {

0 commit comments

Comments
 (0)