Skip to content

Commit

Permalink
Merge pull request #1084 from thaJeztah/minor-code-refactor
Browse files Browse the repository at this point in the history
Minor refactor in stack helper functions
  • Loading branch information
Vincent Demeester authored May 28, 2018
2 parents 8205323 + 0c175fc commit 537e67d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
42 changes: 9 additions & 33 deletions cli/command/stack/swarm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getStackFilter(namespace string) filters.Args {
return filter
}

func getServiceFilter(namespace string) filters.Args {
func getStackServiceFilter(namespace string) filters.Args {
return getStackFilter(namespace)
}

Expand All @@ -33,42 +33,18 @@ func getAllStacksFilter() filters.Args {
return filter
}

func getServices(
ctx context.Context,
apiclient client.APIClient,
namespace string,
) ([]swarm.Service, error) {
return apiclient.ServiceList(
ctx,
types.ServiceListOptions{Filters: getServiceFilter(namespace)})
func getStackServices(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Service, error) {
return apiclient.ServiceList(ctx, types.ServiceListOptions{Filters: getStackServiceFilter(namespace)})
}

func getStackNetworks(
ctx context.Context,
apiclient client.APIClient,
namespace string,
) ([]types.NetworkResource, error) {
return apiclient.NetworkList(
ctx,
types.NetworkListOptions{Filters: getStackFilter(namespace)})
func getStackNetworks(ctx context.Context, apiclient client.APIClient, namespace string) ([]types.NetworkResource, error) {
return apiclient.NetworkList(ctx, types.NetworkListOptions{Filters: getStackFilter(namespace)})
}

func getStackSecrets(
ctx context.Context,
apiclient client.APIClient,
namespace string,
) ([]swarm.Secret, error) {
return apiclient.SecretList(
ctx,
types.SecretListOptions{Filters: getStackFilter(namespace)})
func getStackSecrets(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Secret, error) {
return apiclient.SecretList(ctx, types.SecretListOptions{Filters: getStackFilter(namespace)})
}

func getStackConfigs(
ctx context.Context,
apiclient client.APIClient,
namespace string,
) ([]swarm.Config, error) {
return apiclient.ConfigList(
ctx,
types.ConfigListOptions{Filters: getStackFilter(namespace)})
func getStackConfigs(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Config, error) {
return apiclient.ConfigList(ctx, types.ConfigListOptions{Filters: getStackFilter(namespace)})
}
2 changes: 1 addition & 1 deletion cli/command/stack/swarm/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error
func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert.Namespace, services map[string]struct{}) {
client := dockerCli.Client()

oldServices, err := getServices(ctx, client, namespace.Name())
oldServices, err := getStackServices(ctx, client, namespace.Name())
if err != nil {
fmt.Fprintf(dockerCli.Err(), "Failed to list services: %s\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/swarm/deploy_composefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func deployServices(
apiClient := dockerCli.Client()
out := dockerCli.Out()

existingServices, err := getServices(ctx, apiClient, namespace.Name())
existingServices, err := getStackServices(ctx, apiClient, namespace.Name())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/swarm/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func RunRemove(dockerCli command.Cli, opts options.Remove) error {

var errs []string
for _, namespace := range namespaces {
services, err := getServices(ctx, client, namespace)
services, err := getStackServices(ctx, client, namespace)
if err != nil {
return err
}
Expand Down

0 comments on commit 537e67d

Please sign in to comment.