fix for issue #67

mine
derailed 2019-02-18 22:03:00 -07:00
parent 1bcdc65fcf
commit d8721bd4b1
27 changed files with 81 additions and 189 deletions

1
go.sum
View File

@ -191,6 +191,7 @@ k8s.io/apimachinery v0.0.0-20190207091153-095b9d203467 h1:zmz9UYvvXrK/B8EDqFuqre
k8s.io/apimachinery v0.0.0-20190207091153-095b9d203467/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= k8s.io/apimachinery v0.0.0-20190207091153-095b9d203467/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/cli-runtime v0.0.0-20190207094101-a32b78e5dd0a h1:MrGQxLLZ09Bl5hYYU9VlKnhY60bpPlYd9yXOPnxkdc0= k8s.io/cli-runtime v0.0.0-20190207094101-a32b78e5dd0a h1:MrGQxLLZ09Bl5hYYU9VlKnhY60bpPlYd9yXOPnxkdc0=
k8s.io/cli-runtime v0.0.0-20190207094101-a32b78e5dd0a/go.mod h1:qWnH3/b8sp/l7EvlDh7ulDU3UWA4P4N1NFbEEP791tM= k8s.io/cli-runtime v0.0.0-20190207094101-a32b78e5dd0a/go.mod h1:qWnH3/b8sp/l7EvlDh7ulDU3UWA4P4N1NFbEEP791tM=
k8s.io/cli-runtime v0.0.0-20190216015921-a605ecc9d9a2 h1:uZv4rNoeZQATWMIYjVG5ke1lY6Yu/p8d/jBq/Ukn2Pk=
k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34= k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34=
k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/klog v0.1.0 h1:I5HMfc/DtuVaGR1KPwUrTc476K8NCqNBldC7H4dYEzk= k8s.io/klog v0.1.0 h1:I5HMfc/DtuVaGR1KPwUrTc476K8NCqNBldC7H4dYEzk=

View File

@ -1,10 +1,14 @@
package resource package resource
import ( import (
"bytes"
"path" "path"
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
) )
type ( type (
@ -71,3 +75,16 @@ func (b *Base) Delete(path string) error {
func (*Base) namespacedName(m metav1.ObjectMeta) string { func (*Base) namespacedName(m metav1.ObjectMeta) string {
return path.Join(m.Namespace, m.Name) return path.Join(m.Namespace, m.Name)
} }
func (*Base) marshalObject(o runtime.Object) (string, error) {
var (
buff bytes.Buffer
p printers.YAMLPrinter
)
err := p.PrintObj(o, &buff)
if err != nil {
log.Errorf("Marshal Error %v", err)
return "", err
}
return buff.String(), nil
}

View File

@ -5,7 +5,6 @@ import (
"strconv" "strconv"
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
yaml "gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
) )
@ -68,11 +67,7 @@ func (r *ConfigMap) Marshal(path string) (string, error) {
cm := i.(*v1.ConfigMap) cm := i.(*v1.ConfigMap)
cm.TypeMeta.APIVersion = "v1" cm.TypeMeta.APIVersion = "v1"
cm.TypeMeta.Kind = "ConfigMap" cm.TypeMeta.Kind = "ConfigMap"
raw, err := yaml.Marshal(i) return r.marshalObject(cm)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -3,9 +3,7 @@ package resource
import ( import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"k8s.io/api/rbac/v1" v1 "k8s.io/api/rbac/v1"
"gopkg.in/yaml.v2"
) )
// ClusterRole tracks a kubernetes resource. // ClusterRole tracks a kubernetes resource.
@ -67,11 +65,7 @@ func (r *ClusterRole) Marshal(path string) (string, error) {
cr := i.(*v1.ClusterRole) cr := i.(*v1.ClusterRole)
cr.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1" cr.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1"
cr.TypeMeta.Kind = "ClusterRole" cr.TypeMeta.Kind = "ClusterRole"
raw, err := yaml.Marshal(i) return r.marshalObject(cr)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -3,8 +3,7 @@ package resource
import ( import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/rbac/v1"
"k8s.io/api/rbac/v1"
) )
// ClusterRoleBinding tracks a kubernetes resource. // ClusterRoleBinding tracks a kubernetes resource.
@ -66,11 +65,7 @@ func (r *ClusterRoleBinding) Marshal(path string) (string, error) {
crb := i.(*v1.ClusterRoleBinding) crb := i.(*v1.ClusterRoleBinding)
crb.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1" crb.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1"
crb.TypeMeta.Kind = "ClusterRoleBinding" crb.TypeMeta.Kind = "ClusterRoleBinding"
raw, err := yaml.Marshal(crb) return r.marshalObject(crb)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,7 +5,6 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
) )
@ -68,11 +67,7 @@ func (r *CRD) Marshal(path string) (string, error) {
return "", err return "", err
} }
raw, err := yaml.Marshal(i) return r.marshalObject(i.(*unstructured.Unstructured))
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return the resource header. // Header return the resource header.

