From 224c7bdb901a0b53e04ed97f35457a86c653df67 Mon Sep 17 00:00:00 2001 From: Joscha Alisch Date: Tue, 4 Feb 2020 22:07:33 +0100 Subject: [PATCH] Add readonly configuration option --- internal/config/k9s.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 7982bec8..ae439edf 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -6,12 +6,14 @@ const ( defaultRefreshRate = 2 defaultLogRequestSize = 200 defaultLogBufferSize = 1000 + defaultReadOnly = false ) // K9s tracks K9s configuration options. type K9s struct { RefreshRate int `yaml:"refreshRate"` Headless bool `yaml:"headless"` + ReadOnly bool `yaml:"readOnly"` LogBufferSize int `yaml:"logBufferSize"` LogRequestSize int `yaml:"logRequestSize"` CurrentContext string `yaml:"currentContext"` @@ -20,6 +22,7 @@ type K9s struct { Clusters map[string]*Cluster `yaml:"clusters,omitempty"` manualRefreshRate int manualHeadless *bool + manualReadOnly *bool manualCommand *string } @@ -27,6 +30,7 @@ type K9s struct { func NewK9s() *K9s { return &K9s{ RefreshRate: defaultRefreshRate, + ReadOnly: defaultReadOnly, LogBufferSize: defaultLogBufferSize, LogRequestSize: defaultLogRequestSize, Clusters: make(map[string]*Cluster), @@ -43,6 +47,11 @@ func (k *K9s) OverrideHeadless(b bool) { k.manualHeadless = &b } +// OverrideReadOnly set the readonly mode manually. +func (k *K9s) OverrideReadOnly(b bool) { + k.manualReadOnly = &b +} + // OverrideCommand set the command manually. func (k *K9s) OverrideCommand(cmd string) { k.manualCommand = &cmd @@ -68,6 +77,15 @@ func (k *K9s) GetRefreshRate() int { return rate } +// GetReadOnly returns the readonly setting. +func (k *K9s) GetReadOnly() bool { + readOnly := k.ReadOnly + if k.manualReadOnly != nil && *k.manualReadOnly { + readOnly = *k.manualReadOnly + } + return readOnly +} + // ActiveCluster returns the currently active cluster. func (k *K9s) ActiveCluster() *Cluster { if k.Clusters == nil {