Skip to content

Commit

Permalink
Allow to configure domain to create routes (#666)
Browse files Browse the repository at this point in the history
* Allow to configure domain to create routes

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Feb 15, 2021
1 parent 562246c commit 2f5ec20
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 72 deletions.
24 changes: 24 additions & 0 deletions deploy/crds/org_v1_che_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ spec:
identityProviderRoute:
description: Route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -475,6 +481,12 @@ spec:
cheServerRoute:
description: The Che server route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -532,6 +544,12 @@ spec:
devfileRegistryRoute:
description: The devfile registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -612,6 +630,12 @@ spec:
pluginRegistryRoute:
description: Plugin registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ spec:
identityProviderRoute:
description: Route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -475,6 +481,12 @@ spec:
cheServerRoute:
description: The Che server route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -532,6 +544,12 @@ spec:
devfileRegistryRoute:
description: The devfile registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -612,6 +630,12 @@ spec:
pluginRegistryRoute:
description: Plugin registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ spec:
identityProviderRoute:
description: Route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -476,6 +482,12 @@ spec:
cheServerRoute:
description: The Che server route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -533,6 +545,12 @@ spec:
devfileRegistryRoute:
description: The devfile registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down Expand Up @@ -613,6 +631,12 @@ spec:
pluginRegistryRoute:
description: Plugin registry route custom settings.
properties:
domain:
description: 'Operator uses the domain to generate a hostname
for a route. In a conjunction with labels it creates a route,
which is served by a non-default Ingress controller. The generated
host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.'
type: string
labels:
description: Comma separated list of labels that can be used
to organize and categorize objects by scoping and selecting.
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/org/v1/che_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ type RouteCustomSettings struct {
// Comma separated list of labels that can be used to organize and categorize objects by scoping and selecting.
// +optional
Labels string `json:"labels,omitempty"`
// Operator uses the domain to generate a hostname for a route.
// In a conjunction with labels it creates a route, which is served by a non-default Ingress controller.
// The generated host name will follow this pattern: `<route-name>-<route-namespace>.<domain>`.
// +optional
Domain string `json:"domain,omitempty"`
}

// ResourceRequirements describes the compute resource requirements.
Expand Down
29 changes: 20 additions & 9 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
instance.Spec.Auth.OpenShiftoAuth = nil
instance.Spec.Auth.InitialOpenShiftOAuthUser = nil
updateFields := map[string]string{
"openShiftoAuth": "nil",
"openShiftoAuth": "nil",
"initialOpenShiftOAuthUser": "nil",
}

if err := r.UpdateCheCRSpecByFields(instance, updateFields); err != nil {
return reconcile.Result{}, err
}
Expand All @@ -406,7 +406,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

if instance.Spec.Auth.InitialOpenShiftOAuthUser == nil && instance.Status.OpenShiftOAuthUserCredentialsSecret != "" {
secret, err := deploy.GetSecret(openShiftOAuthUserCredentialsSecret, instance.Namespace, deployContext.ClusterAPI)
secret, err := deploy.GetSecret(deployContext, openShiftOAuthUserCredentialsSecret, instance.Namespace)
if secret == nil {
if err == nil {
instance.Status.OpenShiftOAuthUserCredentialsSecret = ""
Expand Down Expand Up @@ -822,14 +822,13 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
exposedServiceName := getServerExposingServiceName(instance)
cheHost := ""
if !isOpenShift {
additionalLabels := deployContext.CheCluster.Spec.Server.CheServerIngress.Labels
ingress, err := deploy.SyncIngressToCluster(
deployContext,
cheFlavor,
instance.Spec.Server.CheHost,
exposedServiceName,
8080,
additionalLabels,
deployContext.CheCluster.Spec.Server.CheServerIngress,
cheFlavor)
if !tests {
if ingress == nil {
Expand All @@ -849,8 +848,14 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
customHost = ""
}

additionalLabels := deployContext.CheCluster.Spec.Server.CheServerRoute.Labels
route, err := deploy.SyncRouteToCluster(deployContext, cheFlavor, customHost, exposedServiceName, 8080, additionalLabels, cheFlavor)
route, err := deploy.SyncRouteToCluster(
deployContext,
cheFlavor,
customHost,
exposedServiceName,
8080,
deployContext.CheCluster.Spec.Server.CheServerRoute,
cheFlavor)
if route == nil {
logrus.Infof("Waiting on route '%s' to be ready", cheFlavor)
if err != nil {
Expand Down Expand Up @@ -1087,8 +1092,14 @@ func EvaluateCheServerVersion(cr *orgv1.CheCluster) string {

func getDefaultCheHost(deployContext *deploy.DeployContext) (string, error) {
cheFlavor := deploy.DefaultCheFlavor(deployContext.CheCluster)
additionalLabels := deployContext.CheCluster.Spec.Server.CheServerRoute.Labels
route, err := deploy.SyncRouteToCluster(deployContext, cheFlavor, "", getServerExposingServiceName(deployContext.CheCluster), 8080, additionalLabels, cheFlavor)
route, err := deploy.SyncRouteToCluster(
deployContext,
cheFlavor,
"",
getServerExposingServiceName(deployContext.CheCluster),
8080,
deployContext.CheCluster.Spec.Server.CheServerRoute,
cheFlavor)
if route == nil {
logrus.Infof("Waiting on route '%s' to be ready", cheFlavor)
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions pkg/controller/che/che_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {
}

// Set up che host for route
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, "", "che")
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, orgv1.RouteCustomSettings{}, "che")
r.client.Create(context.TODO(), cheRoute)
// Set up keycloak host for route
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, "", deploy.IdentityProviderName)
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, orgv1.RouteCustomSettings{}, deploy.IdentityProviderName)
r.client.Create(context.TODO(), keycloakRoute)

_, err := r.Reconcile(req)
Expand Down Expand Up @@ -1308,16 +1308,16 @@ func TestShouldSetUpCorrectlyInternalPluginRegistryServiceURL(t *testing.T) {
}

// Set up che host for route
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, "", "che")
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, orgv1.RouteCustomSettings{}, "che")
r.client.Create(context.TODO(), cheRoute)
// Set up keycloak host for route
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, "", deploy.IdentityProviderName)
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, orgv1.RouteCustomSettings{}, deploy.IdentityProviderName)
r.client.Create(context.TODO(), keycloakRoute)
// Set up plugin registry host for route
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, "", deploy.PluginRegistryName)
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.PluginRegistryName)
r.client.Create(context.TODO(), pluginRegistryRoute)
// Set up devfile registry host for route
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, "", deploy.DevfileRegistryName)
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.DevfileRegistryName)
r.client.Create(context.TODO(), devfileRegistryRoute)

