98 lines
2.2 KiB
Go
98 lines
2.2 KiB
Go
package resource
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/derailed/k9s/internal/k8s"
|
|
"github.com/rs/zerolog/log"
|
|
extv1beta1 "k8s.io/api/extensions/v1beta1"
|
|
)
|
|
|
|
// DaemonSet tracks a kubernetes resource.
|
|
type DaemonSet struct {
|
|
*Base
|
|
instance *extv1beta1.DaemonSet
|
|
}
|
|
|
|
// NewDaemonSetList returns a new resource list.
|
|
func NewDaemonSetList(c Connection, ns string) List {
|
|
return NewList(
|
|
ns,
|
|
"ds",
|
|
NewDaemonSet(c),
|
|
AllVerbsAccess|DescribeAccess,
|
|
)
|
|
}
|
|
|
|
// NewDaemonSet instantiates a new DaemonSet.
|
|
func NewDaemonSet(c Connection) *DaemonSet {
|
|
ds := &DaemonSet{&Base{Connection: c, Resource: k8s.NewDaemonSet(c)}, nil}
|
|
ds.Factory = ds
|
|
|
|
return ds
|
|
}
|
|
|
|
// New builds a new DaemonSet instance from a k8s resource.
|
|
func (r *DaemonSet) New(i interface{}) Columnar {
|
|
c := NewDaemonSet(r.Connection)
|
|
switch instance := i.(type) {
|
|
case *extv1beta1.DaemonSet:
|
|
c.instance = instance
|
|
case extv1beta1.DaemonSet:
|
|
c.instance = &instance
|
|
default:
|
|
log.Fatal().Msgf("unknown DaemonSet type %#v", i)
|
|
}
|
|
c.path = c.namespacedName(c.instance.ObjectMeta)
|
|
|
|
return c
|
|
}
|
|
|
|
// Marshal resource to yaml.
|
|
func (r *DaemonSet) Marshal(path string) (string, error) {
|
|
ns, n := namespaced(path)
|
|
i, err := r.Resource.Get(ns, n)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
ds := i.(*extv1beta1.DaemonSet)
|
|
ds.TypeMeta.APIVersion = "extensions/v1beta1"
|
|
ds.TypeMeta.Kind = "DaemonSet"
|
|
|
|
return r.marshalObject(ds)
|
|
}
|
|
|
|
// Header return resource header.
|
|
func (*DaemonSet) Header(ns string) Row {
|
|
hh := Row{}
|
|
if ns == AllNamespaces {
|
|
hh = append(hh, "NAMESPACE")
|
|
}
|
|
hh = append(hh, "NAME", "DESIRED", "CURRENT", "READY", "UP-TO-DATE")
|
|
hh = append(hh, "AVAILABLE", "NODE_SELECTOR", "AGE")
|
|
|
|
return hh
|
|
}
|
|
|
|
// Fields retrieves displayable fields.
|
|
func (r *DaemonSet) Fields(ns string) Row {
|
|
ff := make([]string, 0, len(r.Header(ns)))
|
|
|
|
i := r.instance
|
|
if ns == AllNamespaces {
|
|
ff = append(ff, i.Namespace)
|
|
}
|
|
|
|
return append(ff,
|
|
i.Name,
|
|
strconv.Itoa(int(i.Status.DesiredNumberScheduled)),
|
|
strconv.Itoa(int(i.Status.CurrentNumberScheduled)),
|
|
strconv.Itoa(int(i.Status.NumberReady)),
|
|
strconv.Itoa(int(i.Status.UpdatedNumberScheduled)),
|
|
strconv.Itoa(int(i.Status.NumberAvailable)),
|
|
mapToStr(i.Spec.Template.Spec.NodeSelector),
|
|
toAge(i.ObjectMeta.CreationTimestamp),
|
|
)
|
|
}
|