Skip to content

Commit b89b3d3

Browse files
committed
common: Move container type into separate package
Also: Including an entire package just to retrieve the definition of the ContainerName label is pointless as it will never ever change again. Size reduction: cilium 27M => 17M cilium-agent 37M => 37M cilium-docker 26M => 16M cilium-cni 26M => 16M Signed-off-by: Thomas Graf <thomas@cilium.io>
1 parent 5f67496 commit b89b3d3

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

NEWS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Features
1414
--------
1515

1616
- Improved logging readability (`GH #499 <https://github.com/cilium/cilium/pull/499>`_)
17+
- Reduced size of cilium binary from 27M to 17M
1718

1819
0.8.0
1920
=====

daemon/daemon.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/cilium/cilium/daemon/options"
3737
"github.com/cilium/cilium/pkg/apierror"
3838
"github.com/cilium/cilium/pkg/bpf"
39+
"github.com/cilium/cilium/pkg/container"
3940
"github.com/cilium/cilium/pkg/endpoint"
4041
"github.com/cilium/cilium/pkg/events"
4142
"github.com/cilium/cilium/pkg/kvstore"
@@ -63,7 +64,7 @@ import (
6364
type Daemon struct {
6465
ipamConf *ipam.IPAMConfig
6566
kvClient kvstore.KVClient
66-
containers map[string]*types.Container
67+
containers map[string]*container.Container
6768
containersMU sync.RWMutex
6869
endpoints map[uint16]*endpoint.Endpoint
6970
endpointsAux map[string]*endpoint.Endpoint
@@ -488,7 +489,7 @@ func NewDaemon(c *Config) (*Daemon, error) {
488489
conf: c,
489490
kvClient: kvClient,
490491
dockerClient: dockerClient,
491-
containers: make(map[string]*types.Container),
492+
containers: make(map[string]*container.Container),
492493
endpoints: make(map[uint16]*endpoint.Endpoint),
493494
endpointsAux: make(map[string]*endpoint.Endpoint),
494495
events: make(chan events.Event, 512),

daemon/docker_watcher.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/cilium/cilium/common"
2828
"github.com/cilium/cilium/common/addressing"
29-
"github.com/cilium/cilium/common/types"
29+
"github.com/cilium/cilium/pkg/container"
3030
"github.com/cilium/cilium/pkg/endpoint"
3131
"github.com/cilium/cilium/pkg/labels"
3232
"github.com/cilium/cilium/pkg/policy"
@@ -205,18 +205,18 @@ func (d *Daemon) getFilteredLabels(allLabels map[string]string) labels.Labels {
205205
return normalLabels
206206
}
207207

208-
func (d *Daemon) retrieveWorkingContainerCopy(id string) (types.Container, bool) {
208+
func (d *Daemon) retrieveWorkingContainerCopy(id string) (container.Container, bool) {
209209
d.containersMU.RLock()
210210
defer d.containersMU.RUnlock()
211211

212212
if c, ok := d.containers[id]; ok {
213213
return *c, true
214214
}
215-
return types.Container{}, false
215+
return container.Container{}, false
216216
}
217217

218-
func createContainer(dc *dTypes.ContainerJSON, l labels.Labels) types.Container {
219-
return types.Container{
218+
func createContainer(dc *dTypes.ContainerJSON, l labels.Labels) container.Container {
219+
return container.Container{
220220
ContainerJSON: *dc,
221221
OpLabels: labels.OpLabels{
222222
Custom: labels.Labels{},
@@ -362,7 +362,7 @@ func (d *Daemon) retrieveDockerLabels(dockerID string) (*dTypes.ContainerJSON, l
362362
return &dockerCont, newLabels, nil
363363
}
364364

365-
func updateOrchLabels(c *types.Container, l labels.Labels) bool {
365+
func updateOrchLabels(c *container.Container, l labels.Labels) bool {
366366
changed := false
367367

368368
c.OpLabels.Orchestration.MarkAllForDeletion()

daemon/labels.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
. "github.com/cilium/cilium/api/v1/server/restapi/policy"
2525
"github.com/cilium/cilium/common"
26-
"github.com/cilium/cilium/common/types"
2726
"github.com/cilium/cilium/pkg/apierror"
27+
"github.com/cilium/cilium/pkg/container"
2828
"github.com/cilium/cilium/pkg/events"
2929
"github.com/cilium/cilium/pkg/labels"
3030
"github.com/cilium/cilium/pkg/policy"
@@ -141,7 +141,7 @@ func (d *Daemon) CreateOrUpdateIdentity(lbls labels.Labels, epid string) (*polic
141141
return identity, isNew, nil
142142
}
143143

144-
func (d *Daemon) updateContainerIdentity(container *types.Container) (*policy.Identity, error) {
144+
func (d *Daemon) updateContainerIdentity(container *container.Container) (*policy.Identity, error) {
145145
lbls := container.OpLabels.Enabled()
146146
log.Debugf("Container %s is resolving identity for labels %+v", container.ID, lbls)
147147

common/types/container.go pkg/container/container.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package types
15+
package container
1616

1717
import (
1818
"github.com/cilium/cilium/pkg/labels"
1919

2020
dTypes "github.com/docker/engine-api/types"
21-
k8sDockerLbls "k8s.io/client-go/1.5/pkg/kubelet/types"
21+
)
22+
23+
const (
24+
// KubernetesContainerNameLabel is the name of the pod label carrying
25+
// the name of the container
26+
KubernetesContainerNameLabel = "io.kubernetes.container.name"
2227
)
2328

2429
type Container struct {
@@ -29,7 +34,7 @@ type Container struct {
2934

3035
func (c *Container) IsDockerOrInfracontainer() bool {
3136
if c.Config != nil {
32-
contName, exists := c.Config.Labels[k8sDockerLbls.KubernetesContainerNameLabel]
37+
contName, exists := c.Config.Labels[KubernetesContainerNameLabel]
3338
return !exists || contName == "POD"
3439
}
3540
return false

0 commit comments

Comments
 (0)