Add support for Config, endpoint_mode and 3.3 support (#994)

* Add support for Config

* Add deployment endpoint_mode support

* Add docker compose 3.3 support

* Add compose v3.3 support for openshift
This commit is contained in:
Xianlu Bird
2018-08-01 15:09:00 -04:00
committed by Charlie Drage
parent 0c01309fe8
commit 0252213efb
24 changed files with 1117 additions and 16 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
}
return komposeObject, nil
// Use docker/cli for 3
case "3", "3.0", "3.1", "3.2":
case "3", "3.0", "3.1", "3.2", "3.3":
komposeObject, err := parseV3(files)
if err != nil {
return kobject.KomposeObject{}, err
+49 -2
View File
@@ -119,8 +119,10 @@ func parseV3(files []string) (kobject.KomposeObject, error) {
}
}
// TODO: Check all "unsupported" keys and output details
// Specifically, keys such as "volumes_from" are not supported in V3.
noSupKeys := checkUnsupportedKeyForV3(config)
for _, keyName := range noSupKeys {
log.Warningf("Unsupported %s key - ignoring", keyName)
}
// Finally, we convert the object from docker/cli's ServiceConfig to our appropriate one
komposeObject, err := dockerComposeToKomposeMapping(config)
@@ -350,6 +352,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
serviceConfig.Build = composeServiceConfig.Build.Context
serviceConfig.Dockerfile = composeServiceConfig.Build.Dockerfile
serviceConfig.BuildArgs = composeServiceConfig.Build.Args
serviceConfig.BuildLabels = composeServiceConfig.Build.Labels
// Gather the environment values
// DockerCompose uses map[string]*string while we use []string
@@ -411,9 +414,15 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name))
}
serviceConfig.Configs = composeServiceConfig.Configs
serviceConfig.ConfigsMetaData = composeObject.Configs
if composeServiceConfig.Deploy.EndpointMode == "vip" {
serviceConfig.ServiceType = string(api.ServiceTypeNodePort)
}
// Final step, add to the array!
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
}
handleVolume(&komposeObject)
return komposeObject, nil
@@ -580,3 +589,41 @@ func mergeComposeObject(oldCompose *types.Config, newCompose *types.Config) (*ty
return oldCompose, nil
}
func checkUnsupportedKeyForV3(composeObject *types.Config) []string {
if composeObject == nil {
return []string{}
}
var keysFound []string
for _, service := range composeObject.Services {
//For short syntax, volume mount path must be /, but this will cause pod create fail in kubernetes
//So we ignore this attribute
for _, tmpConfig := range service.Configs {
if tmpConfig.Mode == nil {
keysFound = append(keysFound, "short syntax config")
} else {
if tmpConfig.GID != "" {
keysFound = append(keysFound, "long syntax config gid")
}
if tmpConfig.UID != "" {
keysFound = append(keysFound, "long syntax config uid")
}
}
}
if service.CredentialSpec.Registry != "" || service.CredentialSpec.File != "" {
keysFound = append(keysFound, "credential_spec")
}
}
for _, config := range composeObject.Configs {
if config.External.External {
keysFound = append(keysFound, "external config")
}
}
return keysFound
}