Make sure we marshall version too…#891
Conversation
Codecov Report
@@ Coverage Diff @@
## master #891 +/- ##
==========================================
+ Coverage 53.21% 53.23% +0.02%
==========================================
Files 258 258
Lines 16346 16349 +3
==========================================
+ Hits 8698 8704 +6
+ Misses 7083 7080 -3
Partials 565 565 |
| Version string | ||
| } | ||
|
|
||
| func (c versionedConfig) MarshalYAML() (interface{}, error) { |
There was a problem hiding this comment.
I think the problem is that composetypes.Config is being used as an embeded struct, and it has a MarshalYAML so that is what is called when this versionedConfig struct is marshalled.
How about:
diff --git a/cli/command/stack/kubernetes/loader.go b/cli/command/stack/kubernetes/loader.go
index 14aec58914..66a4071792 100644
--- a/cli/command/stack/kubernetes/loader.go
+++ b/cli/command/stack/kubernetes/loader.go
@@ -8,17 +8,26 @@ import (
)
type versionedConfig struct {
- *composetypes.Config `yaml:",inline"`
- Version string
+ composetypes.Config
+ Version string
}
+// MarshalYAML makes Config implement yaml.Marshaller
func (c versionedConfig) MarshalYAML() (interface{}, error) {
- i, err := c.Config.MarshalYAML()
- if err != nil {
- return nil, err
+ m := map[string]interface{}{}
+ services := map[string]composetypes.ServiceConfig{}
+ for _, service := range c.Services {
+ s := service
+ s.Name = ""
+ services[service.Name] = s
}
- i.(map[string]interface{})["version"] = c.Version
- return i, nil
+ m["services"] = services
+ m["networks"] = c.Networks
+ m["volumes"] = c.Volumes
+ m["secrets"] = c.Secrets
+ m["configs"] = c.Configs
+ m["version"] = c.Version
+ return m, nil
}
// LoadStack loads a stack from a Compose config, with a given name.
@@ -26,7 +35,7 @@ func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack
cfg.Filename = ""
res, err := yaml.Marshal(versionedConfig{
Version: version,
- Config: &cfg,
+ Config: cfg,
})
if err != nil {
return nil, err
diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go
index 2299871cfb..37ec1b5dd7 100644
--- a/cli/compose/types/types.go
+++ b/cli/compose/types/types.go
@@ -78,23 +78,6 @@ type Config struct {
Configs map[string]ConfigObjConfig
}
-// MarshalYAML makes Config implement yaml.Marshaller
-func (c *Config) MarshalYAML() (interface{}, error) {
- m := map[string]interface{}{}
- services := map[string]ServiceConfig{}
- for _, service := range c.Services {
- s := service
- s.Name = ""
- services[service.Name] = s
- }
- m["services"] = services
- m["networks"] = c.Networks
- m["volumes"] = c.Volumes
- m["secrets"] = c.Secrets
- m["configs"] = c.Configs
- return m, nil
-}
-
// ServiceConfig is the configuration of one service
type ServiceConfig struct {
Name string `yaml:",omitempty"`There was a problem hiding this comment.
Or we could make a type for Config.Services that has the MarshalYAML on it, add a yaml:"-" to Config.Filename, and then we should be able to just use inline here.
568167e to
4a1df95
Compare
| m := map[string]interface{}{} | ||
| services := map[string]composetypes.ServiceConfig{} | ||
| for _, service := range c.Services { | ||
| s := service |
There was a problem hiding this comment.
Why do you copy service here?
| s := service | ||
| services[service.Name] = s | ||
| } | ||
| m["services"] = services |
There was a problem hiding this comment.
return map[string]interface{}{
"networks": c.Networks,
"volumes": c.Volumes,
...
}, nil4a1df95 to
68267e5
Compare
… 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>
68267e5 to
9f9f1c8
Compare
| version string | ||
| } | ||
|
|
||
| func (c versionedConfig) MarshalYAML() (interface{}, error) { |
There was a problem hiding this comment.
I think we'll be able to remove these MarshalYAML in the future by making Config.Services a type with a MarshalYAML.
…rsion Make sure we marshall version too… Upstream-commit: 939938b Component: cli


… 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