Attach appends Images and Containers.
(curEntity Entity)
| 112 | |
| 113 | // Attach appends Images and Containers. |
| 114 | func (c *Pod) Attach(curEntity Entity) error { |
| 115 | if err := c.validAttach(curEntity); err != nil { |
| 116 | return err |
| 117 | } |
| 118 | |
| 119 | for { |
| 120 | switch e := curEntity.(type) { |
| 121 | case *Image: |
| 122 | container, err := newDefaultContainer(e.name(), e.Source()) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | |
| 127 | err = container.Attach(e) |
| 128 | curEntity = container |
| 129 | break |
| 130 | case *Container: |
| 131 | c.containers = append(c.containers, e) |
| 132 | sort.Sort(c.containers) |
| 133 | return nil |
| 134 | default: |
| 135 | panic("Unexpected type") |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func (c *Pod) name() string { |
| 141 | return c.pod.ObjectMeta.Name |