Skip to content

Add FallbackDockerEngine with intelligent fallback logic#41

Merged
ewassef merged 4 commits intomainfrom
feature/fallback
Jul 17, 2025
Merged

Add FallbackDockerEngine with intelligent fallback logic#41
ewassef merged 4 commits intomainfrom
feature/fallback

Conversation

@ewassef
Copy link
Contributor

@ewassef ewassef commented Jul 15, 2025

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 FallbackDockerEngine for handling Docker failures, updates to the IDockerEngine interface and its implementations, and dependency version upgrades. Unit tests for the fallback functionality have also been added.

Fallback mechanism for Docker operations:

  • Introduced a new FallbackDockerEngine class to provide a fallback implementation of IDockerEngine when 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)
  • Updated the Build method in ServiceProviderBuilder to include intelligent fallback logic for selecting FallbackDockerEngine when Docker connectivity issues are detected. (cli/src/Vdk/ServiceProviderBuilder.cs)

Enhancements to IDockerEngine interface and implementations:

  • Added a CanConnect method to the IDockerEngine interface to check Docker connectivity. (cli/src/Vdk/Services/IDockerEngine.cs)
  • Implemented the CanConnect method in LocalDockerClient to verify connectivity using the Docker API. (cli/src/Vdk/Services/LocalDockerClient.cs)

Dependency updates:

  • Upgraded several package dependencies, including KubeOps.KubernetesClient (to version 9.10.0), Microsoft.Extensions.DependencyInjection (to version 9.0.7), and YamlDotNet (to version 16.3.0), among others. (cli/src/Vdk/Vdk.csproj)

Configuration changes:

  • Updated the RegistryHostPort constant in Containers.cs from 5000 to 50000 to avoid potential port conflicts. (cli/src/Vdk/Constants/Containers.cs)

Unit tests for fallback functionality:

  • Added comprehensive tests for the FallbackDockerEngine class to verify container operations (Run, Stop, Delete, etc.) and ensure proper handling of ports and volumes. (cli/tests/Vdk.Tests/FallbackDockerEngineTests.cs)

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.
@ewassef ewassef requested a review from Copilot July 15, 2025 15:59

This comment was marked as outdated.

ewassef and others added 3 commits July 15, 2025 11:39
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>
@ewassef ewassef requested a review from Copilot July 17, 2025 17:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 FallbackDockerEngine and integrates intelligent fallback logic in ServiceProviderBuilder.
  • Extends IDockerEngine with CanConnect and implements it in both LocalDockerClient and FallbackDockerEngine.
  • 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 programatic is misspelled. Consider renaming it to programmatic for clarity.
                var programatic = new LocalDockerClient(docker);

.github/workflows/build.yaml:28

  • GitHub Actions does not support a macos-15-large runner. Use a valid runner like macos-latest or a specific version (macos-14/macos-13).
            runner: macos-15-large

.github/workflows/build.yaml:30

  • GitHub Actions does not support a macos-15 runner. Replace with a supported runner tag such as macos-latest or macos-14.
            runner: macos-15

cli/src/Vdk/Services/LocalDockerClient.cs:142

  • The code references ImagesListParameters without importing its namespace. Add using 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}");
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

[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.

Copilot uses AI. Check for mistakes.
@ewassef ewassef merged commit 835ee7b into main Jul 17, 2025
2 checks passed
@ewassef ewassef deleted the feature/fallback branch July 17, 2025 18:25
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.

1 participant