Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31302 from dnephin/purge-orphaned-services
Add --prune to stack deploy
- Loading branch information
Showing
9 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package stack | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/swarm" | ||
"github.com/docker/docker/cli/compose/convert" | ||
"github.com/docker/docker/cli/internal/test" | ||
"github.com/docker/docker/client" | ||
"github.com/docker/docker/pkg/testutil/assert" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type fakeClient struct { | ||
client.Client | ||
serviceList []string | ||
removedIDs []string | ||
} | ||
|
||
func (cli *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { | ||
services := []swarm.Service{} | ||
for _, name := range cli.serviceList { | ||
services = append(services, swarm.Service{ | ||
ID: name, | ||
Spec: swarm.ServiceSpec{ | ||
Annotations: swarm.Annotations{Name: name}, | ||
}, | ||
}) | ||
} | ||
return services, nil | ||
} | ||
|
||
func (cli *fakeClient) ServiceRemove(ctx context.Context, serviceID string) error { | ||
cli.removedIDs = append(cli.removedIDs, serviceID) | ||
return nil | ||
} | ||
|
||
func TestPruneServices(t *testing.T) { | ||
ctx := context.Background() | ||
namespace := convert.NewNamespace("foo") | ||
services := map[string]struct{}{ | ||
"new": {}, | ||
"keep": {}, | ||
} | ||
client := &fakeClient{serviceList: []string{"foo_keep", "foo_remove"}} | ||
dockerCli := test.NewFakeCli(client, &bytes.Buffer{}) | ||
dockerCli.SetErr(&bytes.Buffer{}) | ||
|
||
pruneServices(ctx, dockerCli, namespace, services) | ||
|
||
assert.DeepEqual(t, client.removedIDs, []string{"foo_remove"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters