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

No GenericResources in ServiceSpec.TaskTemplate.Resources.Reservations #2320

Open
johnflavin-fw opened this issue Apr 19, 2024 · 0 comments · May be fixed by #2327
Open

No GenericResources in ServiceSpec.TaskTemplate.Resources.Reservations #2320

johnflavin-fw opened this issue Apr 19, 2024 · 0 comments · May be fixed by #2327

Comments

@johnflavin-fw
Copy link

I'm migrating some code that was written using https://github.com/spotify/docker-client over to docker-java. I've found a part of the Docker API that was supported in the spotify client but I can't see a way to use it in docker-java: when creating a service I want to be able to define GenericResources (NamedResourceSpec or DiscreteResourceSpec) in ServiceSpec.TaskTemplate.Resources.Reservations.

Using the spotify client, this is the type of thing I could do

final Map<String, String> genericResources;  // Assume this is defined somewhere
final List<ResourceSpec> resourceSpecs = genericResources.entrySet().stream()
                .map(entry -> StringUtils.isNumeric(entry.getValue()) ?
                        ResourceSpec.DiscreteResourceSpec.builder().kind(entry.getKey()).value(Integer.parseInt(entry.getValue())).build() :
                        ResourceSpec.NamedResourceSpec.builder().kind(entry.getKey()).value(entry.getValue()).build())
                .collect(Collectors.toList());
final ResourceRequirements resourceRequirements =
        ResourceRequirements.builder()
                .reservations(Reservations.builder()
                        .resources(resourceSpecs)
                        .build())
                .build();
final TaskSpec taskSpec = TaskSpec.builder()
                .resources(resourceRequirements)
                .build();
final ServiceSpec serviceSpec = ServiceSpec.builder()
                .taskTemplate(taskSpec)
                .build();
// then pass this to the client to create a service

In the docker-java client I can do similar things, but I can't see a way to pass generic resources to the task spec.

new TaskSpec().withResources(
        new ResourceRequirements().withReservations(
                new ResourceSpecs().with...?  // There is nothing here that takes generic resources
        )
);

I do see abstract class GenericResource<T> and its concrete implementations NamedResourceSpec and DiscreteResourceSpec in com.github.dockerjava.api.model. But it looks to me like those are only used to deserialize Task responses received from the API, not used to create new services in a TaskSpec.

Also NamedResourceSpec and DiscreteResourceSpec are both marked @Deprecated but I can't understand why. That annotation was added to those classes in #1635 but I can't see it mentioned in any of the commits or the discussion.

Is there some reason this isn't supported? It is part of the docker API and has been for quite some time. Alternatively, is there a workaround I could do to inject these generic resource specs directly into the API calls before they are sent? (I'm still getting used to the new(-to-me) way of working with docker-java, so I don't know what low-level tricks I can pull.)

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

Successfully merging a pull request may close this issue.

1 participant