Skip to content

context list: temporarily add ContextType to JSON output #5094

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

Merged
merged 1 commit into from
May 31, 2024

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 30, 2024

Docker Desktop currently ships with the "cloud integration" wrapper, which outputs an additional ContextType field in the JSON output.

While this field is non-standard, it made its way into Visual Studio's Docker integration, which uses this to exclude "aci" and "eci" context types that are not supported by Visual Studio.

This patch;

  • conditionally adds a ContextType field to the JSON output
  • but ONLY when using the default "{{json .}}" or "json" formats (which are the formats used by Visual Studio)
  • if the context is a "aci" or "eci" context, that type is preserved, otherwise the default "moby" type is used.

- Description for the changelog

Add a temporary `ContextType` field to the JSON output of "docker context ls" for backward-compatibility with Visual Studio.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 61.37%. Comparing base (3da25f6) to head (fed9fa0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5094   +/-   ##
=======================================
  Coverage   61.37%   61.37%           
=======================================
  Files         298      298           
  Lines       20707    20718   +11     
=======================================
+ Hits        12708    12716    +8     
- Misses       7099     7102    +3     
  Partials      900      900           

@thaJeztah thaJeztah force-pushed the context_type_stub branch from d2dea15 to 9e337b5 Compare May 30, 2024 13:02
@thaJeztah
Copy link
Member Author

Interesting; for some reason static check does NOT complain about using deprecated field 🤔 wondering if we have some config incorrect in golangci-lint; I would expect it to barf;

8.45 cli/command/context/list.go:70:52: directive `//nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.` is unused for linter "staticcheck" (nolintlint)
68.45 				ContextType: getContextType(nil, opts.format), //nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.
68.45 				                                               ^
68.45 cli/command/context/list.go:87:69: directive `//nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.` is unused for linter "staticcheck" (nolintlint)
68.45 			ContextType: getContextType(meta.AdditionalFields, opts.format), //nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.
68.45 			                                                                 ^
68.45 cli/command/context/list.go:105:51: directive `//nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.` is unused for linter "staticcheck" (nolintlint)
68.45 			ContextType: getContextType(nil, opts.format), //nolint:staticcheck // ignore SA1019: field is deprecated, but used for backward-compatibility.

@krissetto
Copy link
Contributor

The binary with this patch will only be used with DD for the upcoming release (and maybe one after that?), is that correct?

@thaJeztah
Copy link
Member Author

Yes(ish); I wanted to avoid having to build some forked version of the CLI, so tried to create a patch with as minimal-as-possible impact, so that we could included it in a v26.1.4 patch release.

@krissetto
Copy link
Contributor

so that we could included it in a v26.1.4 patch release.

if this does go out to "everyone" (and not only dd users), we need to document this in a visible way and be ready in case anything else breaks (i guess, just in case any other project depends on the shape of that json in even worse ways?)

@thaJeztah thaJeztah force-pushed the context_type_stub branch 2 times, most recently from d697869 to 7789668 Compare May 31, 2024 09:05
@thaJeztah
Copy link
Member Author

I added 3 commits to improve test-coverage; last commit is the change related to ContextType PTAL

@thaJeztah
Copy link
Member Author

Maybe it's cleaner to move those 3 commits to a separate PR, so that this PR is only showing the changes related to ContextType; let me open a separate PR for the first 3 commits

Copy link
Collaborator

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member Author

I'll rebase this one to get rid of the other commits

Docker Desktop currently ships with the "cloud integration" wrapper,
which outputs an additional ContextType field in the JSON output.

While this field is non-standard, it made its way into Visual Studio's
Docker integration, which uses this to exclude "aci" and "eci" context
types that are not supported by Visual Studio.

This patch;

- conditionally adds a ContextType field to the JSON output
- but ONLY when using the default "{{json .}}" or "json" formats
  (which are the formats used by Visual Studio)
- if the context is a "aci" or "eci" context, that type is
  preserved, otherwise the default "moby" type is used.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the context_type_stub branch from 7789668 to fed9fa0 Compare May 31, 2024 11:08
@thaJeztah
Copy link
Member Author

Rebased and moved out of draft

@thaJeztah thaJeztah marked this pull request as ready for review May 31, 2024 11:09
Copy link
Contributor

@krissetto krissetto left a comment

Choose a reason for hiding this comment

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

LGTM, approving as to not block this.

// We only need the ContextType field when formatting as JSON,
// which is the format-string used by Visual Studio to detect the
// context-type.
return ""
Copy link
Contributor

Choose a reason for hiding this comment

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

One curiosity: could it also be possible to check if the current context being used is from DD? Do we have ways of determining that from here, aside from the context name itself (which i totally wouldn't rely on)?

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 think the custom metadata could allow for things like that; we need to better define things here; it's all quite opaque (i.e. custom metadata is supported, but nothing defines it well); some digging may be needed there, because ISTR there's some complex code present to try to match "custom" metadata to be mapped into a specific type / interface.

And that's where my head always explodes, and we need to remove a ton of unneeded complexity.

(in the end, a context is .. well.. not so much different from just key/value pairs ... but it also uses a map[string]any so it's not just "key=value" strings - which is both "great" and "not so great.."😞

@neersighted neersighted merged commit f53a2ae into docker:master May 31, 2024
88 checks passed
@thaJeztah thaJeztah deleted the context_type_stub branch May 31, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants