Generic service type handler for kompose

Moved label handling code from Transformer to loader,
to make it generic to handle creating service types.

Added new attribute to ServiceConfig which gets populated
in loader.

Fixes #273
This commit is contained in:
Suraj Deshmukh
2016-11-16 22:01:01 +05:30
parent 83c7a824dc
commit bb9e4fba61
5 changed files with 72 additions and 77 deletions
+24
View File
@@ -207,6 +207,16 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
}
}
// canonical "Custom Labels" handler
// Labels used to influence conversion of kompose will be handled
// from here for docker-compose. Each loader will have such handler.
for key, value := range composeServiceConfig.Labels {
switch key {
case "kompose.service.type":
serviceConfig.ServiceType = handleServiceType(value)
}
}
// convert compose labels to annotations
serviceConfig.Annotations = map[string]string(composeServiceConfig.Labels)
@@ -227,3 +237,17 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
return komposeObject
}
func handleServiceType(ServiceType string) string {
switch strings.ToLower(ServiceType) {
case "", "clusterip":
return string(api.ServiceTypeClusterIP)
case "nodeport":
return string(api.ServiceTypeNodePort)
case "loadbalancer":
return string(api.ServiceTypeLoadBalancer)
default:
logrus.Fatalf("Unknown value '%s', supported values are 'NodePort, ClusterIP or LoadBalancer'", ServiceType)
return ""
}
}