Merge pull request #890 from silvin-lubecki/fix-kube-stack-marshaling

Fix stack marshaling for Kubernetes
This commit is contained in:
Vincent Demeester 2018-02-20 16:50:45 +01:00 committed by GitHub
commit 7d41d18b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 5 deletions

View File

@ -26,7 +26,7 @@ func RunDeploy(dockerCli *KubeCli, opts options.Deploy) error {
if err != nil {
return err
}
stack, err := LoadStack(opts.Namespace, version, cfg)
stack, err := LoadStack(opts.Namespace, version, *cfg)
if err != nil {
return err
}

View File

@ -8,15 +8,16 @@ import (
)
type versionedConfig struct {
composetypes.Config
*composetypes.Config `yaml:",inline"`
Version string
}
// LoadStack loads a stack from a Compose config, with a given name.
func LoadStack(name, version string, cfg *composetypes.Config) (*apiv1beta1.Stack, error) {
func LoadStack(name, version string, cfg composetypes.Config) (*apiv1beta1.Stack, error) {
cfg.Filename = ""
res, err := yaml.Marshal(versionedConfig{
Version: version,
Config: *cfg,
Config: &cfg,
})
if err != nil {
return nil, err

View File

@ -0,0 +1,44 @@
package kubernetes
import (
"testing"
composetypes "github.com/docker/cli/cli/compose/types"
apiv1beta1 "github.com/docker/cli/kubernetes/compose/v1beta1"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestLoadStack(t *testing.T) {
s, err := LoadStack("foo", "3.1", composetypes.Config{
Filename: "banana",
Services: []composetypes.ServiceConfig{
{
Name: "foo",
Image: "foo",
},
{
Name: "bar",
Image: "bar",
},
},
})
require.NoError(t, err)
require.Equal(t, &apiv1beta1.Stack{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Spec: apiv1beta1.StackSpec{
ComposeFile: string(`configs: {}
networks: {}
secrets: {}
services:
bar:
image: bar
foo:
image: foo
volumes: {}
`),
},
}, s)
}