Ver código fonte

ignore error parsing container number label, just warn

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 3 anos atrás
pai
commit
19d6ca9c5d
1 arquivos alterados com 10 adições e 8 exclusões
  1. 10 8
      pkg/compose/convergence.go

+ 10 - 8
pkg/compose/convergence.go

@@ -226,10 +226,7 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
 		updated[i] = container
 	}
 
-	next, err := nextContainerNumber(containers)
-	if err != nil {
-		return err
-	}
+	next := nextContainerNumber(containers)
 	for i := 0; i < expected-actual; i++ {
 		// Scale UP
 		number := next + i
@@ -370,18 +367,23 @@ func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceD
 	return true, nil
 }
 
-func nextContainerNumber(containers []moby.Container) (int, error) {
+func nextContainerNumber(containers []moby.Container) int {
 	max := 0
 	for _, c := range containers {
-		n, err := strconv.Atoi(c.Labels[api.ContainerNumberLabel])
+		s, ok := c.Labels[api.ContainerNumberLabel]
+		if !ok {
+			logrus.Warnf("container %s is missing %s label", c.ID, api.ContainerNumberLabel)
+		}
+		n, err := strconv.Atoi(s)
 		if err != nil {
-			return 0, err
+			logrus.Warnf("container %s has invalid %s label: %s", c.ID, api.ContainerNumberLabel, s)
+			continue
 		}
 		if n > max {
 			max = n
 		}
 	}
-	return max + 1, nil
+	return max + 1
 
 }