Skip to content

Commit 10a0cc2

Browse files
Merge pull request #966 from openshift-cherrypick-robot/cherry-pick-965-to-release-4.18
[release-4.18] OCPBUGS-52294: Custom route TLS should be optional when IngressController's DefaultCertificate is set
2 parents 49cd98b + 80c333d commit 10a0cc2

File tree

6 files changed

+211
-46
lines changed

6 files changed

+211
-46
lines changed

manifests/03-rbac-role-cluster.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ rules:
9898
- update
9999
- delete
100100
- patch
101+
- apiGroups:
102+
- operator.openshift.io
103+
resources:
104+
- ingresscontrollers
105+
verbs:
106+
- get
107+
- list
108+
- watch
101109
- apiGroups:
102110
- console.openshift.io
103111
resources:

pkg/api/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ const (
4848
V1Alpha1PluginI18nAnnotation = "console.openshift.io/use-i18n"
4949
VersionResourceName = "version"
5050

51+
// ingress instance named "default" is the OOTB ingresscontroller
52+
// this is an implicit stable API
53+
DefaultIngressController = "default"
54+
IngressControllerNamespace = "openshift-ingress-operator"
55+
5156
OAuthClientName = OpenShiftConsoleName
5257
OpenShiftConsoleDeploymentName = OpenShiftConsoleName
5358
OpenShiftConsoleDownloadsDeploymentName = DownloadsResourceName

pkg/console/controllers/route/controller.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ type RouteSyncController struct {
4040
routeName string
4141
isHealthCheckEnabled bool
4242
// clients
43-
operatorClient v1helpers.OperatorClient
44-
routeClient routeclientv1.RoutesGetter
45-
operatorConfigLister operatorv1listers.ConsoleLister
46-
ingressConfigLister configlistersv1.IngressLister
47-
secretLister corev1listers.SecretLister
48-
infrastructureConfigLister configlistersv1.InfrastructureLister
49-
clusterVersionLister configlistersv1.ClusterVersionLister
43+
operatorClient v1helpers.OperatorClient
44+
routeClient routeclientv1.RoutesGetter
45+
operatorConfigLister operatorv1listers.ConsoleLister
46+
ingressConfigLister configlistersv1.IngressLister
47+
ingressControllerLister operatorv1listers.IngressControllerLister
48+
secretLister corev1listers.SecretLister
49+
ingressControllerSecretLister corev1listers.SecretLister
50+
infrastructureConfigLister configlistersv1.InfrastructureLister
51+
clusterVersionLister configlistersv1.ClusterVersionLister
5052
}
5153

5254
func NewRouteSyncController(
@@ -59,6 +61,7 @@ func NewRouteSyncController(
5961
routev1Client routeclientv1.RoutesGetter,
6062
// informers
6163
operatorConfigInformer v1.ConsoleInformer,
64+
ingressControllerInformer v1.IngressControllerInformer,
6265
secretInformer coreinformersv1.SecretInformer,
6366
routeInformer routesinformersv1.RouteInformer,
6467
// events
@@ -70,6 +73,7 @@ func NewRouteSyncController(
7073
operatorClient: operatorClient,
7174
operatorConfigLister: operatorConfigInformer.Lister(),
7275
ingressConfigLister: configInformer.Config().V1().Ingresses().Lister(),
76+
ingressControllerLister: ingressControllerInformer.Lister(),
7377
routeClient: routev1Client,
7478
secretLister: secretInformer.Lister(),
7579
infrastructureConfigLister: configInformer.Config().V1().Infrastructures().Lister(),
@@ -86,6 +90,9 @@ func NewRouteSyncController(
8690
configV1Informers.Ingresses().Informer(),
8791
).WithInformers(
8892
secretInformer.Informer(),
93+
).WithFilteredEventsInformers(
94+
util.IncludeNamesFilter(api.DefaultIngressController),
95+
ingressControllerInformer.Informer(),
8996
).WithFilteredEventsInformers( // route
9097
util.IncludeNamesFilter(routeName, routesub.GetCustomRouteName(routeName)),
9198
routeInformer.Informer(),
@@ -135,6 +142,11 @@ func (c *RouteSyncController) Sync(ctx context.Context, controllerContext factor
135142
return statusHandler.FlushAndReturn(err)
136143
}
137144

145+
ingressControllerConfig, err := c.ingressControllerLister.IngressControllers(api.IngressControllerNamespace).Get(api.DefaultIngressController)
146+
if err != nil {
147+
return statusHandler.FlushAndReturn(err)
148+
}
149+
138150
clusterVersionConfig, err := c.clusterVersionLister.Get("version")
139151
if err != nil {
140152
return statusHandler.FlushAndReturn(err)
@@ -157,7 +169,7 @@ func (c *RouteSyncController) Sync(ctx context.Context, controllerContext factor
157169
// try to sync the custom route first. If the sync fails for any reason, error
158170
// out the sync loop and inform about this fact instead of putting default
159171
// route into inaccessible state.
160-
_, customRouteErrReason, customRouteErr := c.SyncCustomRoute(ctx, routeConfig, controllerContext)
172+
_, customRouteErrReason, customRouteErr := c.SyncCustomRoute(ctx, routeConfig, ingressControllerConfig, controllerContext)
161173
statusHandler.AddConditions(status.HandleProgressingOrDegraded(typePrefix, customRouteErrReason, customRouteErr))
162174
statusHandler.AddCondition(status.HandleUpgradable(typePrefix, customRouteErrReason, customRouteErr))
163175
if customRouteErr != nil {
@@ -214,7 +226,7 @@ func (c *RouteSyncController) SyncDefaultRoute(ctx context.Context, routeConfig
214226
// 2. if secret is defined, verify the TLS certificate and key
215227
// 4. create the custom console route, if custom TLS certificate and key are defined use them
216228
// 5. apply the custom route
217-
func (c *RouteSyncController) SyncCustomRoute(ctx context.Context, routeConfig *routesub.RouteConfig, controllerContext factory.SyncContext) (*routev1.Route, string, error) {
229+
func (c *RouteSyncController) SyncCustomRoute(ctx context.Context, routeConfig *routesub.RouteConfig, ingressControllerConfig *operatorsv1.IngressController, controllerContext factory.SyncContext) (*routev1.Route, string, error) {
218230
if !routeConfig.IsCustomHostnameSet() {
219231
if err := c.removeRoute(ctx, routesub.GetCustomRouteName(c.routeName)); err != nil {
220232
return nil, "FailedDeleteCustomRoutes", err
@@ -228,7 +240,7 @@ func (c *RouteSyncController) SyncCustomRoute(ctx context.Context, routeConfig *
228240
return nil, "", nil
229241
}
230242

231-
if configErr := c.ValidateCustomRouteConfig(ctx, routeConfig); configErr != nil {
243+
if configErr := c.ValidateCustomRouteConfig(ctx, routeConfig, ingressControllerConfig); configErr != nil {
232244
return nil, "InvalidCustomRouteConfig", configErr
233245
}
234246

@@ -284,7 +296,13 @@ func (c *RouteSyncController) GetDefaultRouteTLSSecret(ctx context.Context, rout
284296
return secret, nil
285297
}
286298

287-
func (c *RouteSyncController) ValidateCustomRouteConfig(ctx context.Context, routeConfig *routesub.RouteConfig) error {
299+
func (c *RouteSyncController) ValidateCustomRouteConfig(ctx context.Context, routeConfig *routesub.RouteConfig, ingressControllerConfig *operatorsv1.IngressController) error {
300+
// Check if the default cetrificate is set in the ingress controller config.
301+
// If it is, then the custom route TLS secret is optional.
302+
if ingressControllerConfig.Spec.DefaultCertificate != nil {
303+
return nil
304+
}
305+
288306
// Check if the custom hostname has cluster domain suffix, which indicates
289307
// if a secret that contains TLS certificate and key needs to exist in the
290308
// `openshift-config` namespace and referenced in the operator config.

pkg/console/starter/starter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
// openshift
2424
configv1 "github.com/openshift/api/config/v1"
2525
"github.com/openshift/api/oauth"
26-
operator "github.com/openshift/api/operator"
2726
operatorv1 "github.com/openshift/api/operator/v1"
2827
"github.com/openshift/console-operator/pkg/api"
2928
"github.com/openshift/console-operator/pkg/console/clientwrapper"
@@ -379,6 +378,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
379378
routesClient.RouteV1(),
380379
// route
381380
operatorConfigInformers.Operator().V1().Consoles(),
381+
operatorConfigInformers.Operator().V1().IngressControllers(),
382382
kubeInformersConfigNamespaced.Core().V1().Secrets(), // `openshift-config` namespace informers
383383
routesInformersNamespaced.Route().V1().Routes(),
384384
// events
@@ -396,6 +396,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
396396
routesClient.RouteV1(),
397397
// route
398398
operatorConfigInformers.Operator().V1().Consoles(),
399+
operatorConfigInformers.Operator().V1().IngressControllers(),
399400
kubeInformersConfigNamespaced.Core().V1().Secrets(), // `openshift-config` namespace informers
400401
routesInformersNamespaced.Route().V1().Routes(),
401402
// events
@@ -433,7 +434,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
433434
clusterOperatorStatus := status.NewClusterOperatorStatusController(
434435
api.ClusterOperatorName,
435436
[]configv1.ObjectReference{
436-
{Group: operator.GroupName, Resource: "consoles", Name: api.ConfigResourceName},
437+
{Group: operatorv1.GroupName, Resource: "consoles", Name: api.ConfigResourceName},
437438
{Group: configv1.GroupName, Resource: "consoles", Name: api.ConfigResourceName},
438439
{Group: configv1.GroupName, Resource: "infrastructures", Name: api.ConfigResourceName},
439440
{Group: configv1.GroupName, Resource: "proxies", Name: api.ConfigResourceName},

pkg/console/subresource/route/route.go

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ import (
2828
"github.com/openshift/console-operator/pkg/api"
2929
)
3030

31-
const (
32-
// ingress instance named "default" is the OOTB ingresscontroller
33-
// this is an implicit stable API
34-
defaultIngressController = "default"
35-
)
36-
3731
// holds information about custom TLS certificate and its key
3832
type CustomTLSCert struct {
3933
Certificate string
@@ -48,8 +42,8 @@ type RouteConfig struct {
4842
}
4943

5044
type RouteControllerSpec struct {
51-
hostname string
52-
secretName string
45+
Hostname string
46+
SecretName string
5347
}
5448

5549
func getComponentRouteSpec(ingressConfig *configv1.Ingress, componentName string) *configv1.ComponentRouteSpec {
@@ -72,17 +66,17 @@ func getComponentRouteStatus(ingressConfig *configv1.Ingress, componentName stri
7266

7367
func NewRouteConfig(operatorConfig *operatorv1.Console, ingressConfig *configv1.Ingress, routeName string) *RouteConfig {
7468
defaultRoute := RouteControllerSpec{
75-
hostname: GetDefaultRouteHost(routeName, ingressConfig),
69+
Hostname: GetDefaultRouteHost(routeName, ingressConfig),
7670
}
7771
var customRoute RouteControllerSpec
7872
var isIngressConfigCustomHostnameSet bool
7973

80-
// Custom hostname in ingress config takes precedent over console operator's config
74+
// Custom Hostname in ingress config takes precedent over console operator's config
8175
componentRouteSpec := getComponentRouteSpec(ingressConfig, routeName)
8276
if componentRouteSpec != nil {
83-
customRoute.hostname = string(componentRouteSpec.Hostname)
77+
customRoute.Hostname = string(componentRouteSpec.Hostname)
8478
if componentRouteSpec.ServingCertKeyPairSecret.Name != "" {
85-
customRoute.secretName = componentRouteSpec.ServingCertKeyPairSecret.Name
79+
customRoute.SecretName = componentRouteSpec.ServingCertKeyPairSecret.Name
8680
}
8781
isIngressConfigCustomHostnameSet = true
8882
}
@@ -92,67 +86,79 @@ func NewRouteConfig(operatorConfig *operatorv1.Console, ingressConfig *configv1.
9286
// TLS for the default route.
9387
if !isIngressConfigCustomHostnameSet && routeName == api.OpenShiftConsoleRouteName {
9488
if len(operatorConfig.Spec.Route.Secret.Name) != 0 {
95-
customRoute.secretName = operatorConfig.Spec.Route.Secret.Name
89+
customRoute.SecretName = operatorConfig.Spec.Route.Secret.Name
9690
}
97-
customRoute.hostname = operatorConfig.Spec.Route.Hostname
91+
customRoute.Hostname = operatorConfig.Spec.Route.Hostname
9892
}
9993

100-
// if hostname for custom route is the same as the hostname for the default route
101-
// OR if the custom route hostname is not set:
94+
// if Hostname for custom route is the same as the Hostname for the default route
95+
// OR if the custom route Hostname is not set:
10296
// - if the custom route TLS secret is set and set it for the default route
103-
// - unset hostname and TLS secret for the custom route
104-
if defaultRoute.hostname == customRoute.hostname || len(customRoute.hostname) == 0 {
105-
if len(customRoute.secretName) != 0 {
106-
defaultRoute.secretName = customRoute.secretName
97+
// - unset Hostname and TLS secret for the custom route
98+
if defaultRoute.Hostname == customRoute.Hostname || len(customRoute.Hostname) == 0 {
99+
if len(customRoute.SecretName) != 0 {
100+
defaultRoute.SecretName = customRoute.SecretName
107101
}
108-
customRoute.hostname = ""
109-
customRoute.secretName = ""
102+
customRoute.Hostname = ""
103+
customRoute.SecretName = ""
110104
}
111105

112-
customHostnameSpec := &RouteConfig{
106+
routeConfig := &RouteConfig{
113107
defaultRoute: defaultRoute,
114108
customRoute: customRoute,
115109
domain: ingressConfig.Spec.Domain,
116110
routeName: routeName,
117111
}
118112

119-
return customHostnameSpec
113+
return routeConfig
114+
}
115+
116+
func (rc *RouteConfig) GetRouteName() string {
117+
return rc.routeName
118+
}
119+
120+
func (rc *RouteConfig) GetDefaultRoute() RouteControllerSpec {
121+
return rc.defaultRoute
122+
}
123+
124+
func (rc *RouteConfig) GetCustomRoute() RouteControllerSpec {
125+
return rc.customRoute
120126
}
121127

122128
func (rc *RouteConfig) HostnameMatch() bool {
123-
return rc.customRoute.hostname == rc.defaultRoute.hostname
129+
return rc.customRoute.Hostname == rc.defaultRoute.Hostname
124130
}
125131

126132
func (rc *RouteConfig) IsCustomHostnameSet() bool {
127-
return len(rc.customRoute.hostname) != 0
133+
return len(rc.customRoute.Hostname) != 0
128134
}
129135

130136
func (rc *RouteConfig) GetCustomRouteHostname() string {
131-
return rc.customRoute.hostname
137+
return rc.customRoute.Hostname
132138
}
133139

134140
func (rc *RouteConfig) IsCustomTLSSecretSet() bool {
135-
return len(rc.customRoute.secretName) != 0
141+
return len(rc.customRoute.SecretName) != 0
136142
}
137143

138144
func (rc *RouteConfig) IsDefaultTLSSecretSet() bool {
139-
return len(rc.defaultRoute.secretName) != 0
145+
return len(rc.defaultRoute.SecretName) != 0
140146
}
141147

142148
func (rc *RouteConfig) GetCustomTLSSecretName() string {
143-
return rc.customRoute.secretName
149+
return rc.customRoute.SecretName
144150
}
145151

146152
func (rc *RouteConfig) GetDefaultTLSSecretName() string {
147-
return rc.defaultRoute.secretName
153+
return rc.defaultRoute.SecretName
148154
}
149155

150156
func (rc *RouteConfig) GetDomain() string {
151157
return rc.domain
152158
}
153159

154160
// Default `console` route points by default to the `console` service.
155-
// If custom hostname for the console is set, then the default route
161+
// If custom Hostname for the console is set, then the default route
156162
// should point to the redirect `console-redirect` service and the
157163
// created custom route should be pointing to the `console` service.
158164
func (rc *RouteConfig) DefaultRoute(tlsConfig *CustomTLSCert, ingressConfig *configv1.Ingress) *routev1.Route {
@@ -169,11 +175,16 @@ func (rc *RouteConfig) DefaultRoute(tlsConfig *CustomTLSCert, ingressConfig *con
169175

170176
func (rc *RouteConfig) CustomRoute(tlsConfig *CustomTLSCert, routeName string) *routev1.Route {
171177
route := resourceread.ReadRouteV1OrDie(bindata.MustAsset(fmt.Sprintf("assets/routes/%s-custom-route.yaml", rc.routeName)))
172-
route.Spec.Host = rc.customRoute.hostname
178+
route.Spec.Host = rc.customRoute.Hostname
173179
setTLS(tlsConfig, route)
174180
return route
175181
}
176182

183+
func (rc *RouteConfig) UnsetTLS() {
184+
rc.defaultRoute.SecretName = ""
185+
rc.customRoute.SecretName = ""
186+
}
187+
177188
func GetDefaultRouteHost(routeName string, ingressConfig *configv1.Ingress) string {
178189
return fmt.Sprintf("%s-%s.%s", routeName, api.OpenShiftConsoleNamespace, ingressConfig.Spec.Domain)
179190
}

0 commit comments

Comments
 (0)