_, err := r.Reconcile(req)
Expand Down Expand Up @@ -1494,16 +1494,16 @@ func TestShouldSetUpCorrectlyInternalDevfileRegistryServiceURL(t *testing.T) {
}

// Set up che host for route
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, "", "che")
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, orgv1.RouteCustomSettings{}, "che")
r.client.Create(context.TODO(), cheRoute)
// Set up keycloak host for route
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, "", deploy.IdentityProviderName)
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, orgv1.RouteCustomSettings{}, deploy.IdentityProviderName)
r.client.Create(context.TODO(), keycloakRoute)
// Set up plugin registry host for route
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, "", deploy.PluginRegistryName)
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.PluginRegistryName)
r.client.Create(context.TODO(), pluginRegistryRoute)
// Set up devfile registry host for route
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, "", deploy.DevfileRegistryName)
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.DevfileRegistryName)
r.client.Create(context.TODO(), devfileRegistryRoute)

_, err := r.Reconcile(req)
Expand Down Expand Up @@ -1629,16 +1629,16 @@ func TestShouldSetUpCorrectlyInternalCheServerURL(t *testing.T) {
}

// Set up che host for route
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, "", "che")
cheRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DefaultCheFlavor(testCase.cheCR), "che-host", "che-host", 8080, orgv1.RouteCustomSettings{}, "che")
r.client.Create(context.TODO(), cheRoute)
// Set up keycloak host for route
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, "", deploy.IdentityProviderName)
keycloakRoute, _ := deploy.GetSpecRoute(deployContext, deploy.IdentityProviderName, "keycloak", deploy.IdentityProviderName, 8080, orgv1.RouteCustomSettings{}, deploy.IdentityProviderName)
r.client.Create(context.TODO(), keycloakRoute)
// Set up plugin registry host for route
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, "", deploy.PluginRegistryName)
pluginRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.PluginRegistryName, "plugin-registry", deploy.PluginRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.PluginRegistryName)
r.client.Create(context.TODO(), pluginRegistryRoute)
// Set up devfile registry host for route
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, "", deploy.DevfileRegistryName)
devfileRegistryRoute, _ := deploy.GetSpecRoute(deployContext, deploy.DevfileRegistryName, "devfile-registry", deploy.DevfileRegistryName, 8080, orgv1.RouteCustomSettings{}, deploy.DevfileRegistryName)
r.client.Create(context.TODO(), devfileRegistryRoute)

_, err := r.Reconcile(req)
Expand Down
Loading

0 comments on commit 2f5ec20

Please sign in to comment.