support both endpoint modes in stack

Signed-off-by: allencloud <allen.sun@daocloud.io>
Upstream-commit: cd1cde6e77
Component: cli
This commit is contained in:
allencloud
2017-03-13 15:00:49 -04:00
committed by Daniel Nephin
parent 19021e1a48
commit a4dea23f9c
3 changed files with 10 additions and 4 deletions
+7 -3
View File
@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"sort" "sort"
"strings"
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
@@ -54,7 +55,7 @@ func convertService(
) (swarm.ServiceSpec, error) { ) (swarm.ServiceSpec, error) {
name := namespace.Scope(service.Name) name := namespace.Scope(service.Name)
endpoint, err := convertEndpointSpec(service.Ports) endpoint, err := convertEndpointSpec(service.EndpointMode, service.Ports)
if err != nil { if err != nil {
return swarm.ServiceSpec{}, err return swarm.ServiceSpec{}, err
} }
@@ -374,7 +375,7 @@ func (a byPublishedPort) Len() int { return len(a) }
func (a byPublishedPort) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a byPublishedPort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byPublishedPort) Less(i, j int) bool { return a[i].PublishedPort < a[j].PublishedPort } func (a byPublishedPort) Less(i, j int) bool { return a[i].PublishedPort < a[j].PublishedPort }
func convertEndpointSpec(source []composetypes.ServicePortConfig) (*swarm.EndpointSpec, error) { func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) (*swarm.EndpointSpec, error) {
portConfigs := []swarm.PortConfig{} portConfigs := []swarm.PortConfig{}
for _, port := range source { for _, port := range source {
portConfig := swarm.PortConfig{ portConfig := swarm.PortConfig{
@@ -387,7 +388,10 @@ func convertEndpointSpec(source []composetypes.ServicePortConfig) (*swarm.Endpoi
} }
sort.Sort(byPublishedPort(portConfigs)) sort.Sort(byPublishedPort(portConfigs))
return &swarm.EndpointSpec{Ports: portConfigs}, nil return &swarm.EndpointSpec{
Mode: swarm.ResolutionMode(strings.ToLower(endpointMode)),
Ports: portConfigs,
}, nil
} }
func convertEnvironment(source map[string]string) []string { func convertEnvironment(source map[string]string) []string {
@@ -156,9 +156,10 @@ func TestConvertEndpointSpec(t *testing.T) {
Published: 80, Published: 80,
}, },
} }
endpoint, err := convertEndpointSpec(source) endpoint, err := convertEndpointSpec("vip", source)
expected := swarm.EndpointSpec{ expected := swarm.EndpointSpec{
Mode: swarm.ResolutionMode(strings.ToLower("vip")),
Ports: []swarm.PortConfig{ Ports: []swarm.PortConfig{
{ {
TargetPort: 8080, TargetPort: 8080,
+1
View File
@@ -89,6 +89,7 @@ type ServiceConfig struct {
DNS StringList DNS StringList
DNSSearch StringList `mapstructure:"dns_search"` DNSSearch StringList `mapstructure:"dns_search"`
DomainName string `mapstructure:"domainname"` DomainName string `mapstructure:"domainname"`
EndpointMode string
Entrypoint ShellCommand Entrypoint ShellCommand
Environment MappingWithEquals Environment MappingWithEquals
EnvFile StringList `mapstructure:"env_file"` EnvFile StringList `mapstructure:"env_file"`