mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
rebase onto head
This commit is contained in:
@@ -30,7 +30,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/apis/experimental"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/expapi"
|
||||
"k8s.io/kubernetes/pkg/fieldpath"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
qosutil "k8s.io/kubernetes/pkg/kubelet/qos/util"
|
||||
@@ -70,7 +69,7 @@ func describerMap(c *client.Client) map[string]Describer {
|
||||
m := map[string]Describer{
|
||||
"Pod": &PodDescriber{c},
|
||||
"ReplicationController": &ReplicationControllerDescriber{c},
|
||||
"Daemon": &DaemonDescriber{c},
|
||||
"DaemonSet": &DaemonSetDescriber{c},
|
||||
"Secret": &SecretDescriber{c},
|
||||
"Service": &ServiceDescriber{c},
|
||||
"ServiceAccount": &ServiceAccountDescriber{c},
|
||||
@@ -130,7 +129,7 @@ func init() {
|
||||
describePod,
|
||||
describeService,
|
||||
describeReplicationController,
|
||||
describeDaemon,
|
||||
describeDaemonSet,
|
||||
describeNode,
|
||||
describeNamespace,
|
||||
)
|
||||
@@ -426,7 +425,6 @@ type PodDescriber struct {
|
||||
|
||||
func (d *PodDescriber) Describe(namespace, name string) (string, error) {
|
||||
rc := d.ReplicationControllers(namespace)
|
||||
dc := d.Daemons(namespace)
|
||||
pc := d.Pods(namespace)
|
||||
|
||||
pod, err := pc.Get(name)
|
||||
@@ -457,15 +455,11 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
daemons, err := getDaemonsForLabels(dc, labels.Set(pod.Labels))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return describePod(pod, rcs, daemons, events)
|
||||
return describePod(pod, rcs, events)
|
||||
}
|
||||
|
||||
func describePod(pod *api.Pod, rcs []api.ReplicationController, daemons []expapi.Daemon, events *api.EventList) (string, error) {
|
||||
func describePod(pod *api.Pod, rcs []api.ReplicationController, events *api.EventList) (string, error) {
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
fmt.Fprintf(out, "Name:\t%s\n", pod.Name)
|
||||
fmt.Fprintf(out, "Namespace:\t%s\n", pod.Namespace)
|
||||
@@ -485,7 +479,6 @@ func describePod(pod *api.Pod, rcs []api.ReplicationController, daemons []expapi
|
||||
fmt.Fprintf(out, "Message:\t%s\n", pod.Status.Message)
|
||||
fmt.Fprintf(out, "IP:\t%s\n", pod.Status.PodIP)
|
||||
fmt.Fprintf(out, "Replication Controllers:\t%s\n", printReplicationControllersByLabels(rcs))
|
||||
fmt.Fprintf(out, "Daemons:\t%s\n", printDaemonsByLabels(daemons))
|
||||
fmt.Fprintf(out, "Containers:\n")
|
||||
describeContainers(pod, out)
|
||||
if len(pod.Status.Conditions) > 0 {
|
||||
@@ -905,13 +898,13 @@ func describeJob(job *experimental.Job, events *api.EventList) (string, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// DaemonDescriber generates information about a daemon and the pods it has created.
|
||||
type DaemonDescriber struct {
|
||||
// DaemonSetDescriber generates information about a daemon set and the pods it has created.
|
||||
type DaemonSetDescriber struct {
|
||||
client.Interface
|
||||
}
|
||||
|
||||
func (d *DaemonDescriber) Describe(namespace, name string) (string, error) {
|
||||
dc := d.Daemons(namespace)
|
||||
func (d *DaemonSetDescriber) Describe(namespace, name string) (string, error) {
|
||||
dc := d.Experimental().DaemonSets(namespace)
|
||||
pc := d.Pods(namespace)
|
||||
|
||||
daemon, err := dc.Get(name)
|
||||
@@ -926,10 +919,10 @@ func (d *DaemonDescriber) Describe(namespace, name string) (string, error) {
|
||||
|
||||
events, _ := d.Events(namespace).Search(daemon)
|
||||
|
||||
return describeDaemon(daemon, events, running, waiting, succeeded, failed)
|
||||
return describeDaemonSet(daemon, events, running, waiting, succeeded, failed)
|
||||
}
|
||||
|
||||
func describeDaemon(daemon *expapi.Daemon, events *api.EventList, running, waiting, succeeded, failed int) (string, error) {
|
||||
func describeDaemonSet(daemon *experimental.DaemonSet, events *api.EventList, running, waiting, succeeded, failed int) (string, error) {
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
fmt.Fprintf(out, "Name:\t%s\n", daemon.Name)
|
||||
if daemon.Spec.Template != nil {
|
||||
@@ -1402,28 +1395,28 @@ func DescribeEvents(el *api.EventList, w io.Writer) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get all daemons whose selectors would match a given set of labels.
|
||||
// Get all daemon set whose selectors would match a given set of labels.
|
||||
// TODO: Move this to pkg/client and ideally implement it server-side (instead
|
||||
// of getting all RC's and searching through them manually).
|
||||
// of getting all DS's and searching through them manually).
|
||||
// TODO: write an interface for controllers and fuse getReplicationControllersForLabels
|
||||
// and getDaemonsForLabels.
|
||||
func getDaemonsForLabels(c client.DaemonInterface, labelsToMatch labels.Labels) ([]expapi.Daemon, error) {
|
||||
// Get all daemon controllers.
|
||||
// TODO this needs a namespace scope as argument
|
||||
daemons, err := c.List(labels.Everything())
|
||||
// and getDaemonSetsForLabels.
|
||||
func getDaemonSetsForLabels(c client.DaemonSetInterface, labelsToMatch labels.Labels) ([]experimental.DaemonSet, error) {
|
||||
// Get all daemon sets
|
||||
// TODO: this needs a namespace scope as argument
|
||||
dss, err := c.List(labels.Everything())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting daemons: %v", err)
|
||||
return nil, fmt.Errorf("error getting daemon set: %v", err)
|
||||
}
|
||||
|
||||
// Find the ones that match labelsToMatch.
|
||||
var matchingDaemons []expapi.Daemon
|
||||
for _, daemon := range daemons.Items {
|
||||
selector := labels.SelectorFromSet(daemon.Spec.Selector)
|
||||
var matchingDaemonSets []experimental.DaemonSet
|
||||
for _, ds := range dss.Items {
|
||||
selector := labels.SelectorFromSet(ds.Spec.Selector)
|
||||
if selector.Matches(labelsToMatch) {
|
||||
matchingDaemons = append(matchingDaemons, daemon)
|
||||
matchingDaemonSets = append(matchingDaemonSets, ds)
|
||||
}
|
||||
}
|
||||
return matchingDaemons, nil
|
||||
return matchingDaemonSets, nil
|
||||
}
|
||||
|
||||
// Get all replication controllers whose selectors would match a given set of
|
||||
@@ -1449,20 +1442,6 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
|
||||
return matchingRCs, nil
|
||||
}
|
||||
|
||||
func printDaemonsByLabels(matchingDaemons []expapi.Daemon) string {
|
||||
// Format the matching RC's into strings.
|
||||
var daemonStrings []string
|
||||
for _, daemon := range matchingDaemons {
|
||||
daemonStrings = append(daemonStrings, fmt.Sprintf("%s (%d desired, %d nodes scheduled, %d nodes misscheduled)", daemon.Name, daemon.Status.DesiredNumberScheduled, daemon.Status.CurrentNumberScheduled, daemon.Status.NumberMisscheduled))
|
||||
}
|
||||
|
||||
list := strings.Join(daemonStrings, ", ")
|
||||
if list == "" {
|
||||
return "<none>"
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func printReplicationControllersByLabels(matchingRCs []api.ReplicationController) string {
|
||||
// Format the matching RC's into strings.
|
||||
var rcStrings []string
|
||||
|
||||
Reference in New Issue
Block a user