update shell pod config

mine
derailed 2020-05-14 18:39:34 -06:00
parent 037d6d3f54
commit 4bd37a492f
4 changed files with 80 additions and 16 deletions

View File

@ -9,6 +9,7 @@ type Cluster struct {
Namespace *Namespace `yaml:"namespace"`
View *View `yaml:"view"`
FeatureGates *FeatureGates `yaml:"featureGates"`
ShellPod *ShellPod `yaml:"shellPod"`
}
// NewCluster creates a new cluster configuration.
@ -17,6 +18,7 @@ func NewCluster() *Cluster {
Namespace: NewNamespace(),
View: NewView(),
FeatureGates: NewFeatureGates(),
ShellPod: NewShellPod(),
}
}
@ -34,4 +36,9 @@ func (c *Cluster) Validate(conn client.Connection, ks KubeSettings) {
c.View = NewView()
}
c.View.Validate()
if c.ShellPod == nil {
c.ShellPod = NewShellPod()
}
c.ShellPod.Validate(conn, ks)
}

View File

@ -261,7 +261,6 @@ func TestSetup(t *testing.T) {
var expectedConfig = `k9s:
refreshRate: 100
dockerShellImage: busybox:1.31
headless: false
readOnly: true
noIcons: false
@ -284,6 +283,12 @@ var expectedConfig = `k9s:
active: po
featureGates:
nodeShell: false
shellPod:
image: busybox:1.31
namespace: default
limits:
cpu: 100m
memory: 100Mi
fred:
namespace:
active: default
@ -297,6 +302,12 @@ var expectedConfig = `k9s:
active: po
featureGates:
nodeShell: false
shellPod:
image: busybox:1.31
namespace: default
limits:
cpu: 100m
memory: 100Mi
minikube:
namespace:
active: kube-system
@ -310,6 +321,12 @@ var expectedConfig = `k9s:
active: ctx
featureGates:
nodeShell: false
shellPod:
image: busybox:1.31
namespace: default
limits:
cpu: 100m
memory: 100Mi
thresholds:
cpu:
critical: 90
@ -321,7 +338,6 @@ var expectedConfig = `k9s:
var resetConfig = `k9s:
refreshRate: 2
dockerShellImage: busybox:1.31
headless: false
readOnly: false
noIcons: false
@ -344,6 +360,12 @@ var resetConfig = `k9s:
active: po
featureGates:
nodeShell: false
shellPod:
image: busybox:1.31
namespace: default
limits:
cpu: 100m
memory: 100Mi
thresholds:
cpu:
critical: 90

View File

@ -2,16 +2,11 @@ package config
import "github.com/derailed/k9s/internal/client"
const (
defaultRefreshRate = 2
// DefaultDockerShellImage specifies the docker image and tag for shelling into nodes.
DefaultDockerShellImage = "busybox:1.31"
)
const defaultRefreshRate = 2
// K9s tracks K9s configuration options.
type K9s struct {
RefreshRate int `yaml:"refreshRate"`
DockerShellImage string `yaml:"dockerShellImage"`
Headless bool `yaml:"headless"`
ReadOnly bool `yaml:"readOnly"`
NoIcons bool `yaml:"noIcons"`
@ -29,11 +24,10 @@ type K9s struct {
// NewK9s create a new K9s configuration.
func NewK9s() *K9s {
return &K9s{
RefreshRate: defaultRefreshRate,
DockerShellImage: DefaultDockerShellImage,
Logger: NewLogger(),
Clusters: make(map[string]*Cluster),
Thresholds: NewThreshold(),
RefreshRate: defaultRefreshRate,
Logger: NewLogger(),
Clusters: make(map[string]*Cluster),
Thresholds: NewThreshold(),
}
}
@ -104,9 +98,6 @@ func (k *K9s) validateDefaults() {
if k.RefreshRate <= 0 {
k.RefreshRate = defaultRefreshRate
}
if k.DockerShellImage == "" {
k.DockerShellImage = DefaultDockerShellImage
}
}
func (k *K9s) validateClusters(c client.Connection, ks KubeSettings) {

View File

@ -0,0 +1,44 @@
package config
import (
"github.com/derailed/k9s/internal/client"
v1 "k8s.io/api/core/v1"
)
const defaultDockerShellImage = "busybox:1.31"
// Limits represents resource limits.
type Limits map[v1.ResourceName]string
// ShellPod represents k9s shell configuration.
type ShellPod struct {
Image string `json:"Image"`
Namespace string `json:"namespace"`
Limits Limits `json:"resources,omitempty"`
}
// NewShellPod returns a new instance.
func NewShellPod() *ShellPod {
return &ShellPod{
Image: defaultDockerShellImage,
Namespace: "default",
Limits: defaultLimits(),
}
}
// Validate validates the configuration.
func (s *ShellPod) Validate(client.Connection, KubeSettings) {
if s.Image == "" {
s.Image = defaultDockerShellImage
}
if len(s.Limits) == 0 {
s.Limits = defaultLimits()
}
}
func defaultLimits() Limits {
return Limits{
v1.ResourceCPU: "100m",
v1.ResourceMemory: "100Mi",
}
}