View File

@ -5,7 +5,6 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
batchv1beta1 "k8s.io/api/batch/v1beta1" batchv1beta1 "k8s.io/api/batch/v1beta1"
) )
@ -65,14 +64,10 @@ func (r *CronJob) Marshal(path string) (string, error) {
return "", err return "", err
} }
dp := i.(*batchv1beta1.CronJob) cj := i.(*batchv1beta1.CronJob)
dp.TypeMeta.APIVersion = "extensions/batchv1beta1" cj.TypeMeta.APIVersion = "extensions/batchv1beta1"
dp.TypeMeta.Kind = "CronJob" cj.TypeMeta.Kind = "CronJob"
raw, err := yaml.Marshal(i) return r.marshalObject(cj)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/apps/v1"
"k8s.io/api/apps/v1"
) )
// Deployment tracks a kubernetes resource. // Deployment tracks a kubernetes resource.
@ -68,11 +67,7 @@ func (r *Deployment) Marshal(path string) (string, error) {
dp := i.(*v1.Deployment) dp := i.(*v1.Deployment)
dp.TypeMeta.APIVersion = "apps/v1" dp.TypeMeta.APIVersion = "apps/v1"
dp.TypeMeta.Kind = "Deployment" dp.TypeMeta.Kind = "Deployment"
raw, err := yaml.Marshal(i) return r.marshalObject(dp)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,7 +5,6 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
extv1beta1 "k8s.io/api/extensions/v1beta1" extv1beta1 "k8s.io/api/extensions/v1beta1"
) )
@ -65,14 +64,10 @@ func (r *DaemonSet) Marshal(path string) (string, error) {
return "", err return "", err
} }
dp := i.(*extv1beta1.DaemonSet) ds := i.(*extv1beta1.DaemonSet)
dp.TypeMeta.APIVersion = "extensions/v1beta1" ds.TypeMeta.APIVersion = "extensions/v1beta1"
dp.TypeMeta.Kind = "DaemonSet" ds.TypeMeta.Kind = "DaemonSet"
raw, err := yaml.Marshal(i) return r.marshalObject(ds)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -7,8 +7,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// Endpoints tracks a kubernetes resource. // Endpoints tracks a kubernetes resource.
@ -69,12 +68,8 @@ func (r *Endpoints) Marshal(path string) (string, error) {
ep := i.(*v1.Endpoints) ep := i.(*v1.Endpoints)
ep.TypeMeta.APIVersion = "v1" ep.TypeMeta.APIVersion = "v1"
ep.TypeMeta.Kind = "Endpoints" ep.TypeMeta.Kind = "Endpoint"
raw, err := yaml.Marshal(ep) return r.marshalObject(ep)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -6,8 +6,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// Event tracks a kubernetes resource. // Event tracks a kubernetes resource.
@ -69,11 +68,7 @@ func (r *Event) Marshal(path string) (string, error) {
ev := i.(*v1.Event) ev := i.(*v1.Event)
ev.TypeMeta.APIVersion = "v1" ev.TypeMeta.APIVersion = "v1"
ev.TypeMeta.Kind = "Event" ev.TypeMeta.Kind = "Event"
raw, err := yaml.Marshal(ev) return r.marshalObject(ev)
if err != nil {
return "", err
}
return string(raw), nil
} }
// // Get resource given a namespaced name. // // Get resource given a namespaced name.

View File

