Add FallbackDockerEngine with intelligent fallback logic#41
Conversation
Introduces FallbackDockerEngine to provide a process-based Docker engine fallback when the programmatic client cannot connect. ServiceProviderBuilder now selects the fallback engine based on connection status and caches fallback state for 2 hours. Updates IDockerEngine and LocalDockerClient to support CanConnect(). Adds tests for FallbackDockerEngine. Also updates several package versions and changes RegistryHostPort to 50000.
Replaced direct System.IO usage with IFileSystem in ServiceProviderBuilder for improved testability. Added unit tests for DockerEngine fallback logic in ServiceProviderBuilderDockerEngineTests. Changed _profileDirectory visibility to internal in GlobalConfiguration.
Refactors the build matrix to specify runner types per runtime identifier, enabling builds on macOS runners for osx-x64 and osx-arm64. Also updates steps to conditionally install zip only on Linux and renames steps for clarity.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Eddie <eddie@wassef.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds a fallback mechanism for Docker operations, updates the Docker engine interface and implementations, bumps several dependencies, and improves configuration and CI matrix support.
- Introduces
FallbackDockerEngineand integrates intelligent fallback logic inServiceProviderBuilder. - Extends
IDockerEnginewithCanConnectand implements it in bothLocalDockerClientandFallbackDockerEngine. - Upgrades package versions, adjusts registry port constant, and refines the GitHub Actions matrix.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cli/tests/Vdk.Tests/ServiceProviderBuilderDockerEngineTests.cs | Adds tests for fallback vs. programmatic Docker engine selection. |
| cli/tests/Vdk.Tests/FallbackDockerEngineTests.cs | Adds end-to-end tests for the FallbackDockerEngine class. |
| cli/src/Vdk/Vdk.csproj | Bumps package versions for Kubernetes client, DI, YAML, etc. |
| cli/src/Vdk/Services/LocalDockerClient.cs | Implements CanConnect to check Docker API connectivity. |
| cli/src/Vdk/Services/IDockerEngine.cs | Adds CanConnect to the IDockerEngine interface. |
| cli/src/Vdk/Services/FallbackDockerEngine.cs | Introduces CLI‐based fallback engine for Docker operations. |
| cli/src/Vdk/ServiceProviderBuilder.cs | Replaces direct LocalDockerClient registration with fallback logic. |
| cli/src/Vdk/GlobalConfiguration.cs | Exposes _profileDirectory as internal for testing. |
| cli/src/Vdk/Constants/Containers.cs | Updates RegistryHostPort from 5000 to 50000. |
| .github/workflows/build.yaml | Expands and parameterizes the CI runner matrix. |
Comments suppressed due to low confidence (6)
cli/src/Vdk/ServiceProviderBuilder.cs:91
- [nitpick] The variable name
programaticis misspelled. Consider renaming it toprogrammaticfor clarity.
var programatic = new LocalDockerClient(docker);
.github/workflows/build.yaml:28
- GitHub Actions does not support a
macos-15-largerunner. Use a valid runner likemacos-latestor a specific version (macos-14/macos-13).
runner: macos-15-large
.github/workflows/build.yaml:30
- GitHub Actions does not support a
macos-15runner. Replace with a supported runner tag such asmacos-latestormacos-14.
runner: macos-15
cli/src/Vdk/Services/LocalDockerClient.cs:142
- The code references
ImagesListParameterswithout importing its namespace. Addusing Docker.DotNet.Models;or fully qualify the type to ensure the code compiles.
_dockerClient.Images.ListImagesAsync(new ImagesListParameters()).GetAwaiter().GetResult();
cli/src/Vdk/ServiceProviderBuilder.cs:65
- [nitpick] The fallback file name is hard‐coded in multiple places. Extract the filename into a constant to avoid duplication and reduce risk of typos.
var fallbackFile = fileSystem.Path.Combine(config.VegaDirectory, ".vdk_docker_fallback");
cli/src/Vdk/ServiceProviderBuilder.cs:97
- [nitpick] The fallback duration (2 hours) is hard‐coded. Consider extracting the duration into a configurable constant or setting to make adjustments easier in the future.
fileSystem.File.WriteAllText(fallbackFile, now.AddHours(2).ToString("o"));
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.Error.WriteLine($"Error in CanConnect: {ex.Message}"); |
There was a problem hiding this comment.
[nitpick] Writing errors directly to the console can make testing and logging harder. Consider injecting an ILogger to handle error reporting in a more flexible way.
This pull request introduces a fallback mechanism for Docker operations, updates dependencies, and includes various enhancements to improve reliability and maintainability. Key changes include the addition of a
FallbackDockerEnginefor handling Docker failures, updates to theIDockerEngineinterface and its implementations, and dependency version upgrades. Unit tests for the fallback functionality have also been added.Fallback mechanism for Docker operations:
FallbackDockerEngineclass to provide a fallback implementation ofIDockerEnginewhen the primary Docker connection fails. This includes methods for container management (e.g.,Run,Stop,Delete) and a helper method to run Docker CLI commands. (cli/src/Vdk/Services/FallbackDockerEngine.cs)Buildmethod inServiceProviderBuilderto include intelligent fallback logic for selectingFallbackDockerEnginewhen Docker connectivity issues are detected. (cli/src/Vdk/ServiceProviderBuilder.cs)Enhancements to
IDockerEngineinterface and implementations:CanConnectmethod to theIDockerEngineinterface to check Docker connectivity. (cli/src/Vdk/Services/IDockerEngine.cs)CanConnectmethod inLocalDockerClientto verify connectivity using the Docker API. (cli/src/Vdk/Services/LocalDockerClient.cs)Dependency updates:
KubeOps.KubernetesClient(to version 9.10.0),Microsoft.Extensions.DependencyInjection(to version 9.0.7), andYamlDotNet(to version 16.3.0), among others. (cli/src/Vdk/Vdk.csproj)Configuration changes:
RegistryHostPortconstant inContainers.csfrom5000to50000to avoid potential port conflicts. (cli/src/Vdk/Constants/Containers.cs)Unit tests for fallback functionality:
FallbackDockerEngineclass to verify container operations (Run,Stop,Delete, etc.) and ensure proper handling of ports and volumes. (cli/tests/Vdk.Tests/FallbackDockerEngineTests.cs)