Make sure we marshall version too…

… otherwise the k8s controller might fail to parse the file as it will
think it's version 1.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2018-02-20 17:50:49 +01:00
parent bbe7f84540
commit 9f9f1c8515
3 changed files with 30 additions and 17 deletions

View File

@ -8,16 +8,30 @@ import (
)
type versionedConfig struct {
*composetypes.Config `yaml:",inline"`
Version string
composetypes.Config
version string
}
func (c versionedConfig) MarshalYAML() (interface{}, error) {
services := map[string]composetypes.ServiceConfig{}
for _, service := range c.Services {
services[service.Name] = service
}
return map[string]interface{}{
"services": services,
"networks": c.Networks,
"volumes": c.Volumes,
"secrets": c.Secrets,
"configs": c.Configs,
"version": c.version,
}, nil
}
// LoadStack loads a stack from a Compose config, with a given name.
func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack, error) {
cfg.Filename = ""
res, err := yaml.Marshal(versionedConfig{
Version: version,
Config: &cfg,
version: version,
Config: cfg,
})
if err != nil {
return nil, err

View File

@ -37,6 +37,7 @@ services:
image: bar
foo:
image: foo
version: "3.1"
volumes: {}
`),
},