diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a13a125..c09a652 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -43,7 +43,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: '8.0.x' # Specify the .NET version you are using + dotnet-version: '10.0.x' # Specify the .NET version you are using - name: Restore run: dotnet restore ./cli diff --git a/cli/src/Vdk/Commands/AppCommand.cs b/cli/src/Vdk/Commands/AppCommand.cs index b1b06ac..1a16a66 100644 --- a/cli/src/Vdk/Commands/AppCommand.cs +++ b/cli/src/Vdk/Commands/AppCommand.cs @@ -3,14 +3,14 @@ namespace Vdk.Commands; -public class AppCommand: RootCommand +public class AppCommand : RootCommand { public AppCommand(CreateCommand create, RemoveCommand remove, ListCommand list, InitializeCommand init, UpdateCommand update, IHubClient client) : base("Vega CLI - Manage Vega development environment") { - AddCommand(create); - AddCommand(remove); - AddCommand(list); - AddCommand(init); - AddCommand(update); + Add(create); + Add(remove); + Add(list); + Add(init); + Add(update); } } \ No newline at end of file diff --git a/cli/src/Vdk/Commands/CreateCloudProviderKindCommand.cs b/cli/src/Vdk/Commands/CreateCloudProviderKindCommand.cs index fe4e743..68b43cb 100644 --- a/cli/src/Vdk/Commands/CreateCloudProviderKindCommand.cs +++ b/cli/src/Vdk/Commands/CreateCloudProviderKindCommand.cs @@ -13,7 +13,7 @@ public CreateCloudProviderKindCommand(IConsole console, IHubClient client): base { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/CreateClusterCommand.cs b/cli/src/Vdk/Commands/CreateClusterCommand.cs index 52f8b36..034cc61 100644 --- a/cli/src/Vdk/Commands/CreateClusterCommand.cs +++ b/cli/src/Vdk/Commands/CreateClusterCommand.cs @@ -11,16 +11,16 @@ namespace Vdk.Commands; public class CreateClusterCommand : Command { + private readonly Func _clientFunc; + private readonly GlobalConfiguration _configs; private readonly IConsole _console; - private readonly IKindVersionInfoService _kindVersionInfo; - private readonly IYamlObjectSerializer _yaml; private readonly IFileSystem _fileSystem; - private readonly IKindClient _kind; - private readonly IHubClient _hub; private readonly IFluxClient _flux; + private readonly IHubClient _hub; + private readonly IKindClient _kind; + private readonly IKindVersionInfoService _kindVersionInfo; private readonly IReverseProxyClient _reverseProxy; - private readonly Func _clientFunc; - private readonly GlobalConfiguration _configs; + private readonly IYamlObjectSerializer _yaml; public CreateClusterCommand( IConsole console, @@ -45,15 +45,24 @@ public CreateClusterCommand( _reverseProxy = reverseProxy; _clientFunc = clientFunc; _configs = configs; - var nameOption = new Option(new[] { "-n", "--Name" }, () => Defaults.ClusterName, "The name of the kind cluster to create."); - var controlNodes = new Option(new[] { "-c", "--ControlPlaneNodes" }, () => Defaults.ControlPlaneNodes, "The number of control plane nodes in the cluster."); - var workers = new Option(new[] { "-w", "--Workers" }, () => Defaults.WorkerNodes, "The number of worker nodes in the cluster."); - var kubeVersion = new Option(new[] { "-k", "--KubeVersion" }, () => "1.29", "The kubernetes api version."); - AddOption(nameOption); - AddOption(controlNodes); - AddOption(workers); - AddOption(kubeVersion); - this.SetHandler(InvokeAsync, nameOption, controlNodes, workers, kubeVersion); + var nameOption = new Option("--Name") { DefaultValueFactory = _ => Defaults.ClusterName, Description = "The name of the kind cluster to create." }; + nameOption.Aliases.Add("-n"); + var controlNodes = new Option("--ControlPlaneNodes") { DefaultValueFactory = _ => Defaults.ControlPlaneNodes, Description = "The number of control plane nodes in the cluster." }; + controlNodes.Aliases.Add("-c"); + var workers = new Option("--Workers") { DefaultValueFactory = _ => Defaults.WorkerNodes, Description = "The number of worker nodes in the cluster." }; + workers.Aliases.Add("-w"); + var kubeVersion = new Option("--KubeVersion") { DefaultValueFactory = _ => "1.29", Description = "The kubernetes api version." }; + kubeVersion.Aliases.Add("-k"); + + Options.Add(nameOption); + Options.Add(controlNodes); + Options.Add(workers); + Options.Add(kubeVersion); + SetAction(parseResult => InvokeAsync( + parseResult.GetValue(nameOption) ?? Defaults.ClusterName, + parseResult.GetValue(controlNodes), + parseResult.GetValue(workers), + parseResult.GetValue(kubeVersion))); } public async Task InvokeAsync(string name = Defaults.ClusterName, int controlPlaneNodes = 1, int workerNodes = 2, string? kubeVersionRequested = null) diff --git a/cli/src/Vdk/Commands/CreateCommand.cs b/cli/src/Vdk/Commands/CreateCommand.cs index c1ac013..e8d335f 100644 --- a/cli/src/Vdk/Commands/CreateCommand.cs +++ b/cli/src/Vdk/Commands/CreateCommand.cs @@ -4,12 +4,12 @@ namespace Vdk.Commands; public class CreateCommand: Command { - public CreateCommand(CreateClusterCommand createCluster, CreateRegistryCommand createRegistry, CreateProxyCommand createProxy, CreateCloudProviderKindCommand createCloudProviderKindCommand) + public CreateCommand(CreateClusterCommand createCluster, CreateRegistryCommand createRegistry, CreateProxyCommand createProxy, CreateCloudProviderKindCommand createCloudProviderKindCommand) : base("create", "Create vega development resources") { - AddCommand(createCluster); - AddCommand(createRegistry); - AddCommand(createProxy); - AddCommand(createCloudProviderKindCommand); + Subcommands.Add(createCluster); + Subcommands.Add(createRegistry); + Subcommands.Add(createProxy); + Subcommands.Add(createCloudProviderKindCommand); } } \ No newline at end of file diff --git a/cli/src/Vdk/Commands/CreateProxyCommand.cs b/cli/src/Vdk/Commands/CreateProxyCommand.cs index 6e55848..e234c61 100644 --- a/cli/src/Vdk/Commands/CreateProxyCommand.cs +++ b/cli/src/Vdk/Commands/CreateProxyCommand.cs @@ -13,7 +13,7 @@ public CreateProxyCommand(IConsole console, IReverseProxyClient client) : base(" { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/CreateRegistryCommand.cs b/cli/src/Vdk/Commands/CreateRegistryCommand.cs index b6483b0..5f9f9b3 100644 --- a/cli/src/Vdk/Commands/CreateRegistryCommand.cs +++ b/cli/src/Vdk/Commands/CreateRegistryCommand.cs @@ -13,7 +13,7 @@ public CreateRegistryCommand(IConsole console, IHubClient client): base("registr { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/InitializeCommand.cs b/cli/src/Vdk/Commands/InitializeCommand.cs index d6dad79..bf50710 100644 --- a/cli/src/Vdk/Commands/InitializeCommand.cs +++ b/cli/src/Vdk/Commands/InitializeCommand.cs @@ -24,7 +24,7 @@ public InitializeCommand(CreateClusterCommand createCluster, CreateProxyCommand _kind = kind; _console = console; _kindVersionInfo = kindVersionInfo; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public async Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/ListClustersCommand.cs b/cli/src/Vdk/Commands/ListClustersCommand.cs index 3e9fca6..02f95b0 100644 --- a/cli/src/Vdk/Commands/ListClustersCommand.cs +++ b/cli/src/Vdk/Commands/ListClustersCommand.cs @@ -13,7 +13,7 @@ public ListClustersCommand(IConsole console, IKindClient client) : base("cluster { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/ListCommand.cs b/cli/src/Vdk/Commands/ListCommand.cs index 781b2a2..46075a1 100644 --- a/cli/src/Vdk/Commands/ListCommand.cs +++ b/cli/src/Vdk/Commands/ListCommand.cs @@ -6,7 +6,7 @@ public class ListCommand: Command { public ListCommand(ListClustersCommand clustersCommand, ListKubernetesVersions kubernetesVersions) : base("list", "List Vega development resources") { - AddCommand(clustersCommand); - AddCommand(kubernetesVersions); + Subcommands.Add(clustersCommand); + Subcommands.Add(kubernetesVersions); } } \ No newline at end of file diff --git a/cli/src/Vdk/Commands/ListKubernetesVersions.cs b/cli/src/Vdk/Commands/ListKubernetesVersions.cs index dc50037..974245e 100644 --- a/cli/src/Vdk/Commands/ListKubernetesVersions.cs +++ b/cli/src/Vdk/Commands/ListKubernetesVersions.cs @@ -16,7 +16,7 @@ public ListKubernetesVersions(IConsole console, IKindClient client, IKindVersion _console = console; _client = client; _versionInfo = versionInfo; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public async Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/RemoveCloudProviderKindCommand.cs b/cli/src/Vdk/Commands/RemoveCloudProviderKindCommand.cs index 298a97e..84a39b5 100644 --- a/cli/src/Vdk/Commands/RemoveCloudProviderKindCommand.cs +++ b/cli/src/Vdk/Commands/RemoveCloudProviderKindCommand.cs @@ -13,7 +13,7 @@ public RemoveCloudProviderKindCommand(IConsole console, IHubClient client) : bas { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/RemoveClusterCommand.cs b/cli/src/Vdk/Commands/RemoveClusterCommand.cs index a983c6c..50147c3 100644 --- a/cli/src/Vdk/Commands/RemoveClusterCommand.cs +++ b/cli/src/Vdk/Commands/RemoveClusterCommand.cs @@ -15,9 +15,10 @@ public RemoveClusterCommand(IConsole console, IKindClient kind) : base("cluster" _console = console; _kind = kind; - var nameOption = new Option(new[] { "-n", "--Name" }, () => Defaults.ClusterName, "The name of the cluster to remove"); - AddOption(nameOption); - this.SetHandler(InvokeAsync, nameOption); + var nameOption = new Option("--Name") { DefaultValueFactory = _ => Defaults.ClusterName, Description = "The name of the cluster to remove" }; + nameOption.Aliases.Add("-n"); + Options.Add(nameOption); + SetAction(parseResult => InvokeAsync(parseResult.GetValue(nameOption) ?? Defaults.ClusterName)); } public Task InvokeAsync(string name = Defaults.ClusterName) diff --git a/cli/src/Vdk/Commands/RemoveCommand.cs b/cli/src/Vdk/Commands/RemoveCommand.cs index 194d130..4940e6f 100644 --- a/cli/src/Vdk/Commands/RemoveCommand.cs +++ b/cli/src/Vdk/Commands/RemoveCommand.cs @@ -7,9 +7,9 @@ public class RemoveCommand: Command public RemoveCommand(RemoveClusterCommand removeCluster, RemoveRegistryCommand removeRegistry, RemoveProxyCommand removeProxy, RemoveCloudProviderKindCommand removeCloudProviderKindCommand) : base("remove", "Remove Vega development resources") { - AddCommand(removeCluster); - AddCommand(removeRegistry); - AddCommand(removeProxy); - AddCommand(removeCloudProviderKindCommand); + Subcommands.Add(removeCluster); + Subcommands.Add(removeRegistry); + Subcommands.Add(removeProxy); + Subcommands.Add(removeCloudProviderKindCommand); } } \ No newline at end of file diff --git a/cli/src/Vdk/Commands/RemoveProxyCommand.cs b/cli/src/Vdk/Commands/RemoveProxyCommand.cs index 5572514..5163b0b 100644 --- a/cli/src/Vdk/Commands/RemoveProxyCommand.cs +++ b/cli/src/Vdk/Commands/RemoveProxyCommand.cs @@ -13,7 +13,7 @@ public RemoveProxyCommand(IConsole console, IReverseProxyClient client) : base(" { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/RemoveRegistryCommand.cs b/cli/src/Vdk/Commands/RemoveRegistryCommand.cs index 65dee3e..3205c6d 100644 --- a/cli/src/Vdk/Commands/RemoveRegistryCommand.cs +++ b/cli/src/Vdk/Commands/RemoveRegistryCommand.cs @@ -13,7 +13,7 @@ public RemoveRegistryCommand(IConsole console, IHubClient client) : base("regist { _console = console; _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Commands/UpdateCommand.cs b/cli/src/Vdk/Commands/UpdateCommand.cs index a4fb798..105bea3 100644 --- a/cli/src/Vdk/Commands/UpdateCommand.cs +++ b/cli/src/Vdk/Commands/UpdateCommand.cs @@ -7,6 +7,6 @@ public class UpdateCommand: Command public UpdateCommand(UpdateKindVersionInfoCommand updateKindVersionInfo) : base("update", "Update resources in vega development environment") { - AddCommand(updateKindVersionInfo); + Subcommands.Add(updateKindVersionInfo); } } \ No newline at end of file diff --git a/cli/src/Vdk/Commands/UpdateKindVersionInfoCommand.cs b/cli/src/Vdk/Commands/UpdateKindVersionInfoCommand.cs index 16e73c2..7295afa 100644 --- a/cli/src/Vdk/Commands/UpdateKindVersionInfoCommand.cs +++ b/cli/src/Vdk/Commands/UpdateKindVersionInfoCommand.cs @@ -11,7 +11,7 @@ public UpdateKindVersionInfoCommand(IKindVersionInfoService client) : base("kind "Update kind version info (Maps kind and Kubernetes versions/enables new releases of kubernetes in vega)") { _client = client; - this.SetHandler(InvokeAsync); + SetAction(_ => InvokeAsync()); } public Task InvokeAsync() diff --git a/cli/src/Vdk/Program.cs b/cli/src/Vdk/Program.cs index e292a06..2c106f0 100644 --- a/cli/src/Vdk/Program.cs +++ b/cli/src/Vdk/Program.cs @@ -8,8 +8,8 @@ class Program { private static readonly IServiceProvider Services = ServiceProviderBuilder.Build(); - static async Task Main(string[] args) + static async Task Main(string[] args) { - await Services.GetRequiredService().InvokeAsync(args); + return await Services.GetRequiredService().Parse(args).InvokeAsync(); } } diff --git a/cli/src/Vdk/Properties/launchSettings.json b/cli/src/Vdk/Properties/launchSettings.json index 1b73d7f..7b98765 100644 --- a/cli/src/Vdk/Properties/launchSettings.json +++ b/cli/src/Vdk/Properties/launchSettings.json @@ -1,25 +1,25 @@ -{ - "profiles": { - "update-kind": { - "commandName": "Project", - "commandLineArgs": "update kind-version-info" - }, - "remove-proxy": { - "commandName": "Project", - "commandLineArgs": "remove proxy" - }, - "create-proxy": { - "commandName": "Project", - "commandLineArgs": "create proxy" - }, - "create-clutser": { - "commandName": "Project", - "commandLineArgs": "create cloud-provider-kind" - }, - "WSL": { - "commandName": "WSL2", - "commandLineArgs": "{OutDir}vega.dll create cluster -n vdk-wsl", - "distributionName": "" - } - } +{ + "profiles": { + "update-kind": { + "commandName": "Project", + "commandLineArgs": "update kind-version-info" + }, + "remove-proxy": { + "commandName": "Project", + "commandLineArgs": "remove proxy" + }, + "create-proxy": { + "commandName": "Project", + "commandLineArgs": "create proxy" + }, + "create-clutser": { + "commandName": "Project", + "commandLineArgs": "create cloud-provider-kind" + }, + "WSL": { + "commandName": "WSL2", + "commandLineArgs": "{OutDir}vega.dll create cluster -n vdk-wsl", + "distributionName": "" + } + } } \ No newline at end of file diff --git a/cli/src/Vdk/Services/ReverseProxyClient.cs b/cli/src/Vdk/Services/ReverseProxyClient.cs index dff19bd..baa8e2b 100644 --- a/cli/src/Vdk/Services/ReverseProxyClient.cs +++ b/cli/src/Vdk/Services/ReverseProxyClient.cs @@ -196,23 +196,23 @@ private bool PatchCoreDns(string clusterName) do { // check up to 10 times , waiting 5 seconds each time - ingressService = _client(clusterName).Get("ingress-nginx-controller", "ingress-nginx"); + ingressService = _client(clusterName).Get("kgateway-system-kgateway", "kgateway-system"); if (ingressService == null) { - _console.WriteLine("Waiting for ingress-nginx-controller service to be available..."); + _console.WriteLine("Waiting for kgateway-system-kgateway service to be available..."); Thread.Sleep(5000); attempts++; } else { - _console.WriteLine("Ingress-nginx-controller service found."); + _console.WriteLine("kgateway-system-kgateway service found."); break; } } while (ingressService == null && attempts < 6); if (ingressService == null) { - _console.WriteError("Ingress-nginx-controller service not found. Please check the configuration and try again."); + _console.WriteError("kgateway-system-kgateway service not found. Please check the configuration and try again."); return false; } var rewriteString = $" rewrite name {clusterName}.dev-k8s.cloud {ingressService.Name()}.{ingressService.Namespace()}.svc.cluster.local"; diff --git a/cli/src/Vdk/Vdk.csproj b/cli/src/Vdk/Vdk.csproj index d77ca8f..c451c7d 100644 --- a/cli/src/Vdk/Vdk.csproj +++ b/cli/src/Vdk/Vdk.csproj @@ -1,8 +1,8 @@ - + Exe - net8.0 + net10.0 enable enable vega @@ -19,14 +19,14 @@ - - + + - - - + + + @@ -43,3 +43,4 @@ + diff --git a/cli/tests/Vdk.Tests/ReverseProxyClientTests.cs b/cli/tests/Vdk.Tests/ReverseProxyClientTests.cs index bcf4393..30e059f 100644 --- a/cli/tests/Vdk.Tests/ReverseProxyClientTests.cs +++ b/cli/tests/Vdk.Tests/ReverseProxyClientTests.cs @@ -12,11 +12,11 @@ namespace Vdk.Tests { public class ReverseProxyClientTests { - private readonly Mock _dockerMock = new(); + private readonly Func _clientFunc; private readonly Mock _consoleMock = new(); + private readonly Mock _dockerMock = new(); private readonly Mock _kindMock = new(); private readonly Mock _kubeClientMock = new(); - private readonly Func _clientFunc; public ReverseProxyClientTests() { @@ -30,14 +30,6 @@ public void Constructor_SetsDependencies() client.Should().NotBeNull(); } - [Fact] - public void Exists_ReturnsTrue_WhenDockerThrows() - { - _dockerMock.Setup(d => d.Exists(It.IsAny(), It.IsAny())).Throws(new Exception("fail")); - var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); - client.Exists().Should().BeTrue(); - } - [Fact] public void Exists_ReturnsFalse_WhenDockerReturnsFalse() { @@ -54,6 +46,14 @@ public void Exists_ReturnsTrue_WhenDockerReturnsTrue() client.Exists().Should().BeTrue(); } + [Fact] + public void Exists_ReturnsTrue_WhenDockerThrows() + { + _dockerMock.Setup(d => d.Exists(It.IsAny(), It.IsAny())).Throws(new Exception("fail")); + var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); + client.Exists().Should().BeTrue(); + } + [Fact] public void InitConfFile_CreatesFileAndWritesConfig() { @@ -68,11 +68,13 @@ public void InitConfFile_CreatesFileAndWritesConfig() } [Fact] - public void PatchCoreDns_ReturnsFalse_WhenIngressServiceNotFound() + public void PatchCoreDns_ReturnsFalse_WhenCoreDnsConfigMapNotFound() { // Arrange - _kubeClientMock.SetupSequence(x => x.Get("ingress-nginx-controller", "ingress-nginx")) - .Returns((V1Service?)null); + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) + .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); + _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) + .Returns((V1ConfigMap?)null); var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); // Act @@ -80,17 +82,17 @@ public void PatchCoreDns_ReturnsFalse_WhenIngressServiceNotFound() // Assert Assert.False(result); - _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("Ingress-nginx-controller service not found"))), Times.Once); + _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("CoreDNS configmap not found"))), Times.Once); } [Fact] - public void PatchCoreDns_ReturnsFalse_WhenCoreDnsConfigMapNotFound() + public void PatchCoreDns_ReturnsFalse_WhenCorefileMissing() { // Arrange - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) - .Returns((V1ConfigMap?)null); + .Returns(new V1ConfigMap { Data = new Dictionary() }); var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); // Act @@ -98,17 +100,15 @@ public void PatchCoreDns_ReturnsFalse_WhenCoreDnsConfigMapNotFound() // Assert Assert.False(result); - _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("CoreDNS configmap not found"))), Times.Once); + _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("CoreDNS Corefile not found"))), Times.Once); } [Fact] - public void PatchCoreDns_ReturnsFalse_WhenCorefileMissing() + public void PatchCoreDns_ReturnsFalse_WhenIngressServiceNotFound() { // Arrange - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) - .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); - _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) - .Returns(new V1ConfigMap { Data = new Dictionary() }); + _kubeClientMock.SetupSequence(x => x.Get("kgateway-system-kgateway", "kgateway-system")) + .Returns((V1Service?)null); var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); // Act @@ -116,28 +116,26 @@ public void PatchCoreDns_ReturnsFalse_WhenCorefileMissing() // Assert Assert.False(result); - _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("CoreDNS Corefile not found"))), Times.Once); + _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("kgateway-system-kgateway service not found"))), Times.Once); } [Fact] - public void PatchCoreDns_ReturnsTrue_WhenRewriteAlreadyExists() + public void PatchCoreDns_ReturnsFalse_WhenNoClosingBrace() { // Arrange - var clusterName = "test-cluster"; - var rewriteString = $" rewrite name {clusterName}.dev-k8s.cloud svc.ns.svc.cluster.local"; - var corefile = $"kubernetes cluster.local in-addr.arpa ip6.arpa {{\n}}\n{rewriteString}\n"; - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) + var corefile = "kubernetes cluster.local in-addr.arpa ip6.arpa {"; + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) .Returns(new V1ConfigMap { Data = new Dictionary { { "Corefile", corefile } } }); var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); // Act - var result = InvokePatchCoreDns(client, clusterName); + var result = InvokePatchCoreDns(client, "test-cluster"); // Assert - Assert.True(result); - _consoleMock.Verify(x => x.WriteLine(It.Is(s => s.Contains("already contains the rewrite entry"))), Times.Once); + Assert.False(result); + _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("does not contain a closing brace"))), Times.Once); } [Fact] @@ -145,7 +143,7 @@ public void PatchCoreDns_ReturnsFalse_WhenNoKubernetesBlock() { // Arrange var corefile = "some unrelated config"; - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) .Returns(new V1ConfigMap { Data = new Dictionary { { "Corefile", corefile } } }); @@ -160,22 +158,24 @@ public void PatchCoreDns_ReturnsFalse_WhenNoKubernetesBlock() } [Fact] - public void PatchCoreDns_ReturnsFalse_WhenNoClosingBrace() + public void PatchCoreDns_ReturnsTrue_WhenRewriteAlreadyExists() { // Arrange - var corefile = "kubernetes cluster.local in-addr.arpa ip6.arpa {"; - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) + var clusterName = "test-cluster"; + var rewriteString = $" rewrite name {clusterName}.dev-k8s.cloud svc.ns.svc.cluster.local"; + var corefile = $"kubernetes cluster.local in-addr.arpa ip6.arpa {{\n}}\n{rewriteString}\n"; + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) .Returns(new V1ConfigMap { Data = new Dictionary { { "Corefile", corefile } } }); var client = new ReverseProxyClient(_dockerMock.Object, _clientFunc, _consoleMock.Object, _kindMock.Object); // Act - var result = InvokePatchCoreDns(client, "test-cluster"); + var result = InvokePatchCoreDns(client, clusterName); // Assert - Assert.False(result); - _consoleMock.Verify(x => x.WriteError(It.Is(s => s.Contains("does not contain a closing brace"))), Times.Once); + Assert.True(result); + _consoleMock.Verify(x => x.WriteLine(It.Is(s => s.Contains("already contains the rewrite entry"))), Times.Once); } [Fact] @@ -186,7 +186,7 @@ public void PatchCoreDns_UpdatesConfigMapAndRestartsPods() var corefile = $"kubernetes cluster.local in-addr.arpa ip6.arpa {{{Environment.NewLine}}}{Environment.NewLine}"; var configMap = new V1ConfigMap { Data = new Dictionary { { "Corefile", corefile } } }; var pod = new V1Pod { Metadata = new V1ObjectMeta { Name = "coredns-1" } }; - _kubeClientMock.Setup(x => x.Get("ingress-nginx-controller", "ingress-nginx")) + _kubeClientMock.Setup(x => x.Get("kgateway-system-kgateway", "kgateway-system")) .Returns(new V1Service { Metadata = new V1ObjectMeta { Name = "svc", NamespaceProperty = "ns" } }); _kubeClientMock.Setup(x => x.Get("coredns", "kube-system")) .Returns(configMap); diff --git a/cli/tests/Vdk.Tests/Vdk.Tests.csproj b/cli/tests/Vdk.Tests/Vdk.Tests.csproj index 6a032ff..d64b460 100644 --- a/cli/tests/Vdk.Tests/Vdk.Tests.csproj +++ b/cli/tests/Vdk.Tests/Vdk.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0 enable enable @@ -18,17 +18,17 @@ - - - + + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -39,3 +39,4 @@ +