cli icon indicating copy to clipboard operation
cli copied to clipboard

Docker stack not scaling to 0 on overridden yml

Open AngeloDelgado opened this issue 2 years ago • 6 comments

ln order to deploy our services over docker swarm we use 2 different yml files : the base one and the customized one Here it is an example of our base.yml file:

version: '3.6'
services:
    hello-server-api:
      image: hello-server
      environment:
        - ID=1
      deploy:
        mode: replicated
        replicas: 1
        update_config:
          delay: 50s
        restart_policy:
          condition: on-failure
          max_attempts: 3

Here it is an example of our customized.yml file:

version: '3.6'
services:
    hello-server-api:
      deploy:
        mode: replicated
        replicas: 0
        update_config:
          delay: 50s
        restart_policy:
          condition: on-failure
          max_attempts: 3

we use the customized yml file to manage variables from production and the number of replicas of each container.

docker command to deploy:

docker stack deploy -c base.yml -c customized.yml server

This approach on docker-ce 19.03.11 was working correctly, in fact, the docker service is always deployed 0/0.

Upgrading the docker-ce version to 20.10.0 (we also tried 20.10.8) the behavior is changed and the replicas are always 1/1, it seems like it is not possible to set 0 in the customized.yml file.

However, if we put replicas: 2 in the base.yml and replicas: 1 in the customized.yml it is working correctly (it is working properly in every increasing and decreasing scenario, except when 0 value is used in the customized one ).

AngeloDelgado avatar Sep 09 '21 15:09 AngeloDelgado

Thanks for reporting; just from looking at your report, I suspect it may confuse the 0 for "not set" (as 0 is the default value for numbers) 🤔

thaJeztah avatar Sep 09 '21 15:09 thaJeztah

Is this still an issue @thaJeztah @AngeloDelgado? If so, I would like to claim it and start working on it. Please let me know.

kamden-rasmussen avatar Mar 30 '22 20:03 kamden-rasmussen

I don't think anyone started working on this, so feel free to check if it's still an issue, and if it's possible to fix 🙂☺️

thaJeztah avatar Mar 30 '22 20:03 thaJeztah

Yes it is still an issue, let me know if you need any further info

AngeloDelgado avatar Apr 12 '22 12:04 AngeloDelgado

Good afternoon. I believe I may have found the issue. cli/command/service/opts.go options.replicas.Value() is being compared against nil instead of potentially checking against a >= 0. I am working on changes right now. Is this the correct place to be looking?

However, this made me think of a potential problem that might occur if this change is implemented. In the case where someone may be banking on increments starting at 1, we will throw their count off and an extra replica may be made. I understand this bug was found a few months ago and I am worried we may cause more bugs.

kamden-rasmussen avatar Apr 27 '22 20:04 kamden-rasmussen

Good afternoon, @thaJeztah I am making the following changes but I am unsure if they are correct. Can you point me in the right direction? Also, if you want to see all of the changes, let me know.

`func (options *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) { serviceMode := swarm.ServiceMode{} switch options.mode { case "global": // Problem lies in the considereatin of 'nill'. replicasVal := int64(*options.replicas.Value());

	if replicasVal >= 0 {
	// if options.replicas.Value() != nil {
		return serviceMode, errors.Errorf("replicas can only be used with replicated or replicated-job mode")
	}`
	

This change is found multiple times through the file and I think is the issue. What are your thoughts?

kamden-rasmussen avatar May 02 '22 21:05 kamden-rasmussen

Hi, I took a stab at it and found the issue to be in a different place than what @kamden-rasmussen identified. @thaJeztah what do I need to do to get some eyes on my PR #3812?

mspiess avatar Oct 24 '22 16:10 mspiess