Created
October 21, 2015 20:14
-
-
Save kelseyhightower/978c4eb52a7587e8d65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ $ diff cluster.go go/src/github.com/docker/swarm/cluster/kubernetes/cluster.go | |
7d6 | |
< "net" | |
33d31 | |
< engines map[string]*cluster.Engine | |
51d48 | |
< | |
72,88d68 | |
< engines := make(map[string]*cluster.Engine) | |
< nodes, err := kubeClient.Nodes().List(labels.Everything(), fields.Everything()) | |
< if err != nil { | |
< log.Error(err) | |
< } | |
< | |
< for _, node := range nodes.Items { | |
< var host string | |
< for _, address := range node.Status.Addresses { | |
< if address.Type == api.NodeInternalIP { | |
< host = address.Address | |
< } | |
< } | |
< engine := cluster.NewEngine(net.JoinHostPort(host, "2375"), 0) | |
< engines[node.ObjectMeta.Name] = engine | |
< } | |
< | |
94d73 | |
< engines: engines, | |
159a139 | |
> // Containers returns all the containers in the cluster. | |
163,173c143,146 | |
< for _, engine := range c.engines { | |
< err := engine.Connect(nil) | |
< if err != nil { | |
< log.Error(err) | |
< return cs | |
< } | |
< err = engine.RefreshContainers(true) | |
< if err != nil { | |
< log.Error(err) | |
< return cs | |
< } | |
--- | |
> pods, err := c.kubeClient.Pods(api.NamespaceDefault).List(labels.Everything(), fields.Everything()) | |
> if err != nil { | |
> log.Error(err) | |
> return cs | |
176,178c149,156 | |
< for _, engine := range c.engines { | |
< for _, container := range engine.Containers() { | |
< cs = append(cs, container) | |
--- | |
> for _, runningPod := range pods.Items { | |
> container := &cluster.Container{ | |
> Info: dockerclient.ContainerInfo{ | |
> Name: runningPod.Status.ContainerStatuses[0].Name, | |
> Image: runningPod.Status.ContainerStatuses[0].Image, | |
> Id: runningPod.Status.ContainerStatuses[0].ContainerID, | |
> Created: runningPod.Status.StartTime.String(), | |
> }, | |
179a158 | |
> cs = append(cs, container) | |
187,206d165 | |
< if len(IDOrName) == 0 { | |
< return nil | |
< } | |
< c.RLock() | |
< defer c.RUnlock() | |
< return cluster.Containers(c.Containers()).Get(IDOrName) | |
< } | |
< | |
< // Image returns an image with IdOrName in the cluster | |
< func (c *Cluster) Image(IDOrName string) *cluster.Image { | |
< if len(IDOrName) == 0 { | |
< return nil | |
< } | |
< c.RLock() | |
< defer c.RUnlock() | |
< for _, engine := range c.engines { | |
< if image := engine.Image(IDOrName); image != nil { | |
< return image | |
< } | |
< } | |
210,252d168 | |
< // Images returns all the images in the cluster. | |
< func (c *Cluster) Images(all bool, filters dockerfilters.Args) []*cluster.Image { | |
< c.RLock() | |
< defer c.RUnlock() | |
< images := []*cluster.Image{} | |
< for _, engine := range c.engines { | |
< images = append(images, engine.Images(all, filters)...) | |
< } | |
< return images | |
< } | |
< | |
< func (c *Cluster) Info() [][]string { | |
< return [][]string{} | |
< } | |
< | |
< func (c *Cluster) TotalCpus() int64 { | |
< nodes, err := c.kubeClient.Nodes().List(labels.Everything(), fields.Everything()) | |
< if err != nil { | |
< log.Error(err) | |
< return 0 | |
< } | |
< | |
< total := int64(0) | |
< for _, node := range nodes.Items { | |
< total += node.Status.Capacity.Cpu().Value() | |
< } | |
< return total | |
< } | |
< | |
< func (c *Cluster) TotalMemory() int64 { | |
< nodes, err := c.kubeClient.Nodes().List(labels.Everything(), fields.Everything()) | |
< if err != nil { | |
< log.Error(err) | |
< return 0 | |
< } | |
< | |
< total := int64(0) | |
< for _, node := range nodes.Items { | |
< total += node.Status.Capacity.Memory().Value() | |
< } | |
< return total | |
< } | |
< | |
282a199,213 | |
> // CreateNetwork creates a network in the cluster | |
> func (c *Cluster) CreateNetwork(request *dockerclient.NetworkCreate) (*dockerclient.NetworkCreateResponse, error) { | |
> return nil, errNotSupported | |
> } | |
> | |
> // RemoveNetwork removes network from the cluster | |
> func (c *Cluster) RemoveNetwork(network *cluster.Network) error { | |
> return errNotSupported | |
> } | |
> | |
> // Networks returns all the networks in the cluster. | |
> func (c *Cluster) Networks() cluster.Networks { | |
> return cluster.Networks{} | |
> } | |
> | |
287a219,229 | |
> // Image returns an image with IdOrName in the cluster | |
> func (c *Cluster) Image(IDOrName string) *cluster.Image { | |
> return nil | |
> } | |
> | |
> // Images returns all the images in the cluster. | |
> func (c *Cluster) Images(all bool, filters dockerfilters.Args) []*cluster.Image { | |
> images := []*cluster.Image{} | |
> return images | |
> } | |
> | |
299a242,276 | |
> // Info gives minimal information about containers and resources on the Kubernetes cluster | |
> func (c *Cluster) Info() [][]string { | |
> return [][]string{} | |
> } | |
> | |
> // TotalCpus return the total memory of the cluster | |
> func (c *Cluster) TotalCpus() int64 { | |
> nodes, err := c.kubeClient.Nodes().List(labels.Everything(), fields.Everything()) | |
> if err != nil { | |
> log.Error(err) | |
> return 0 | |
> } | |
> | |
> total := int64(0) | |
> for _, node := range nodes.Items { | |
> total += node.Status.Capacity.Cpu().Value() | |
> } | |
> return total | |
> } | |
> | |
> // TotalMemory return the total memory of the cluster | |
> func (c *Cluster) TotalMemory() int64 { | |
> nodes, err := c.kubeClient.Nodes().List(labels.Everything(), fields.Everything()) | |
> if err != nil { | |
> log.Error(err) | |
> return 0 | |
> } | |
> | |
> total := int64(0) | |
> for _, node := range nodes.Items { | |
> total += node.Status.Capacity.Memory().Value() | |
> } | |
> return total | |
> } | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment