fix: filtering requires case-by-case handling
See https://github.com/moby/moby/issues/32985.
This commit is contained in:
parent
e8e41850b5
commit
323f4467c8
|
@ -30,7 +30,7 @@ var logOpts = types.ContainerLogsOptions{
|
||||||
|
|
||||||
// stackLogs lists logs for all stack services
|
// stackLogs lists logs for all stack services
|
||||||
func stackLogs(c *cli.Context, app config.App, client *dockerClient.Client) {
|
func stackLogs(c *cli.Context, app config.App, client *dockerClient.Client) {
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ var appPsCommand = cli.Command{
|
||||||
|
|
||||||
// showPSOutput renders ps output.
|
// showPSOutput renders ps output.
|
||||||
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ var appRemoveCommand = cli.Command{
|
||||||
logrus.Fatalf("%s is still deployed. Run \"abra app undeploy %s\"", app.Name, app.Name)
|
logrus.Fatalf("%s is still deployed. Run \"abra app undeploy %s\"", app.Name, app.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs, err := app.Filters()
|
fs, err := app.Filters(false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,11 @@ var appRemoveCommand = cli.Command{
|
||||||
logrus.Info("no secrets to remove")
|
logrus.Info("no secrets to remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs, err = app.Filters(false, true)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
volumeListOKBody, err := cl.VolumeList(context.Background(), fs)
|
volumeListOKBody, err := cl.VolumeList(context.Background(), fs)
|
||||||
volumeList := volumeListOKBody.Volumes
|
volumeList := volumeListOKBody.Volumes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -216,7 +216,7 @@ Example:
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ var appSecretLsCommand = cli.Command{
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ var appVolumeListCommand = cli.Command{
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ Passing "--force/-f" will select all volumes for removal. Be careful.
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
filters, err := app.Filters()
|
filters, err := app.Filters(false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,13 @@ func (a App) StackName() string {
|
||||||
return stackName
|
return stackName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters retrieves exact app filters for querying the container runtime.
|
// Filters retrieves exact app filters for querying the container runtime. Due
|
||||||
func (a App) Filters() (filters.Args, error) {
|
// to upstream issues, filtering works different depending on what you're
|
||||||
|
// querying. So, for example, secrets don't work with regex! The caller needs
|
||||||
|
// to implement their own validation that the right secrets are matched. In
|
||||||
|
// order to handle these cases, we provide the `appendServiceNames` /
|
||||||
|
// `exactMatch` modifiers.
|
||||||
|
func (a App) Filters(appendServiceNames, exactMatch bool) (filters.Args, error) {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
composeFiles, err := GetAppComposeFiles(a.Recipe, a.Env)
|
composeFiles, err := GetAppComposeFiles(a.Recipe, a.Env)
|
||||||
|
@ -80,7 +85,22 @@ func (a App) Filters() (filters.Args, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range compose.Services {
|
for _, service := range compose.Services {
|
||||||
filter := fmt.Sprintf("^%s_%s", a.StackName(), service.Name)
|
var filter string
|
||||||
|
|
||||||
|
if appendServiceNames {
|
||||||
|
if exactMatch {
|
||||||
|
filter = fmt.Sprintf("^%s_%s", a.StackName(), service.Name)
|
||||||
|
} else {
|
||||||
|
filter = fmt.Sprintf("%s_%s", a.StackName(), service.Name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if exactMatch {
|
||||||
|
filter = fmt.Sprintf("^%s", a.StackName())
|
||||||
|
} else {
|
||||||
|
filter = fmt.Sprintf("%s", a.StackName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filters.Add("name", filter)
|
filters.Add("name", filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue