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

@@ -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
}

View File

@@ -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

View File

@@ -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 {