Skip to content

LCOW (and generic): Add Supported-Platforms to _ping API endpoint#34628

Closed
lowenna wants to merge 1 commit intomoby:masterfrom
microsoft:jjh/ismultiplatformheader
Closed

LCOW (and generic): Add Supported-Platforms to _ping API endpoint#34628
lowenna wants to merge 1 commit intomoby:masterfrom
microsoft:jjh/ismultiplatformheader

Conversation

@lowenna
Copy link
Member

@lowenna lowenna commented Aug 24, 2017

Signed-off-by: John Howard jhoward@microsoft.com

This is part of the LCOW discussion issue, specifically for #34617 (comment). It adds an HTTP header to the _ping API endpoint so that a client can determine whether the daemon is multi-platform capable, and the list of possible values. As HTTP headers can't be structured, it passes this as a string.

For a Linux daemon, it would return something like Supported-Platforms: linux/amd64. For a dual-mode LCOW/WCOW daemon on Windows, it would return Supported-Platforms: windows/amd64,linux/amd64.

@dnephin @johnstep

EDIT: Updated to use JSON encode the OCI Image-Spec platform structure instead of a comma-separated list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is outside of the API layer, this should return []Platform , right?

And the api layer can transform that into a comma separated list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I'll update that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I need to look into where the Has-Experimental header is added, I would expect this in the same place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's set in WrapHandler in the middleware and does it for every request by the look of it, rather than just on _ping.

@lowenna lowenna force-pushed the jjh/ismultiplatformheader branch from 40ca378 to 8fd5a84 Compare August 24, 2017 20:57
@lowenna
Copy link
Member Author

lowenna commented Aug 24, 2017

@dnephin. Updated (but not the location of where it's set - see my comment above).

I was being silly - I JSON encoded it instead to preserve structure. And used the OCI image-spec structure to match what @stevvooe has been working on in https://github.com/containerd/containerd/pull/1403/files for example.

So it now will return something like: Supported-Platforms: [{"architecture":"amd64","os":"windows"},{"architecture":"amd64","os":"linux"}]

Signed-off-by: John Howard <jhoward@microsoft.com>
@lowenna lowenna force-pushed the jjh/ismultiplatformheader branch from 8fd5a84 to a1c7695 Compare August 24, 2017 21:01
@lowenna
Copy link
Member Author

lowenna commented Aug 25, 2017

Thinking a little more - maybe Supported-Runtime-Platforms rather than Supported-Platforms to indicate that it's specifically for running containers. For multi-stage build, assuming the entire set of work is completed to make the daemon fully multi-platform/arch aware everywhere, you could still have a build stage which just does a COPY for example.

Input welcome 😄

@lowenna
Copy link
Member Author

lowenna commented Aug 25, 2017

@tonistiigi too.

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Supported-Platform should be ok. For multi-stage builds that support different platforms the Dockerfile would need a FROM --platform. The client doesn't really parse the Dockerfile so it shouldn't refuse to build something because of that header.

description: "If the server is running with experimental mode enabled"
Supported-Platforms:
type: "string"
description: "JSON encoded list of supported platforms"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'm not a fan of JSON encoded HTTP headers/query values. I liked the comma separated list. If I'm alone on this I can live with the JSON.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go either way. I'm not sure we have other examples of passing as JSON encoded, but we certainly use Base64 encoded headers (such as registry auth). I kind of liked the fidelity using a JSON structure, and no need to do string-conversion routines.

@tonistiigi
Copy link
Member

What's the use case for this? The linked issue talks about detecting if a flag is supported but this can be done with a version identifier like for any other new feature.

@lowenna
Copy link
Member Author

lowenna commented Aug 25, 2017

@tonistiigi It's based on #34617 (comment), the second part by @dnephin:

"The CLI should hide the --platform flag when it's connecting to any daemon that doesn't support multi-platform. This is similar to how we handle experimental features, and features that exist in a newer version of the API (API downgrading). The daemon should return a Is-Multi-Platform header on _ping so the cli can hide these flags."

@tonistiigi
Copy link
Member

Problem with hiding the --platform flag is that it makes valid code snippets from windows not work in linux. For example, lcow user adds documentation for their image and it needs to be pulled for linux platform, so the docs will say docker run --platform=linux ... Then a linux user copies that snippet and tries to run it, but fails because there is no platform flag in their system.

@dnephin
Copy link
Member

dnephin commented Aug 31, 2017

Problem with hiding the --platform flag is that it makes valid code snippets from windows not work in linux.

Not true. Hidden doesn't mean it's an error to provide it, it just doesn't show up in --help or usage. If a user provides the flag it will still be accepted and sent to the server.

@tonistiigi
Copy link
Member

That's not how the experimental and version annotations work that were used as an example. Why is this case special? We have tens of flags that are platform specific and even more that depend on a feature being available on a node. They are validated during the request, not with a ping.

@dnephin
Copy link
Member

dnephin commented Sep 1, 2017

That's not how the experimental and version annotations work that were used as an example.

It is how they are implemented: https://github.com/docker/cli/blob/d861a1c3ddd794cd64d6c2efb722d7d33391ead7/cmd/docker/docker.go#L211-L237 . We hide them, we don't remove the flag entirely.

However, apparently we also do another check and error out here (https://github.com/docker/cli/blob/d861a1c3ddd794cd64d6c2efb722d7d33391ead7/cmd/docker/docker.go#L245-L271). This is probably because in these cases the daemon will either 1) completely ignore the flag, or 2) report 404 if the API endpoint doesn't exist. In these cases it's better to offer the user an error on the client side because the API doesn't do the right thing.

In the case of platform we don't need to (and shouldn't) error from the client, because specifying a platform that matches a default is a no-op, not an error. Hidding the flag is sufficient. So we can add the platform flags to hideUnsupportedFeatures(), but not to isSupported()

We have tens of flags that are platform specific... They are validated during the request

This is a problem we've already started to fix. From the linked code you can see we have started to hide features by API OSType.

@thaJeztah thaJeztah assigned johnstep and unassigned aaronlehmann Nov 30, 2017
@thaJeztah thaJeztah added the area/lcow Issues and PR's related to the experimental LCOW feature label Oct 30, 2018
@lowenna
Copy link
Member Author

lowenna commented Jan 16, 2020

Long out-of-date. Closing as I am no longer working in this area.

@lowenna lowenna closed this Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lcow Issues and PR's related to the experimental LCOW feature status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants