Add argo-ui as an iframe

This change request demonstrates using the iframe capability in octant.

It requires that argo-ui is running and available locally,
which can be accomplished with the commands:
  kubectl create namespace argo
  kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj\
/argo/stable/manifests/install.yaml
  kubectl -n argo port-forward deployment/argo-ui 8001:8001

A check is made for the presence of the argo-ui deployments and will
only attempt to show the iframe if it is present.

Change-Id: I1a26e788366d0adb770368083c4f1996311bcd33
This commit is contained in:
Gary Smith 2019-11-26 02:29:44 +00:00
parent ede25ee6e3
commit 01350d74b0
4 changed files with 42 additions and 10 deletions

View File

@ -21,10 +21,6 @@ endif
DIRS = internal pkg
RECURSIVE_DIRS = $(addsuffix /...,$(DIRS))
#.PHONY: install-plugin
#install-plugin:
# mkdir -p $(OCTANT_PLUGINSTUB_DIR)
# go build -o $(OCTANT_PLUGINSTUB_DIR)/airship-ui-plugin $(GO_FLAGS) opendev.org/airship/airshipui/cmd/airshipui
.PHONY: install-plugins
install-plugins: $(PLUGINS)

3
go.mod
View File

@ -5,6 +5,7 @@ go 1.12
require (
github.com/hashicorp/go-plugin v0.0.0-20190220160451-3f118e8ee104
github.com/pkg/errors v0.8.1
github.com/vmware-tanzu/octant v0.9.1
github.com/vmware-tanzu/octant v0.9.2-0.20191125001025-78689a9c6779
k8s.io/api v0.0.0-20191016225839-816a9b7df678
k8s.io/apimachinery v0.0.0-20191016225534-b1267f8c42b4
)

2
go.sum
View File

@ -278,6 +278,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/vmware-tanzu/octant v0.9.1 h1:LuGhTKpRuoffCLZyY2lu5BvRY4Jwjnfz0cx97tfO168=
github.com/vmware-tanzu/octant v0.9.1/go.mod h1:muLHGuQDxXn7yWzAIV5updPjrbtmOkyuAv8LMObed88=
github.com/vmware-tanzu/octant v0.9.2-0.20191125001025-78689a9c6779 h1:V7eCYZw4iFr4KprO87NAsgtk+MEyVPRA6pkZWKzGR7A=
github.com/vmware-tanzu/octant v0.9.2-0.20191125001025-78689a9c6779/go.mod h1:muLHGuQDxXn7yWzAIV5updPjrbtmOkyuAv8LMObed88=
github.com/vmware/octant v0.7.0 h1:i5bXVw9v5tDPOzpYhxwUTJgmn2vXaw/3gv/j+2FsK1c=
github.com/vmware/octant v0.7.0/go.mod h1:yqMiD0isYTmmQLZsS251j7WExsD93K2d3mLHXqewZSI=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=

View File

@ -6,9 +6,15 @@ SPDX-License-Identifier: Apache-2.0
package plugin
import (
"fmt"
// corev1 "k8s.io/api/core/v1"
// "k8s.io/apimachinery/pkg/runtime"
"github.com/vmware-tanzu/octant/pkg/navigation"
"github.com/vmware-tanzu/octant/pkg/plugin"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
"github.com/vmware-tanzu/octant/pkg/store"
"github.com/vmware-tanzu/octant/pkg/view/component"
)
@ -34,18 +40,45 @@ func handleNavigation(request *service.NavigationRequest) (navigation.Navigation
return navigation.Navigation{
Title: "Airship UI",
Path: request.GeneratePath(),
IconName: "cloud",
IconName: "folder",
Children: []navigation.Navigation{
{
Title: "Argo",
Path: request.GeneratePath("argo"),
IconName: "cloud",
},
},
}, nil
}
// initRoutes routes for this plugin. In this example, there is a global catch all route
// that will return the content for every single path.
func initRoutes(router *service.Router) {
router.HandleFunc("*", func(request *service.Request) (component.ContentResponse, error) {
contentResponse := component.NewContentResponse(component.TitleFromString("Airship UI"))
router.HandleFunc("", func(request *service.Request) (component.ContentResponse, error) {
text := component.NewText("This is the Airship UI plugin.")
contentResponse.Add(text)
contentResponse := component.NewContentResponse(component.TitleFromString("Airship UI"))
contentResponse.Add(component.NewText(fmt.Sprintf("This is the Airship UI plugin")))
return *contentResponse, nil
})
router.HandleFunc("/argo", func(request *service.Request) (component.ContentResponse, error) {
contentResponse := component.NewContentResponse(component.TitleFromString("Argo Workflows"))
// Verify that argo-ui is deployed before displaying its iframe. Octant has visibility
// as to whether a port forward has been created, so it is possible that the iframe
// shows an empty frame in that situation
errMsg := "The Argo UI is not available for the currently selected context"
key := store.Key{APIVersion: "apps/v1", Kind: "Deployment", Namespace: "argo", Name: "argo-ui"}
_, found, err := request.DashboardClient().Get(request.Context(), key)
if err != nil || !found {
contentResponse.Add(component.NewText(errMsg))
} else {
frame := component.NewIFrame(
"http://127.0.0.1:8001/workflows",
"Argo Workflows UI")
contentResponse.Add(frame)
}
return *contentResponse, nil
})