@ -6,8 +6,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/autoscaling/v1"
"k8s.io/api/autoscaling/v1"
) )
// HPA tracks a kubernetes resource. // HPA tracks a kubernetes resource.
@ -68,12 +67,8 @@ func (r *HPA) Marshal(path string) (string, error) {
hpa := i.(*v1.HorizontalPodAutoscaler) hpa := i.(*v1.HorizontalPodAutoscaler)
hpa.TypeMeta.APIVersion = "autoscaling/v1" hpa.TypeMeta.APIVersion = "autoscaling/v1"
hpa.TypeMeta.Kind = "HPA" hpa.TypeMeta.Kind = "HorizontalPodAutoscaler"
raw, err := yaml.Marshal(i) return r.marshalObject(hpa)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1" "k8s.io/api/extensions/v1beta1"
) )
@ -69,11 +68,7 @@ func (r *Ingress) Marshal(path string) (string, error) {
ing := i.(*v1beta1.Ingress) ing := i.(*v1beta1.Ingress)
ing.TypeMeta.APIVersion = "extensions/v1beta1" ing.TypeMeta.APIVersion = "extensions/v1beta1"
ing.TypeMeta.Kind = "Ingress" ing.TypeMeta.Kind = "Ingress"
raw, err := yaml.Marshal(i) return r.marshalObject(ing)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -6,8 +6,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/util/duration" "k8s.io/apimachinery/pkg/util/duration"
) )
@ -67,14 +66,10 @@ func (r *Job) Marshal(path string) (string, error) {
return "", err return "", err
} }
dp := i.(*v1.Job) jo := i.(*v1.Job)
dp.TypeMeta.APIVersion = "extensions/v1beta1" jo.TypeMeta.APIVersion = "extensions/v1beta1"
dp.TypeMeta.Kind = "Job" jo.TypeMeta.Kind = "Job"
raw, err := yaml.Marshal(i) return r.marshalObject(jo)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -7,8 +7,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
const ( const (
@ -105,11 +104,7 @@ func (r *Node) Marshal(path string) (string, error) {
no := i.(*v1.Node) no := i.(*v1.Node)
no.TypeMeta.APIVersion = "v1" no.TypeMeta.APIVersion = "v1"
no.TypeMeta.Kind = "Node" no.TypeMeta.Kind = "Node"
raw, err := yaml.Marshal(no) return r.marshalObject(no)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header returns resource header. // Header returns resource header.

View File

@ -3,8 +3,7 @@ package resource
import ( import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// Namespace tracks a kubernetes resource. // Namespace tracks a kubernetes resource.
@ -67,11 +66,7 @@ func (r *Namespace) Marshal(path string) (string, error) {
nss := i.(*v1.Namespace) nss := i.(*v1.Namespace)
nss.TypeMeta.APIVersion = "v1" nss.TypeMeta.APIVersion = "v1"
nss.TypeMeta.Kind = "Namespace" nss.TypeMeta.Kind = "Namespace"
raw, err := yaml.Marshal(nss) return r.marshalObject(nss)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header returns resource header. // Header returns resource header.

View File

@ -9,8 +9,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
const defaultTimeout = 1 * time.Second const defaultTimeout = 1 * time.Second
@ -111,11 +110,7 @@ func (r *Pod) Marshal(path string) (string, error) {
po := i.(*v1.Pod) po := i.(*v1.Pod)
po.TypeMeta.APIVersion = "v1" po.TypeMeta.APIVersion = "v1"
po.TypeMeta.Kind = "Pod" po.TypeMeta.Kind = "Pod"
raw, err := yaml.Marshal(po) return r.marshalObject(po)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Containers lists out all the docker contrainers name contained in a pod. // Containers lists out all the docker contrainers name contained in a pod.

View File

@ -6,8 +6,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// PV tracks a kubernetes resource. // PV tracks a kubernetes resource.
@ -68,12 +67,8 @@ func (r *PV) Marshal(path string) (string, error) {
pv := i.(*v1.PersistentVolume) pv := i.(*v1.PersistentVolume)
pv.TypeMeta.APIVersion = "v1" pv.TypeMeta.APIVersion = "v1"
pv.TypeMeta.Kind = "PV" pv.TypeMeta.Kind = "PeristentVolume"
raw, err := yaml.Marshal(pv) return r.marshalObject(pv)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -3,8 +3,7 @@ package resource
import ( import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// PVC tracks a kubernetes resource. // PVC tracks a kubernetes resource.
@ -66,11 +65,7 @@ func (r *PVC) Marshal(path string) (string, error) {
pvc := i.(*v1.PersistentVolumeClaim) pvc := i.(*v1.PersistentVolumeClaim)
pvc.TypeMeta.APIVersion = "v1" pvc.TypeMeta.APIVersion = "v1"
pvc.TypeMeta.Kind = "PersistentVolumeClaim" pvc.TypeMeta.Kind = "PersistentVolumeClaim"
raw, err := yaml.Marshal(pvc) return r.marshalObject(pvc)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// ReplicationController tracks a kubernetes resource. // ReplicationController tracks a kubernetes resource.
@ -65,14 +64,10 @@ func (r *ReplicationController) Marshal(path string) (string, error) {
return "", err return "", err
} }
rs := i.(*v1.ReplicationController) rc := i.(*v1.ReplicationController)
rs.TypeMeta.APIVersion = "v1" rc.TypeMeta.APIVersion = "v1"
rs.TypeMeta.Kind = "ReplicationController" rc.TypeMeta.Kind = "ReplicationController"
raw, err := yaml.Marshal(rs) return r.marshalObject(rc)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/rbac/v1"
"k8s.io/api/rbac/v1"
) )
// Role tracks a kubernetes resource. // Role tracks a kubernetes resource.
@ -70,11 +69,7 @@ func (r *Role) Marshal(path string) (string, error) {
role := i.(*v1.Role) role := i.(*v1.Role)
role.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1" role.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1"
role.TypeMeta.Kind = "Role" role.TypeMeta.Kind = "Role"
raw, err := yaml.Marshal(role) return r.marshalObject(role)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/rbac/v1"
"k8s.io/api/rbac/v1"
) )
// RoleBinding tracks a kubernetes resource. // RoleBinding tracks a kubernetes resource.
@ -68,11 +67,7 @@ func (r *RoleBinding) Marshal(path string) (string, error) {
rb := i.(*v1.RoleBinding) rb := i.(*v1.RoleBinding)
rb.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1" rb.TypeMeta.APIVersion = "rbac.authorization.k8s.io/v1"
rb.TypeMeta.Kind = "RoleBinding" rb.TypeMeta.Kind = "RoleBinding"
raw, err := yaml.Marshal(rb) return r.marshalObject(rb)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/apps/v1"
"k8s.io/api/apps/v1"
) )
// ReplicaSet tracks a kubernetes resource. // ReplicaSet tracks a kubernetes resource.
@ -68,11 +67,7 @@ func (r *ReplicaSet) Marshal(path string) (string, error) {
rs := i.(*v1.ReplicaSet) rs := i.(*v1.ReplicaSet)
rs.TypeMeta.APIVersion = "extensions/v1beta" rs.TypeMeta.APIVersion = "extensions/v1beta"
rs.TypeMeta.Kind = "ReplicaSet" rs.TypeMeta.Kind = "ReplicaSet"
raw, err := yaml.Marshal(rs) return r.marshalObject(rs)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// ServiceAccount represents a Kubernetes resource. // ServiceAccount represents a Kubernetes resource.
@ -68,11 +67,7 @@ func (r *ServiceAccount) Marshal(path string) (string, error) {
sa := i.(*v1.ServiceAccount) sa := i.(*v1.ServiceAccount)
sa.TypeMeta.APIVersion = "v1" sa.TypeMeta.APIVersion = "v1"
sa.TypeMeta.Kind = "ServiceAccount" sa.TypeMeta.Kind = "ServiceAccount"
raw, err := yaml.Marshal(i) return r.marshalObject(sa)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"strconv" "strconv"
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
) )
// Secret tracks a kubernetes resource. // Secret tracks a kubernetes resource.
@ -65,14 +64,10 @@ func (r *Secret) Marshal(path string) (string, error) {
return "", err return "", err
} }
cm := i.(*v1.Secret) sec := i.(*v1.Secret)
cm.TypeMeta.APIVersion = "v1" sec.TypeMeta.APIVersion = "v1"
cm.TypeMeta.Kind = "Secret" sec.TypeMeta.Kind = "Secret"
raw, err := yaml.Marshal(i) return r.marshalObject(sec)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -5,8 +5,7 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2" v1 "k8s.io/api/apps/v1"
"k8s.io/api/apps/v1"
) )
// StatefulSet tracks a kubernetes resource. // StatefulSet tracks a kubernetes resource.
@ -68,11 +67,7 @@ func (r *StatefulSet) Marshal(path string) (string, error) {
sts := i.(*v1.StatefulSet) sts := i.(*v1.StatefulSet)
sts.TypeMeta.APIVersion = "v1" sts.TypeMeta.APIVersion = "v1"
sts.TypeMeta.Kind = "StatefulSet" sts.TypeMeta.Kind = "StatefulSet"
raw, err := yaml.Marshal(i) return r.marshalObject(sts)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header return resource header. // Header return resource header.

View File

@ -7,7 +7,6 @@ import (
"github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
) )
@ -73,11 +72,7 @@ func (r *Service) Marshal(path string) (string, error) {
svc := i.(*v1.Service) svc := i.(*v1.Service)
svc.TypeMeta.APIVersion = "v1" svc.TypeMeta.APIVersion = "v1"
svc.TypeMeta.Kind = "Service" svc.TypeMeta.Kind = "Service"
raw, err := yaml.Marshal(svc) return r.marshalObject(svc)
if err != nil {
return "", err
}
return string(raw), nil
} }
// Header returns resource header. // Header returns resource header.