Pārlūkot izejas kodu

Specific error message when user tries to remove one container from an ACI compose application, mentioning the name of the compose application and that user should use compose down

Guillaume Tardif 5 gadi atpakaļ
vecāks
revīzija
6b74716490
3 mainītis faili ar 16 papildinājumiem un 2 dzēšanām
  1. 5 1
      azure/backend.go
  2. 9 0
      azure/backend_test.go
  3. 2 1
      example/backend.go

+ 5 - 1
azure/backend.go

@@ -258,7 +258,11 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r
 }
 
 func (cs *aciContainerService) Delete(ctx context.Context, containerID string, _ bool) error {
-	cg, err := deleteACIContainerGroup(ctx, cs.ctx, containerID)
+	groupName, containerName := getGroupAndContainerName(containerID)
+	if groupName != containerID {
+		return errors.New(fmt.Sprintf(`cannot delete service "%s" from compose app "%s", you must delete the entire compose app with docker compose down`, containerName, groupName))
+	}
+	cg, err := deleteACIContainerGroup(ctx, cs.ctx, groupName)
 	if err != nil {
 		return err
 	}

+ 9 - 0
azure/backend_test.go

@@ -17,6 +17,7 @@
 package azure
 
 import (
+	"context"
 	"testing"
 
 	"github.com/stretchr/testify/suite"
@@ -42,6 +43,14 @@ func (suite *BackendSuiteTest) TestGetContainerName() {
 	Expect(container).To(Equal("service1"))
 }
 
+func (suite *BackendSuiteTest) TestErrorMessageDeletingContainerFromComposeApplication() {
+	service := aciContainerService{}
+	err := service.Delete(context.TODO(), "compose-app_service1", false)
+
+	Expect(err).NotTo(BeNil())
+	Expect(err.Error()).To(Equal("cannot delete service \"service1\" from compose app \"compose-app\", you must delete the entire compose app with docker compose down"))
+}
+
 func TestBackendSuite(t *testing.T) {
 	RegisterTestingT(t)
 	suite.Run(t, new(BackendSuiteTest))

+ 2 - 1
example/backend.go

@@ -22,9 +22,10 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"github.com/compose-spec/compose-go/cli"
 	"io"
 
+	"github.com/compose-spec/compose-go/cli"
+
 	"github.com/docker/api/context/cloud"
 
 	"github.com/docker/api/backend"