mirror of https://github.com/docker/cli.git
Fix stack marshaling for Kubernetes
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
e34ca9740e
commit
9b27e92903
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue