Skip to content

Commit

Permalink
add labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tonicmuroq committed Jun 24, 2016
1 parent 0c12d20 commit 7f64f6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
24 changes: 22 additions & 2 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ func (c *Calcium) makeContainerOptions(quota map[string]int, specs types.Specs,
capAdd = append(capAdd, "SYS_ADMIN")
}

// labels
// basic labels, and set meta in specs to labels
containerLabels := map[string]string{
"Appname": opts.Appname,
"Version": utils.GetVersion(opts.Image),
"Image": opts.Image,
"Podname": opts.Podname,
"Nodename": opts.Nodename,
"Entrypoint": opts.Entrypoint,
}
for key, value := range specs.Meta {
containerLabels[key] = value
}

// ulimit
ulimits := []*units.Ulimit{&units.Ulimit{Name: "nofile", Soft: 65535, Hard: 65535}}

Expand All @@ -324,7 +338,7 @@ func (c *Calcium) makeContainerOptions(quota map[string]int, specs types.Specs,
Volumes: volumes,
WorkingDir: workingDir,
NetworkDisabled: false,
Labels: make(map[string]string),
Labels: containerLabels,
}
hostConfig := &enginecontainer.HostConfig{
Binds: binds,
Expand Down Expand Up @@ -419,6 +433,11 @@ func (c *Calcium) doUpgradeContainer(containers []*types.Container, image string
continue
}

// have to put it here because later we'll call `makeContainerConfig`
// which will override this
// TODO in the future I hope `makeContainerConfig` will make a deep copy of config
imageToDelete := info.Config.Image

// stops the old container
timeout := 5 * time.Second
err = engine.ContainerStop(context.Background(), info.ID, &timeout)
Expand Down Expand Up @@ -478,7 +497,7 @@ func (c *Calcium) doUpgradeContainer(containers []*types.Container, image string
continue
}

imagesToDelete[info.Image] = struct{}{}
imagesToDelete[imageToDelete] = struct{}{}

// remove the old container in etcd
err = c.store.RemoveContainer(info.ID)
Expand All @@ -501,6 +520,7 @@ func (c *Calcium) doUpgradeContainer(containers []*types.Container, image string
PruneChildren: true,
}
for image, _ := range imagesToDelete {
log.Debugf("Try to remove image %q while upgrade container", image)
engine.ImageRemove(context.Background(), image, rmiOpts)
}
}()
Expand Down
15 changes: 14 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,18 @@ func GetGitRepoName(url string) (string, error) {
if len(y) != 2 {
return "", fmt.Errorf("Bad git url format %q", url)
}
return y[1][:len(y[1])-4], nil
return strings.TrimSuffix(y[1], ".git"), nil
}

func GetVersion(image string) string {
if !strings.Contains(image, ":") {
return "unknown"
}

parts := strings.Split(image, ":")
if len(parts) != 2 {
return "unknown"
}

return parts[1]
}

0 comments on commit 7f64f6d

Please sign in to comment.