Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swarm.CreateServiceAsync doesn't return "Version" which means unable to do an UpdateServiceAsync afterwards #675

Open
dazinator opened this issue Mar 27, 2024 · 0 comments

Comments

@dazinator
Copy link

dazinator commented Mar 27, 2024

When creating a swarm service

        var createService = new ServiceCreateParameters
        {
            Service = serviceSpec
        };

        var response = await client.Swarm.CreateServiceAsync(createService);

The response does not contain the "Version.Index".
The version index (this is sometimes represented as a long and other times a ulong in this library) is required in order to call UpdateServiceAsync - if you don't specify it you can get exceptions back about the update being out of sequence.

To workaround this, after creating the service, I have to do an intermediary ListServicesAsync to fetch it again, because that API does return a Version.

 var listServiceResult = await client.Swarm.ListServicesAsync(new ServicesListParameters()
        {
            Filters = new ServiceFilter()
            {
                Name = new string[]
                {
                    testServiceName
                }
            }
        });
var results = listServiceResult.ToList();
var service = results.Single();

Then I can do

        
  var updatePlacementConstraintResponse = await client.Swarm.UpdateServiceAsync(testServiceName, new ServiceUpdateParameters()
                {
                    Version = (long)service.Version.Index,
                    Service = serviceSpec,
                });

Note: I have to cast from ulong to long - ideally these types could be aligned?

You may wonder why I am doing a create then an immediate update. I am writing a test to check that I can update a service and it has the intended behaviour. At the start of the test I need to create the service first as a test subject. In normal application usage I don't envisage I'd want to create then immediately update a service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant