Code cosmetics

This commit is contained in:
Andrei Pohilko
2022-12-06 15:31:18 +00:00
parent 2c1883c835
commit 2c25193adf
7 changed files with 31 additions and 9 deletions

View File

@@ -37,6 +37,7 @@ func main() {
opts.BindHost = host opts.BindHost = host
} }
opts.Verbose = opts.Verbose || os.Getenv("DEBUG") != ""
setupLogging(opts.Verbose) setupLogging(opts.Verbose)
server := dashboard.Server{ server := dashboard.Server{

View File

@@ -29,6 +29,11 @@ func (s Server) StartServer() (string, utils.ControlChan) {
data := subproc.DataLayer{ data := subproc.DataLayer{
Namespace: s.Namespace, Namespace: s.Namespace,
Cache: subproc.NewCache(), Cache: subproc.NewCache(),
StatusInfo: &subproc.StatusInfo{
CurVer: s.Version,
Analytics: false,
LimitedToNamespace: s.Namespace,
},
} }
err := data.CheckConnectivity() err := data.CheckConnectivity()
if err != nil { if err != nil {
@@ -36,12 +41,7 @@ func (s Server) StartServer() (string, utils.ControlChan) {
os.Exit(1) // TODO: propagate error instead? os.Exit(1) // TODO: propagate error instead?
} }
isDevModeWithAnalytics := os.Getenv("HD_DEV_ANALYTICS") == "true" isDevModeWithAnalytics := os.Getenv("HD_DEV_ANALYTICS") == "true"
enableAnalytics := (!s.NoTracking && s.Version != "0.0.0") || isDevModeWithAnalytics data.StatusInfo.Analytics = (!s.NoTracking && s.Version != "0.0.0") || isDevModeWithAnalytics
data.StatusInfo = &subproc.StatusInfo{
CurVer: s.Version,
Analytics: enableAnalytics,
LimitedToNamespace: s.Namespace,
}
go checkUpgrade(data.StatusInfo) go checkUpgrade(data.StatusInfo)
discoverScanners(&data) discoverScanners(&data)

View File

@@ -13,7 +13,11 @@ function revisionClicked(namespace, name, self) {
$("#sectionDetails .rev-tags .rev-chart").text(elm.chart) $("#sectionDetails .rev-tags .rev-chart").text(elm.chart)
$("#sectionDetails .rev-tags .rev-app").text(elm.app_version) $("#sectionDetails .rev-tags .rev-app").text(elm.app_version)
$("#sectionDetails .rev-tags .rev-ns").text(getHashParam("namespace")) $("#sectionDetails .rev-tags .rev-ns").text(getHashParam("namespace"))
if (getHashParam("context")) {
$("#sectionDetails .rev-tags .rev-cluster").text(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") $("#revDescr").text(elm.description).removeClass("text-danger")
if (elm.status === "failed") { if (elm.status === "failed") {

View File

@@ -35,6 +35,7 @@ type StatusInfo struct {
Analytics bool Analytics bool
LimitedToNamespace string LimitedToNamespace string
CacheHitRatio float64 CacheHitRatio float64
ClusterMode bool
} }
func (d *DataLayer) runCommand(cmd ...string) (string, error) { func (d *DataLayer) runCommand(cmd ...string) (string, error) {
@@ -74,10 +75,17 @@ func (d *DataLayer) CheckConnectivity() error {
} }
if len(contexts) < 1 { if len(contexts) < 1 {
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") 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 { if err != nil {
return err return err
} }

View File

@@ -3,6 +3,7 @@ package subproc
import ( import (
"encoding/json" "encoding/json"
v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"os"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
@@ -31,6 +32,12 @@ type KubeContext struct {
} }
func (d *DataLayer) ListContexts() (res []KubeContext, err error) { 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") out, err := d.runCommandKubectl("config", "get-contexts")
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -12,6 +12,7 @@ import (
func (d *DataLayer) ChartRepoList() (res []RepositoryElement, err error) { func (d *DataLayer) ChartRepoList() (res []RepositoryElement, err error) {
out, err := d.Cache.String(CacheKeyAllRepos, nil, func() (string, 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") return d.runCommandHelm("repo", "list", "--output", "json")
}) })
if err != nil { if err != nil {

View File

@@ -11,6 +11,7 @@ if [ -n "${HELM_PUSH_PLUGIN_NO_INSTALL_HOOK}" ]; then
fi fi
version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" 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} ..." echo "Downloading and installing ${name} v${version} ..."
url="" url=""