Skip to content

Commit

Permalink
Merge pull request #84 from janetkuo/labels-to-annotations
Browse files Browse the repository at this point in the history
Converting compose labels to k8s annotations
  • Loading branch information
ngtuna authored Aug 4, 2016
2 parents 4cf1875 + b71b70e commit c4d62c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cli/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ func loadBundlesFile(file string, opt convertOptions) KomposeObject {
serviceConfig := ServiceConfig{}
serviceConfig.Command = service.Command
serviceConfig.Args = service.Args
serviceConfig.Labels = service.Labels
// convert bundle labels to annotations
serviceConfig.Annotations = service.Labels

image, err := loadImage(service)
if err != "" {
Expand Down Expand Up @@ -874,14 +875,8 @@ func loadComposeFile(file string, opt convertOptions) KomposeObject {
serviceConfig.WorkingDir = composeServiceConfig.WorkingDir
serviceConfig.Volumes = composeServiceConfig.Volumes

// load labels
labels := composeServiceConfig.Labels
if labels != nil {
if err := labels.UnmarshalYAML("", labels); err != nil {
logrus.Fatalf("Failed to load labels from compose file: %v", err)
}
}
serviceConfig.Labels = labels
// convert compose labels to annotations
serviceConfig.Annotations = map[string]string(composeServiceConfig.Labels)

serviceConfig.CPUSet = composeServiceConfig.CPUSet
serviceConfig.CPUShares = composeServiceConfig.CPUShares
Expand Down Expand Up @@ -952,12 +947,15 @@ func komposeConvert(komposeObject KomposeObject, opt convertOptions) {
servicePorts := configServicePorts(name, service)
sc.Spec.Ports = servicePorts

// Configure label
// Configure labels
labels := map[string]string{"service": name}
for key, value := range service.Labels {
labels[key] = value
}
sc.ObjectMeta.Labels = labels
// Configure annotations
annotations := map[string]string{}
for key, value := range service.Annotations {
annotations[key] = value
}
sc.ObjectMeta.Annotations = annotations

// fillTemplate fills the pod template with the value calculated from config
fillTemplate := func(template *api.PodTemplateSpec) {
Expand Down Expand Up @@ -990,6 +988,7 @@ func komposeConvert(komposeObject KomposeObject, opt convertOptions) {
// fillObjectMeta fills the metadata with the value calculated from config
fillObjectMeta := func(meta *api.ObjectMeta) {
meta.Labels = labels
meta.Annotations = annotations
}

// Update each supported controllers
Expand Down
1 change: 1 addition & 0 deletions cli/app/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ServiceConfig struct {
Volumes []string
Network []string
Labels map[string]string
Annotations map[string]string
CPUSet string
CPUShares int64
CPUQuota int64
Expand Down
4 changes: 4 additions & 0 deletions examples/docker-voting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
vote:
build: ./vote
command: python app.py
labels:
- "com.example.description=Vote"
volumes:
- ./vote:/app
ports:
Expand All @@ -18,6 +20,8 @@ services:

db:
image: postgres:9.4
labels:
- "com.example.description=Postgres Database"

result:
build: ./result
Expand Down

0 comments on commit c4d62c9

Please sign in to comment.