From 2c25193adf92e34f33c7085cb6fb9c681b16cb25 Mon Sep 17 00:00:00 2001 From: Andrei Pohilko Date: Tue, 6 Dec 2022 15:31:18 +0000 Subject: [PATCH] Code cosmetics --- main.go | 1 + pkg/dashboard/server.go | 12 ++++++------ pkg/dashboard/static/details-view.js | 6 +++++- pkg/dashboard/subproc/data.go | 12 ++++++++++-- pkg/dashboard/subproc/kubectl.go | 7 +++++++ pkg/dashboard/subproc/repos.go | 1 + scripts/install_plugin.sh | 1 + 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 8904219..f26d483 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ func main() { opts.BindHost = host } + opts.Verbose = opts.Verbose || os.Getenv("DEBUG") != "" setupLogging(opts.Verbose) server := dashboard.Server{ diff --git a/pkg/dashboard/server.go b/pkg/dashboard/server.go index 8319583..5af3bfe 100644 --- a/pkg/dashboard/server.go +++ b/pkg/dashboard/server.go @@ -29,6 +29,11 @@ func (s Server) StartServer() (string, utils.ControlChan) { data := subproc.DataLayer{ Namespace: s.Namespace, Cache: subproc.NewCache(), + StatusInfo: &subproc.StatusInfo{ + CurVer: s.Version, + Analytics: false, + LimitedToNamespace: s.Namespace, + }, } err := data.CheckConnectivity() if err != nil { @@ -36,12 +41,7 @@ func (s Server) StartServer() (string, utils.ControlChan) { os.Exit(1) // TODO: propagate error instead? } isDevModeWithAnalytics := os.Getenv("HD_DEV_ANALYTICS") == "true" - enableAnalytics := (!s.NoTracking && s.Version != "0.0.0") || isDevModeWithAnalytics - data.StatusInfo = &subproc.StatusInfo{ - CurVer: s.Version, - Analytics: enableAnalytics, - LimitedToNamespace: s.Namespace, - } + data.StatusInfo.Analytics = (!s.NoTracking && s.Version != "0.0.0") || isDevModeWithAnalytics go checkUpgrade(data.StatusInfo) discoverScanners(&data) diff --git a/pkg/dashboard/static/details-view.js b/pkg/dashboard/static/details-view.js index 36c3532..677871b 100644 --- a/pkg/dashboard/static/details-view.js +++ b/pkg/dashboard/static/details-view.js @@ -13,7 +13,11 @@ function revisionClicked(namespace, name, self) { $("#sectionDetails .rev-tags .rev-chart").text(elm.chart) $("#sectionDetails .rev-tags .rev-app").text(elm.app_version) $("#sectionDetails .rev-tags .rev-ns").text(getHashParam("namespace")) - $("#sectionDetails .rev-tags .rev-cluster").text(getHashParam("context")) + if (getHashParam("context")) { + $("#sectionDetails .rev-tags .rev-cluster").text(getHashParam("context")) + } else { + $("#sectionDetails .rev-tags .rev-cluster").parent().hide() // TODO: makes UI jumpy, change to showing + } $("#revDescr").text(elm.description).removeClass("text-danger") if (elm.status === "failed") { diff --git a/pkg/dashboard/subproc/data.go b/pkg/dashboard/subproc/data.go index 2d9a74d..f319ea0 100644 --- a/pkg/dashboard/subproc/data.go +++ b/pkg/dashboard/subproc/data.go @@ -35,6 +35,7 @@ type StatusInfo struct { Analytics bool LimitedToNamespace string CacheHitRatio float64 + ClusterMode bool } func (d *DataLayer) runCommand(cmd ...string) (string, error) { @@ -74,10 +75,17 @@ func (d *DataLayer) CheckConnectivity() error { } if len(contexts) < 1 { - return errors.New("did not find any kubectl contexts configured") + log.Debugf("Did not find any contexts, will try checking k8s") + _, err := d.runCommandKubectl("get", "pods") + if err != nil { + log.Debugf("The error were: %s", err) + return errors.New("did not find any kubectl contexts configured") + } + log.Infof("Assuming k8s environment") + d.StatusInfo.ClusterMode = true } - _, err = d.runCommandHelm("--help") // no point in doing is, since the default context may be invalid + _, err = d.runCommandHelm("--help") if err != nil { return err } diff --git a/pkg/dashboard/subproc/kubectl.go b/pkg/dashboard/subproc/kubectl.go index 6773208..ad7aa8f 100644 --- a/pkg/dashboard/subproc/kubectl.go +++ b/pkg/dashboard/subproc/kubectl.go @@ -3,6 +3,7 @@ package subproc import ( "encoding/json" v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" + "os" "regexp" "sort" "strings" @@ -31,6 +32,12 @@ type KubeContext struct { } func (d *DataLayer) ListContexts() (res []KubeContext, err error) { + res = []KubeContext{} + + if os.Getenv("HD_CLUSTER_MODE") != "" { + return res, nil + } + out, err := d.runCommandKubectl("config", "get-contexts") if err != nil { return nil, err diff --git a/pkg/dashboard/subproc/repos.go b/pkg/dashboard/subproc/repos.go index bedc933..b18cbf5 100644 --- a/pkg/dashboard/subproc/repos.go +++ b/pkg/dashboard/subproc/repos.go @@ -12,6 +12,7 @@ import ( func (d *DataLayer) ChartRepoList() (res []RepositoryElement, err error) { out, err := d.Cache.String(CacheKeyAllRepos, nil, func() (string, error) { + // TODO: do a bg check, if the state is changed - do reset some caches return d.runCommandHelm("repo", "list", "--output", "json") }) if err != nil { diff --git a/scripts/install_plugin.sh b/scripts/install_plugin.sh index 90b4115..a13e74f 100755 --- a/scripts/install_plugin.sh +++ b/scripts/install_plugin.sh @@ -11,6 +11,7 @@ if [ -n "${HELM_PUSH_PLUGIN_NO_INSTALL_HOOK}" ]; then fi version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" +# TODO: if no version provided, get it from https://api.github.com/repos/komodorio/helm-dashboard/releases/latest echo "Downloading and installing ${name} v${version} ..." url=""