Skip to content

Commit

Permalink
Add --openshift flag
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-edouard.breteche authored and tekton-robot committed Jul 8, 2020
1 parent a03a369 commit 6af2c85
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 62 deletions.
12 changes: 9 additions & 3 deletions cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
kubeConfigPath = flag.String("kube-config", "", "Path to kube config file")
portNumber = flag.Int("port", 8080, "Dashboard port number")
readOnly = flag.Bool("read-only", false, "Enable or disable read only mode")
isOpenshift = flag.Bool("openshift", false, "Indicates the dashboard is running on openshift")
webDir = flag.String("web-dir", "", "Dashboard web resources dir")
logoutUrl = flag.String("logout-url", "", "If set, enables logout on the frontend and binds the logout button to this url")
csrfSecureCookie = flag.Bool("csrf-secure-cookie", true, "Enable or disable Secure attribute on the CSRF cookie")
Expand Down Expand Up @@ -117,9 +118,13 @@ func main() {
logging.Log.Errorf("Error building k8s clientset: %s", err.Error())
}

routeClient, err := routeclientset.NewForConfig(cfg)
if err != nil {
logging.Log.Errorf("Error building route clientset: %s", err.Error())
var routeClient routeclientset.Interface

if *isOpenshift {
routeClient, err = routeclientset.NewForConfig(cfg)
if err != nil {
logging.Log.Errorf("Error building route clientset: %s", err.Error())
}
}

transport, err := rest.TransportFor(cfg)
Expand All @@ -133,6 +138,7 @@ func main() {
TriggersNamespace: *triggersNamespace,
TenantNamespace: *tenantNamespace,
ReadOnly: *readOnly,
IsOpenShift: *isOpenshift,
WebDir: *webDir,
LogoutURL: *logoutUrl,
}
Expand Down
4 changes: 4 additions & 0 deletions overlays/patches/installer/deployment-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
path: /spec/template/spec/containers/0/args/-
value:
--namespace=--tenant-namespace
- op: add
path: /spec/template/spec/containers/0/args/-
value:
--openshift=--openshift
50 changes: 26 additions & 24 deletions pkg/endpoints/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,43 @@ func (r Resource) GetIngress(request *restful.Request, response *restful.Respons
return
}

// GetIngress returns the Ingress endpoint called "tektonDashboardIngressName" in the requested namespace
// GetEndpoints returns the Ingress or Route for the Dashboard
func (r Resource) GetEndpoints(request *restful.Request, response *restful.Response) {
type element struct {
Type string `json:"type"`
Url string `json:"url"`
}
var responses []element
var err error
requestNamespace := utils.GetNamespace(request)

route, err := r.RouteClient.RouteV1().Routes(requestNamespace).Get(tektonDashboardIngressName, metav1.GetOptions{})
noRuleError := "no Route found labelled " + tektonDashboardRouteName
if err != nil || route == nil {
logging.Log.Infof("Unable to retrieve any routes: %s", err)
} else {
if route.Spec.Host != "" { // For that rule, is there actually a host?
routeHost := route.Spec.Host
responses = append(responses, element{"Route", routeHost})
if r.Options.IsOpenShift {
ingress, err := r.K8sClient.ExtensionsV1beta1().Ingresses(requestNamespace).Get(tektonDashboardIngressName, metav1.GetOptions{})
noRuleError := "no Ingress rules found labelled " + tektonDashboardIngressName
if err != nil || ingress == nil {
logging.Log.Infof("Unable to retrieve any ingresses: %s", err)
} else {
logging.Log.Error(noRuleError)
if len(ingress.Spec.Rules) > 0 { // Got more than zero entries?
if ingress.Spec.Rules[0].Host != "" { // For that rule, is there actually a host?
ingressHost := ingress.Spec.Rules[0].Host
responses = append(responses, element{"Ingress", ingressHost})
}
} else {
logging.Log.Error(noRuleError)
}
}
}

ingress, err := r.K8sClient.ExtensionsV1beta1().Ingresses(requestNamespace).Get(tektonDashboardIngressName, metav1.GetOptions{})
noRuleError = "no Ingress rules found labelled " + tektonDashboardIngressName
if err != nil || ingress == nil {
logging.Log.Infof("Unable to retrieve any ingresses: %s", err)
} else {
if len(ingress.Spec.Rules) > 0 { // Got more than zero entries?
if ingress.Spec.Rules[0].Host != "" { // For that rule, is there actually a host?
ingressHost := ingress.Spec.Rules[0].Host
responses = append(responses, element{"Ingress", ingressHost})
}
route, err := r.RouteClient.RouteV1().Routes(requestNamespace).Get(tektonDashboardIngressName, metav1.GetOptions{})
noRuleError := "no Route found labelled " + tektonDashboardRouteName
if err != nil || route == nil {
logging.Log.Infof("Unable to retrieve any routes: %s", err)
} else {
logging.Log.Error(noRuleError)
if route.Spec.Host != "" { // For that rule, is there actually a host?
routeHost := route.Spec.Host
responses = append(responses, element{"Route", routeHost})
} else {
logging.Log.Error(noRuleError)
}
}
}

Expand All @@ -191,15 +194,14 @@ func (r Resource) GetProperties(request *restful.Request, response *restful.Resp
pipelineNamespace := r.Options.GetPipelinesNamespace()
triggersNamespace := r.Options.GetTriggersNamespace()
dashboardVersion := getDashboardVersion(r, r.Options.InstallNamespace)
isOpenShift := isOpenShift(r, r.Options.InstallNamespace)
pipelineVersion := getPipelineVersion(r, pipelineNamespace)

properties := Properties{
DashboardNamespace: r.Options.InstallNamespace,
DashboardVersion: dashboardVersion,
PipelineNamespace: pipelineNamespace,
PipelineVersion: pipelineVersion,
IsOpenShift: isOpenShift,
IsOpenShift: r.Options.IsOpenShift,
ReadOnly: r.Options.ReadOnly,
LogoutURL: r.Options.LogoutURL,
TenantNamespace: r.Options.TenantNamespace,
Expand Down
35 changes: 0 additions & 35 deletions pkg/endpoints/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/tektoncd/dashboard/pkg/logging"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Get dashboard version
Expand Down Expand Up @@ -53,40 +52,6 @@ func getDashboardVersion(r Resource, installedNamespace string) string {
return version
}

// isOpenShift determines whether the Dashboard is running on OpenShift or not
func isOpenShift(r Resource, namespace string) bool {
openshiftPipelineFound := false
tektonPipelinesFound := false
routeFound := false

found := searchForDeployment(r, "pipelines", namespace)

if found {
if namespace == "openshift-pipelines" {
openshiftPipelineFound = true
} else {
tektonPipelinesFound = true
}
}

routes, err := r.RouteClient.RouteV1().Routes(namespace).List(v1.ListOptions{})
if err != nil {
logging.Log.Errorf("Error getting the list of routes: %s", err.Error())
}

for _, route := range routes.Items {
routeA := route.GetName()
if routeA == "tekton-dashboard" {
routeFound = true
}
}

if (openshiftPipelineFound == true || tektonPipelinesFound == true) && routeFound == true {
return true
}
return false
}

// Get pipelines version
func getPipelineVersion(r Resource, namespace string) string {
version := getDeployments(r, "pipelines", namespace)
Expand Down
1 change: 1 addition & 0 deletions pkg/endpoints/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Options struct {
TriggersNamespace string
TenantNamespace string
ReadOnly bool
IsOpenShift bool
WebDir string
LogoutURL string
}
Expand Down
1 change: 1 addition & 0 deletions scripts/installer
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ patch() {
replace "--logout-url=--logout-url" "--logout-url=$LOGOUT_URL"
replace "--read-only=--read-only" "--read-only=$READONLY"
replace "--namespace=--tenant-namespace" "--namespace=$TENANT_NAMESPACE"
replace "--openshift=--openshift" "--openshift=$OPENSHIFT"
replace "namespace: tekton-dashboard" "namespace: $INSTALL_NAMESPACE"

if [ "$OPENSHIFT" == "true" ] && [ "$IMAGE_STREAM" == "true" ]; then
Expand Down

0 comments on commit 6af2c85

Please sign in to comment.