Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from dimitraz/INTLY-3122-update-route
Browse files Browse the repository at this point in the history
[INTLY-3122] Update solution explorer route
  • Loading branch information
Dimitra Zuccarelli authored Apr 17, 2020
2 parents ff95b81 + 06a12a6 commit 78d0743
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL=/bin/bash
REG=quay.io
ORG=integreatly
IMAGE=tutorial-web-app-operator
TAG=0.0.47
TAG=v0.0.48
KUBE_CMD=oc apply -f
DEPLOY_DIR=deploy
OUT_STATIC_DIR=tmp/_output
Expand Down
2 changes: 1 addition & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
serviceAccountName: tutorial-web-app-operator
containers:
- name: tutorial-web-app-operator
image: quay.io/integreatly/tutorial-web-app-operator:v0.0.47
image: quay.io/integreatly/tutorial-web-app-operator:v0.0.48
ports:
- containerPort: 60000
name: metrics
Expand Down
12 changes: 0 additions & 12 deletions deploy/template/tutorial-web-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,6 @@ objects:
port: 5001
selector:
app: tutorial-web-app
- apiVersion: v1
kind: Route
metadata:
labels:
app: tutorial-web-app
name: solution-explorer
spec:
tls:
termination: edge
to:
kind: Service
name: tutorial-web-app
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand Down
38 changes: 38 additions & 0 deletions pkg/handlers/webhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package handlers
import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/integr8ly/tutorial-web-app-operator/pkg/apis/integreatly/v1alpha1"

"errors"
"fmt"

"github.com/integr8ly/tutorial-web-app-operator/pkg/apis/integreatly/openshift"
"github.com/integr8ly/tutorial-web-app-operator/pkg/metrics"
routev1 "github.com/openshift/api/route/v1"
v1 "github.com/openshift/api/template/v1"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
Expand All @@ -33,6 +36,8 @@ const (
OpenShiftVersionDefault = "3"
OpenShiftAPIHostDefault = "openshift.default.svc"
WebAppImage = "quay.io/integreatly/tutorial-web-app:2.22.3"
serviceName = "tutorial-web-app"
routeName = "solution-explorer"
)

var webappParams = [...]string{"OPENSHIFT_OAUTHCLIENT_ID", "OPENSHIFT_HOST", "OPENSHIFT_OAUTH_HOST", "SSO_ROUTE", OpenShiftAPIHost, OpenShiftVersion, IntegreatlyVersion, WTLocations, ClusterType, InstalledServices}
Expand Down Expand Up @@ -82,6 +87,11 @@ func (h *AppHandler) Handle(ctx context.Context, event sdk.Event) error {
h.SetStatus(err.Error(), o)
return err
}

// append route onto runtime objs list
route := h.CreateRoute(o)
runtimeObjs = append(runtimeObjs, route)

err = h.ProvisionObjects(runtimeObjs, o)
if err != nil {
logrus.Errorf("Error provisioning the runtime objects: %v", err)
Expand Down Expand Up @@ -219,6 +229,34 @@ func (h *AppHandler) GetRuntimeObjs(exts []runtime.RawExtension) ([]runtime.Obje
return objects, nil
}

func (h *AppHandler) CreateRoute(cr *v1alpha1.WebApp) *routev1.Route {
route := &routev1.Route{
TypeMeta: metav1.TypeMeta{
Kind: "Route",
APIVersion: "route.openshift.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: routeName,
Namespace: cr.Namespace,
Labels: cr.GetLabels(),
},
Spec: routev1.RouteSpec{
TLS: &routev1.TLSConfig{
Termination: routev1.TLSTerminationEdge,
},
To: routev1.RouteTargetReference{
Kind: "Service",
Name: serviceName,
},
},
}
subdomain := cr.Spec.Template.Parameters["ROUTING_SUBDOMAIN"]
if subdomain != "" {
route.Spec.Host = fmt.Sprintf("%s.%s", routeName, subdomain)
}
return route
}

func (h *AppHandler) ProvisionObjects(objects []runtime.Object, cr *v1alpha1.WebApp) error {
for _, o := range objects {
gvk := o.GetObjectKind().GroupVersionKind()
Expand Down

0 comments on commit 78d0743

Please sign in to comment.