forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.go
54 lines (45 loc) · 1.33 KB
/
cluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package config
import "github.com/derailed/k9s/internal/client"
// DefaultPFAddress specifies the default PortForward host address.
const DefaultPFAddress = "localhost"
// Cluster tracks K9s cluster configuration.
type Cluster struct {
Namespace *Namespace `yaml:"namespace"`
View *View `yaml:"view"`
FeatureGates *FeatureGates `yaml:"featureGates"`
ShellPod *ShellPod `yaml:"shellPod"`
PortForwardAddress string `yaml:"portForwardAddress"`
}
// NewCluster creates a new cluster configuration.
func NewCluster() *Cluster {
return &Cluster{
Namespace: NewNamespace(),
View: NewView(),
PortForwardAddress: DefaultPFAddress,
FeatureGates: NewFeatureGates(),
ShellPod: NewShellPod(),
}
}
// Validate a cluster config.
func (c *Cluster) Validate(conn client.Connection, ks KubeSettings) {
if c.PortForwardAddress == "" {
c.PortForwardAddress = DefaultPFAddress
}
if c.Namespace == nil {
c.Namespace = NewNamespace()
}
if c.Namespace.Active == client.AllNamespaces {
c.Namespace.Active = client.NamespaceAll
}
if c.FeatureGates == nil {
c.FeatureGates = NewFeatureGates()
}
if c.View == nil {
c.View = NewView()
}
c.View.Validate()
if c.ShellPod == nil {
c.ShellPod = NewShellPod()
}
c.ShellPod.Validate(conn, ks)
}