cleaning up

mine
derailed 2020-10-29 17:18:46 -06:00
parent 883f3b7695
commit da8a65e59a
13 changed files with 29 additions and 8 deletions

View File

@ -94,7 +94,7 @@ func (k *K9s) GetRefreshRate() int {
return rate
}
// GetReadOnly returns the readonly setting.
// IsReadOnly returns the readonly setting.
func (k *K9s) IsReadOnly() bool {
readOnly := k.ReadOnly
if k.manualReadOnly != nil {

View File

@ -212,6 +212,7 @@ func (d *Deployment) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs
return refs, nil
}
// GetPodSpec returns a pod spec given a resource.
func (d *Deployment) GetPodSpec(path string) (*v1.PodSpec, error) {
dp, err := d.Load(d.Factory, path)
if err != nil {
@ -221,6 +222,7 @@ func (d *Deployment) GetPodSpec(path string) (*v1.PodSpec, error) {
return &podSpec, nil
}
// SetImages sets container images.
func (d *Deployment) SetImages(ctx context.Context, path string, imageSpecs ImageSpecs) error {
ns, n := client.Namespaced(path)
auth, err := d.Client().CanI(ns, "apps/v1/deployments", []string{client.PatchVerb})

View File

@ -226,6 +226,7 @@ func (d *DaemonSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs,
return refs, nil
}
// GetPodSpec returns a pod spec given a resource.
func (d *DaemonSet) GetPodSpec(path string) (*v1.PodSpec, error) {
ds, err := d.GetInstance(path)
if err != nil {
@ -235,6 +236,7 @@ func (d *DaemonSet) GetPodSpec(path string) (*v1.PodSpec, error) {
return &podSpec, nil
}
// SetImages sets container images.
func (d *DaemonSet) SetImages(ctx context.Context, path string, imageSpecs ImageSpecs) error {
ns, n := client.Namespaced(path)
auth, err := d.Client().CanI(ns, "apps/v1/daemonset", []string{client.PatchVerb})

View File

@ -4,26 +4,32 @@ import (
"encoding/json"
)
// ImageSpec represents a container image.
type ImageSpec struct {
Index int
Name, DockerImage string
Init bool
}
// ImageSpecs represents a collection of container images.
type ImageSpecs []ImageSpec
// JsonPatch track pod spec updates.
type JsonPatch struct {
Spec Spec `json:"spec"`
}
// Spec represents a pod template.
type Spec struct {
Template PodSpec `json:"template"`
}
// PodSpec represents a collection of container images.
type PodSpec struct {
Spec ImagesSpec `json:"spec"`
}
// ImagesSpec tracks container image updates.
type ImagesSpec struct {
SetElementOrderContainers []Element `json:"$setElementOrder/containers,omitempty"`
SetElementOrderInitContainers []Element `json:"$setElementOrder/initContainers,omitempty"`
@ -31,12 +37,13 @@ type ImagesSpec struct {
InitContainers []Element `json:"initContainers,omitempty"`
}
// Element tracks a given container image.
type Element struct {
Image string `json:"image,omitempty"`
Name string `json:"name"`
}
// Build a json patch string to update PodSpec images
// GetTemplateJsonPatch builds a json patch string to update PodSpec images
func GetTemplateJsonPatch(imageSpecs ImageSpecs) ([]byte, error) {
jsonPatch := JsonPatch{
Spec: Spec{
@ -46,6 +53,7 @@ func GetTemplateJsonPatch(imageSpecs ImageSpecs) ([]byte, error) {
return json.Marshal(jsonPatch)
}
// GetJsonPatch returns container image patch.
func GetJsonPatch(imageSpecs ImageSpecs) ([]byte, error) {
podSpec := getPatchPodSpec(imageSpecs)
return json.Marshal(podSpec)

View File

@ -453,6 +453,7 @@ func in(ll []string, s string) bool {
return false
}
// GetPodSpec returns a pod spec given a resource.
func (p *Pod) GetPodSpec(path string) (*v1.PodSpec, error) {
pod, err := p.GetInstance(path)
if err != nil {
@ -462,6 +463,7 @@ func (p *Pod) GetPodSpec(path string) (*v1.PodSpec, error) {
return &podSpec, nil
}
// SetImages sets container images.
func (p *Pod) SetImages(ctx context.Context, path string, imageSpecs ImageSpecs) error {
ns, n := client.Namespaced(path)
auth, err := p.Client().CanI(ns, "v1/pod", []string{client.PatchVerb})

View File

@ -222,6 +222,7 @@ func (s *StatefulSet) Scan(ctx context.Context, gvr, fqn string, wait bool) (Ref
return refs, nil
}
// GetPodSpec returns a pod spec given a resource.
func (s *StatefulSet) GetPodSpec(path string) (*v1.PodSpec, error) {
sts, err := s.getStatefulSet(path)
if err != nil {
@ -231,6 +232,7 @@ func (s *StatefulSet) GetPodSpec(path string) (*v1.PodSpec, error) {
return &podSpec, nil
}
// SetImages sets container images.
func (s *StatefulSet) SetImages(ctx context.Context, path string, imageSpecs ImageSpecs) error {
ns, n := client.Namespaced(path)
auth, err := s.Client().CanI(ns, "apps/v1/statefulset", []string{client.PatchVerb})

View File

@ -147,6 +147,7 @@ type Logger interface {
Logs(path string, opts *v1.PodLogOptions) (*restclient.Request, error)
}
// ContainsPodSpec represents a resource with a pod template.
type ContainsPodSpec interface {
// Get PodSpec of a resource
GetPodSpec(path string) (*v1.PodSpec, error)

View File

@ -8,11 +8,13 @@ import (
"github.com/sahilm/fuzzy"
)
// Filterable represents an entity that can be filtered.
type Filterable interface {
Filter(string)
ClearFilter()
}
// Textable represents a text resource.
type Textable interface {
Peek() []string
SetText(string)

View File

@ -23,7 +23,7 @@ type ResourceViewerListener interface {
ResourceFailed(error)
}
// ToggleOpts represents a collection of viewing options.
// ViewerToggleOpts represents a collection of viewing options.
type ViewerToggleOpts map[string]bool
// ResourceViewer represents a viewed resource.

View File

@ -18,7 +18,7 @@ import (
"github.com/sahilm/fuzzy"
)
// ManageFieldOpts tracks managed fields.
// ManagedFieldsOpts tracks managed fields.
const ManagedFieldsOpts = "ManagedFields"
// YAML tracks yaml resource representations.
@ -109,7 +109,7 @@ func (y *YAML) ClearFilter() {
y.query = ""
}
// Peel returns the current model data.
// Peek returns the current model data.
func (y *YAML) Peek() []string {
return y.lines
}

View File

@ -79,6 +79,7 @@ func IsFuzzySelector(s string) bool {
return fuzzyRx.MatchString(s)
}
// IsInverseSelector checks if inverse char has been provided.
func IsInverseSelector(s string) bool {
if s == "" {
return false
@ -162,8 +163,8 @@ func rxFilter(q string, inverse bool, data render.TableData) (render.TableData,
}
for _, re := range data.RowEvents {
fields := strings.Join(re.Row.Fields, " ")
if (inverse && ! rx.MatchString(fields)) ||
((! inverse) && rx.MatchString(fields)) {
if (inverse && !rx.MatchString(fields)) ||
((!inverse) && rx.MatchString(fields)) {
filtered.RowEvents = append(filtered.RowEvents, re)
}
}

View File

@ -45,6 +45,7 @@ type ImageExtender struct {
ResourceViewer
}
// NewImageExtender returns a new extender.
func NewImageExtender(r ResourceViewer) ResourceViewer {
s := ImageExtender{ResourceViewer: r}
s.AddBindKeysFn(s.bindKeys)

View File

@ -595,7 +595,7 @@ func (x *Xray) Stop() {
x.CmdBuff().RemoveListener(x)
}
// SetBindKeysFn sets up extra key bindings.
// AddBindKeysFn sets up extra key bindings.
func (x *Xray) AddBindKeysFn(BindKeysFunc) {}
// SetContextFn sets custom context.