forked from LaconicNetwork/kompose
Merge pull request #84 from janetkuo/labels-to-annotations
Converting compose labels to k8s annotations
This commit is contained in:
commit
c4d62c99ee
@ -785,7 +785,8 @@ func loadBundlesFile(file string, opt convertOptions) KomposeObject {
|
|||||||
serviceConfig := ServiceConfig{}
|
serviceConfig := ServiceConfig{}
|
||||||
serviceConfig.Command = service.Command
|
serviceConfig.Command = service.Command
|
||||||
serviceConfig.Args = service.Args
|
serviceConfig.Args = service.Args
|
||||||
serviceConfig.Labels = service.Labels
|
// convert bundle labels to annotations
|
||||||
|
serviceConfig.Annotations = service.Labels
|
||||||
|
|
||||||
image, err := loadImage(service)
|
image, err := loadImage(service)
|
||||||
if err != "" {
|
if err != "" {
|
||||||
@ -874,14 +875,8 @@ func loadComposeFile(file string, opt convertOptions) KomposeObject {
|
|||||||
serviceConfig.WorkingDir = composeServiceConfig.WorkingDir
|
serviceConfig.WorkingDir = composeServiceConfig.WorkingDir
|
||||||
serviceConfig.Volumes = composeServiceConfig.Volumes
|
serviceConfig.Volumes = composeServiceConfig.Volumes
|
||||||
|
|
||||||
// load labels
|
// convert compose labels to annotations
|
||||||
labels := composeServiceConfig.Labels
|
serviceConfig.Annotations = map[string]string(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
|
|
||||||
|
|
||||||
serviceConfig.CPUSet = composeServiceConfig.CPUSet
|
serviceConfig.CPUSet = composeServiceConfig.CPUSet
|
||||||
serviceConfig.CPUShares = composeServiceConfig.CPUShares
|
serviceConfig.CPUShares = composeServiceConfig.CPUShares
|
||||||
@ -952,12 +947,15 @@ func komposeConvert(komposeObject KomposeObject, opt convertOptions) {
|
|||||||
servicePorts := configServicePorts(name, service)
|
servicePorts := configServicePorts(name, service)
|
||||||
sc.Spec.Ports = servicePorts
|
sc.Spec.Ports = servicePorts
|
||||||
|
|
||||||
// Configure label
|
// Configure labels
|
||||||
labels := map[string]string{"service": name}
|
labels := map[string]string{"service": name}
|
||||||
for key, value := range service.Labels {
|
|
||||||
labels[key] = value
|
|
||||||
}
|
|
||||||
sc.ObjectMeta.Labels = labels
|
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 fills the pod template with the value calculated from config
|
||||||
fillTemplate := func(template *api.PodTemplateSpec) {
|
fillTemplate := func(template *api.PodTemplateSpec) {
|
||||||
@ -990,6 +988,7 @@ func komposeConvert(komposeObject KomposeObject, opt convertOptions) {
|
|||||||
// fillObjectMeta fills the metadata with the value calculated from config
|
// fillObjectMeta fills the metadata with the value calculated from config
|
||||||
fillObjectMeta := func(meta *api.ObjectMeta) {
|
fillObjectMeta := func(meta *api.ObjectMeta) {
|
||||||
meta.Labels = labels
|
meta.Labels = labels
|
||||||
|
meta.Annotations = annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update each supported controllers
|
// Update each supported controllers
|
||||||
|
|||||||
@ -33,6 +33,7 @@ type ServiceConfig struct {
|
|||||||
Volumes []string
|
Volumes []string
|
||||||
Network []string
|
Network []string
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
|
Annotations map[string]string
|
||||||
CPUSet string
|
CPUSet string
|
||||||
CPUShares int64
|
CPUShares int64
|
||||||
CPUQuota int64
|
CPUQuota int64
|
||||||
|
|||||||
@ -4,6 +4,8 @@ services:
|
|||||||
vote:
|
vote:
|
||||||
build: ./vote
|
build: ./vote
|
||||||
command: python app.py
|
command: python app.py
|
||||||
|
labels:
|
||||||
|
- "com.example.description=Vote"
|
||||||
volumes:
|
volumes:
|
||||||
- ./vote:/app
|
- ./vote:/app
|
||||||
ports:
|
ports:
|
||||||
@ -18,6 +20,8 @@ services:
|
|||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:9.4
|
image: postgres:9.4
|
||||||
|
labels:
|
||||||
|
- "com.example.description=Postgres Database"
|
||||||
|
|
||||||
result:
|
result:
|
||||||
build: ./result
|
build: ./result
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user