forked from toolshed/abra
refactor: drop dead code and garden formatting
This commit is contained in:
parent
dc616fd3a0
commit
a8f30426ea
@ -2,14 +2,11 @@ package stack
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
abraClient "coopcloud.tech/abra/client"
|
abraClient "coopcloud.tech/abra/client"
|
||||||
"coopcloud.tech/abra/client/convert"
|
"coopcloud.tech/abra/client/convert"
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
"github.com/docker/cli/opts"
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
@ -21,6 +18,14 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Resolve image constants
|
||||||
|
const (
|
||||||
|
defaultNetworkDriver = "overlay"
|
||||||
|
ResolveImageAlways = "always"
|
||||||
|
ResolveImageChanged = "changed"
|
||||||
|
ResolveImageNever = "never"
|
||||||
|
)
|
||||||
|
|
||||||
type StackStatus struct {
|
type StackStatus struct {
|
||||||
Services []swarm.Service
|
Services []swarm.Service
|
||||||
Err error
|
Err error
|
||||||
@ -36,12 +41,6 @@ func getStackServiceFilter(namespace string) filters.Args {
|
|||||||
return getStackFilter(namespace)
|
return getStackFilter(namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
|
||||||
filter := opt.Value()
|
|
||||||
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
|
||||||
return filter
|
|
||||||
}
|
|
||||||
|
|
||||||
func getAllStacksFilter() filters.Args {
|
func getAllStacksFilter() filters.Args {
|
||||||
filter := filters.NewArgs()
|
filter := filters.NewArgs()
|
||||||
filter.Add("label", convert.LabelNamespace)
|
filter.Add("label", convert.LabelNamespace)
|
||||||
@ -93,21 +92,6 @@ func GetAllDeployedServices(contextName string) StackStatus {
|
|||||||
return StackStatus{services, nil}
|
return StackStatus{services, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateStackName checks if the provided string is a valid stack name (namespace).
|
|
||||||
// It currently only does a rudimentary check if the string is empty, or consists
|
|
||||||
// of only whitespace and quoting characters.
|
|
||||||
func validateStackName(namespace string) error {
|
|
||||||
v := strings.TrimFunc(namespace, quotesOrWhitespace)
|
|
||||||
if v == "" {
|
|
||||||
return fmt.Errorf("invalid stack name: %q", namespace)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func quotesOrWhitespace(r rune) bool {
|
|
||||||
return unicode.IsSpace(r) || r == '"' || r == '\''
|
|
||||||
}
|
|
||||||
|
|
||||||
// pruneServices removes services that are no longer referenced in the source
|
// pruneServices removes services that are no longer referenced in the source
|
||||||
func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace convert.Namespace, services map[string]struct{}) {
|
func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace convert.Namespace, services map[string]struct{}) {
|
||||||
oldServices, err := getStackServices(ctx, cl, namespace.Name())
|
oldServices, err := getStackServices(ctx, cl, namespace.Name())
|
||||||
@ -124,14 +108,6 @@ func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace conve
|
|||||||
removeServices(ctx, cl, pruneServices)
|
removeServices(ctx, cl, pruneServices)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve image constants
|
|
||||||
const (
|
|
||||||
defaultNetworkDriver = "overlay"
|
|
||||||
ResolveImageAlways = "always"
|
|
||||||
ResolveImageChanged = "changed"
|
|
||||||
ResolveImageNever = "never"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RunDeploy is the swarm implementation of docker stack deploy
|
// RunDeploy is the swarm implementation of docker stack deploy
|
||||||
func RunDeploy(cl *dockerclient.Client, opts Deploy, cfg *composetypes.Config) error {
|
func RunDeploy(cl *dockerclient.Client, opts Deploy, cfg *composetypes.Config) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -307,8 +283,13 @@ func createNetworks(ctx context.Context, cl *dockerclient.Client, namespace conv
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: gocyclo
|
func deployServices(
|
||||||
func deployServices(ctx context.Context, cl *dockerclient.Client, services map[string]swarm.ServiceSpec, namespace convert.Namespace, sendAuth bool, resolveImage string) error {
|
ctx context.Context,
|
||||||
|
cl *dockerclient.Client,
|
||||||
|
services map[string]swarm.ServiceSpec,
|
||||||
|
namespace convert.Namespace,
|
||||||
|
sendAuth bool,
|
||||||
|
resolveImage string) error {
|
||||||
existingServices, err := getStackServices(ctx, cl, namespace.Name())
|
existingServices, err := getStackServices(ctx, cl, namespace.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user